# How to calculate the magnitude of frequency response from Pole zero plot

I have checked the theory to calculate the magnitude of frequency response from the pole-zero plot from the previous posts. As far as I understand(and I hope I am correct), the magnitude can be calculated from this formula.

|$$H(z)| = \frac{|\prod_{n=0}^{n=\infty} (z-z_n)|}{|\prod_{n=0}^{n=\infty}(z-p_n)|}$$

So, for this question, (no 11, fig. a),

To visualize the frequency plot, I wrote the following Python code,

w = np.linspace(-np.pi,np.pi,100)
z = np.exp(1j*w)
cof1 = (0.9+0.1j)
cof2 = (0.9-0.1j)
eq = z**2 - ((cof1+cof2)*z)+(cof1*cof2)  //to find the equation from the roots
num = (z+1)**3
den = (z-0.8)*eq
y = num/den
plt.plot(w,np.sqrt(y.real**2+y.imag**2))


The code is not great but it kind of works (I think so). And, I took some approximate values for coefficient of poles. Anyway, I got the following output,

which is wrong. The correct output is,

I don't understand, where I went wrong. Why is there a significant gap in the magnitude between my output and the correct answer? I used the same code to calculate some other plots and it worked fine. But in this particular question, it didn't work. I hope my code is not wrong. Could anybody help me with this? I am trying to play around with the poles and zeros to see its relation with the magnitude of the frequency response curve.

• I don't see anything in that figure given in the solution. What's that supposed to be? Your magnitude plot looks fine, it's just a low pass filter. Take a look at these questions for the relation between pole-zero plots and frequency responses: Q1, Q2, Q3. Feb 13, 2021 at 19:13
• @MattL. there is a small bump between $-\pi/2$ and $\pi/2$. Though the magnitude is very small. This is the answer sheet provided by the lecturer and I don't understand it. And the answer to the rest of the figures is also similar. I can't seem to figure out the difference.
– Rima
Feb 14, 2021 at 6:11
• I think I got my mistake. I should have used the range between -1 to 1 instead of $\pi$ and calculated in terms of z rather than $e^(j\omega)$ because of which there is a large gap in the magnitude. thanks for the reference.
– Rima
Feb 14, 2021 at 8:54
• I don't think that you made a mistake. The frequency response is obtained by using $z=e^{j\omega}$, and $\omega$ is in the range $[-\pi,\pi]$. I'm quite sure that the problem lies in the solution. I mean, what are those strange lines supposed to be that extend over all the figures? Feb 14, 2021 at 11:49
• This question has a few very related exercises. Many more nice matching exercises can be found here. Feb 14, 2021 at 12:34