My DSP professor uses the freqz() function to find and plot the frequency response and I think it's wrong but I want to make sure before I point it out. Take this example:

Given the impulse response of an LTI, derive an expression for the magnitude and phase response and verify using MATLAB.

$$h(n)=2(-1)^{n-8\over 2}\sum_{k=0}^5 \delta(n-2k)$$

This is how I calculated the freq. response:

The impulse response is just the following values:

h = 2[1 0 -1 0 1 0 -1 0 1 0 -1]

The freq. response is the FT of the impulse response:

$$H(e^{j\omega}) = \sum_{n=-\infty}^\infty h(n)e^{-j\omega n}$$

h(n) exists only for $n=[0,10]$ so I change the limits of summation. Also, the series in the impulse response, converges to 6, so I replace it with 6:

$$\sum_{n=0}^{10} 2\times 6\times (-1)^{n-8\over 2}e^{-j\omega n}$$

Let $n'={n-8\over 2}\Rightarrow n=2n'+8$. Absorb the $(-1)^{n'}$ term. Replace these in the summation and update the limits in terms of n':

$$2\times 6 \sum_{n'=-4}^{1} (-1)^{n'} e^{-j\omega (2n'+8)}=12\sum_{n'=-4}^{1} e^{-j8\omega}(-e)^{-j2\omega n'}=12e^{-j8\omega}\sum_{n'=-4}^{1}(-e)^{-j2\omega n'}$$

And after finding the sum of the series, and some simplifications, the expression becomes:

$$H(e^{j\omega})=\frac{12(1-e^{-12\omega j})}{1+e^{-2\omega j}}$$

I derived the expression for phase response and got the following:

$$\angle H(e^{j\omega})=-5\omega +{\pi\over 2}+\left\{ \begin{array}{ll} 0, & k{\pi\over 6}\le\omega\le(k+1){\pi\over 6} \\ \pi, & (k+1){\pi\over 6}<\omega<(k+2){\pi\over 6} \\ \end{array} \right.$$ for $k=0,1,2,...$

I plug in some test value for $\omega$ to get the phase.

Then, to find and plot the frequency response, this is what my professor does:


where h is the vector of the impulse response, h(n), and w is the vector of freq. (in rad). He says the '1' is added because it's an FIR filter.

Looking at the MATLAB documentation for freqz none of what he said makes sense. The '1' is supposed to be the arguments for the number of points for the transformation, and 'h' is supposed to be the digital filter represented either by the vector coefficients b and a or other methods.

When I run his code, I get the right shape and points where the frequency jumps up by $\pi$ but not the right values. For example, this is what I get with his plot:

enter image description here

Notice the phase at $\pi /6$.

This is what I get by passing the b and a coefficients from the transfer function $H(e^{j\omega })$:

enter image description here

Notice the phase at $\pi /6$. If I plug in $\omega = \pi /6$ in the expression for the phase response, I get that the phase is $\phi = -\pi /3 \Rightarrow -60^{\circ}$

I tried hours and hours to find out what my mistake was and got very frustrated, until I looked at the documentation. I want to bring this up to him because other students in the class are using his method which inherently gives wrong results, and future students will too, but just to make sure before I do that, am I right or am I wrong?

Thank you!

  • $\begingroup$ That was a bad comment, I hope you could ignore it (deleted). $\endgroup$ – a concerned citizen Apr 3 at 15:44

Your professor is right, and you're almost right too. The filter is clearly an FIR filter, but because its frequency response can be expressed as a geometric series, a recursive implementation is possible.

If you write the transfer function as a rational function you get


which is almost the same as you got, apart from a constant factor.

Note that there is a pole-zero cancellation in $(1)$, so the filter is FIR with impulse response

h = [2 0 -2 0 2 0 -2 0 2 0 -2];

So apart from rounding errors both

b = 2*[1,zeros(1,11),-1];
a = [1,0,1];
[H1,w] = freqz(b,a,1024);


[H2,w] = freqz(h,1,1024);

must give the same result, which turns out to be true. On my machine I get

ans =    7.9623e-14

Note that the phase is ambiguous, so the phase values are only identical up to an additive multiple of $2\pi$.

  • $\begingroup$ Thank you so much for the answer. I have a few more questions to expand on: 1. how did you get the constant for your transfer function to be 2? I edited my question to show my process for finding the DFT of h(n). Clearly, my mistake is with assuming that the $\delta(n-2k)$ series converges to 6. I know that the DFT of $\delta(n)=1$ so it makes sense intuitively that it should be 1 instead of 6 but I don't know how to do that mathematically. Btw, this process is before we got to the z-transform although we have covered that already. 2. How is it that you can just pass the h vector into freqz? $\endgroup$ – Kevin KZ Apr 3 at 14:59
  • $\begingroup$ Sorry, ran out of characters but from 2-continued: Looking at MATLAB's doc., the args passed should be either the vector coeffs [b] and [a] or a digital filter 'd' or an 'sos'; how does the vector fit in here? I'm assuming since you said there's a zero-pole cancellation that the $z^{-2}$ term is cancelled so that leaves with 11 zeros in the num. and the den. = 1. The degree of the num then becomes 10 ($z^{-12}/z^{-2}=z^{-10})$ So then the vector h represents the coeffs of the num. $b_i$ for $i=[0:10]$, and since the den = 1, that's why there's a '1' passed as the a arg, correct? $\endgroup$ – Kevin KZ Apr 3 at 15:08
  • 1
    $\begingroup$ @KevinKZ: If you have a FIR filter with impulse response h, then b=h (numerator) and a=1 (denominator). In that sense, a FIR filter is just a special case with a=1. $\endgroup$ – Matt L. Apr 3 at 15:12
  • $\begingroup$ so I'm assuming this wouldn't work if for some reason the h-vector contains extra padded zeros, for example: h=[0 0 0 0 0 2 0 -2 0 2 0 -2 0 2 0 -2 0 0 0 0] ? $\endgroup$ – Kevin KZ Apr 3 at 15:24
  • $\begingroup$ @KevinKZ: Of course it would work, why not? $\endgroup$ – Matt L. Apr 3 at 16:57

Your Answer

