1
$\begingroup$

I have to design a notch filter based on an allpass but when I plot the resulting filter in MATLAB it does not fit my specification. I'll provide you with some background.

The filter has the following equation:

$$H(z) = \frac{(1+k_2)}{2}\frac{1+2k_1z^{-1}+z^{-2}}{1+k_1(1+k_2)z^{-1}+k_2z^{-2}}$$

where

$$k_1 = -\cos\omega_0, \hspace{1cm} k_2=\frac{1-\tan(\Delta\omega_0/2)}{1+\tan(\Delta\omega_0/2)}$$

The frequency I want the notch to eliminate is fr = 490.89Hz, so I compute all the coefficients in MATLAB and then design the function as follows:

fr = 490.89;
wr = 2*pi*fr
delta_wr = 2*pi*50
k1 = -cos(wr)
k2 = (1-tan(delta_wr/2))/(1+tan(delta_wr/2))

%TF H(z)
c = (1+k2)/2, num = [1 2*k1 1], den = [1 k1*(1+k2) k2]

freqz(c*num, den, 2e6, Fs)

but when analyzing the final filter with freqz(), the result is

enter image description here

which is obviously not behaving as a notch, and even the frequency is not the desired.

Any answer is welcomed! Thank you!

$\endgroup$
3
  • 1
    $\begingroup$ I suggest you review the definition of the frequency variables in your equations for k1 and k2. I'd be surprised if those frequency variables are measured in Hz. $\endgroup$ Jul 2, 2022 at 6:57
  • 1
    $\begingroup$ Where do you define your sample rate ? $\endgroup$
    – Hilmar
    Jul 2, 2022 at 10:34
  • 2
    $\begingroup$ I have converted your equations to MathJax, please check that I have done so correctly and consider using MathJax in the future. $\endgroup$ Jul 2, 2022 at 11:10

1 Answer 1

2
$\begingroup$

I believe you need to normalize your design frequencies with Fs:

wr = 2*pi*fr/Fs
delta_wr = 2*pi*50/Fs

If I make those two changes (and assume Fs = 44100) then I get the following plot, which is more like what I would expect.

Notch filter after normalizing to sampling rate

$\endgroup$
2
  • 1
    $\begingroup$ Yes, that was the problem! I really appreciate your help! $\endgroup$ Jul 2, 2022 at 17:33
  • $\begingroup$ @MiqueasEzequiel You're welcome! $\endgroup$
    – Peter K.
    Jul 2, 2022 at 17:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.