I have the transfer function below which is for a IIR filter and trying to plot its frequency response for omega<pi. r=0.99 and theta=pi/3:

enter image description here

Here is my attempt at implementing it in MATLAB:

z= exp(j*W);

num= (1-r1);
den= (1-2*r1*cos(theta)*z.^(-1)+r1^(2)*z.^(-2));
TFdb= 20*log10(TF);

Here is what I get:

enter image description here

Apparently it should look like this:

enter image description here

I am very new to this and can't tell what I'm doing wrong, would appreciate if anyone can help.


1 Answer 1


How did you derive the second figure? I got the different result using the following code:

b = 1 - r1;
a = [1, -2*r1*cos(theta), r1^(2)];
figure; freqz(b, a)

enter image description here)

The only problme I can find in your code is that

TFdb= 20*log10(TF);

should be

TFdb= 20*log10(abs(TF));

Did you take the wrong sign of $a_1$ when calculating second transfer function?

b = 1 - r1;
a = [1, 2*r1*cos(theta), r1^(2)];

The above code generates the second figure.

  • $\begingroup$ Right the second one must be wrong then, that now gives me a notch filter using abs, what's the reason the response using freqz command looks so different ? The filtered frequency is 1.04 radian but that appears to be different in the freqz plot ? Thanks a lot for helping $\endgroup$ May 17, 2021 at 6:09
  • $\begingroup$ Yes ! I did check that now and that's indeed the problem with the second plot, however I'm still confused about the first plot as mention in my above comment. $\endgroup$ May 17, 2021 at 6:14
  • $\begingroup$ @BigRedMachine Note that the x axis in the freqz plot is normalized frequency, in my plot it's $0.334 \times \pi$ radian which is equal to 1.047 radian. $\endgroup$
    – ZR Han
    May 17, 2021 at 6:17
  • $\begingroup$ Oh ok, got it now, thanks a lot ! $\endgroup$ May 17, 2021 at 6:19

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.