Problems designing a notch filter based on allpass in MATLAB

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

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

Any answer is welcomed! Thank you!

• 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. Jul 2, 2022 at 6:57
• Where do you define your sample rate ? Jul 2, 2022 at 10:34
• I have converted your equations to MathJax, please check that I have done so correctly and consider using MathJax in the future. Jul 2, 2022 at 11:10