How to evaluate frequency response of a filter using freqz()?
14 views (last 30 days)
Show older comments
I have a vector of length 25 which contains the impulse response of a filter.
I'm supposed to use freqz() to evaluate the frequency response of the filter, and plot the evaluated response with frequency in Hz and magnitude in dB.
I'm confused because freqz() can be used in two ways. If I assign it to some variables it will return the requency response vector h and the corresponding angular frequency vector w. I can then manually plot these, giving me the plot in image 1 below.
[h,w] = freqz(b,a); %here, b is the impulse response vector and a is 1
plot(h, abs(w));
But I can also call freqz() on its own and it will automatically plot the frequency response. (Image 2 below)
freqz(b,a);
Why do these plots seem to be completely different? Which one is the correct frequency response of the filter, plotted as frequency(Hz) against magnitude(dB)?


0 Comments
Answers (2)
Paul
on 18 May 2021
Image 1 is plotted against against magnitude, not magnitude(dB). Just change the second input to plot() to be the db of the magnitude. Also, Image 1 is plotted against frequency whereas Image 2 is against normalized frequency. The two are related to each other by a factor of pi.
0 Comments
Star Strider
on 18 May 2021
This is not correct:
[h,w] = freqz(b,a); %here, b is the impulse response vector and a is 1
plot(h, abs(w));
It shouild be:
plot(w, abs(h))
so for example —
b = ones(1,3);
a = 1;
figure
freqz(b,a)
and using the output arguments —
[h,w] = freqz(b,a);
figure
subplot(2,1,1)
plot(w, mag2db(abs(h)))
grid
subplot(2,1,2)
plot(w, angle(h))
grid
Except for the normalisation from
this produces the plot from freqz.
this produces the plot from freqz. .
0 Comments
See Also
Categories
Find more on Digital Filter Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
