3
$\begingroup$

I've plotted the response of a high-pass filter x=[1 -1];

freqz(x) gave me

enter image description here

where as the magnitude plot for the fft gave me

enter image description here

Why are the two plots different? Both are frequency responses, then why are my plots are diffferent. What does freqz() do?

$\endgroup$
0

1 Answer 1

4
$\begingroup$

You calculating FFT only from two samples. You need to pad your impulse response with zeros to get a valid result. So in MATLAB that would be:

N = 1024; % Number of points to evaluate at
% Create the vector of angular frequencies at one more point.
% Filter itself
b=[1,-1];
[h_f, w_f] = freqz(b, 1);
figure
grid on
hold on
plot(w_f, abs(h_f), 'or') % MATLAB
h = [b, zeros(1,N-2)];
HH = abs(fft(h));
HH = HH(1:length(w_f));
plot(w_f, HH); % Manual calculation
legend({'MATLAB freqz', 'Manual'})

As you can see it matches first and last value from fft you calculated. Please keep in mind that it is shown in linear - not dB scale.

enter image description here

For more info you can see my previous answer.

$\endgroup$
4
  • 1
    $\begingroup$ Another important point is that invoking 'freqz()' without any specified output argument plots the magnitude in dB (as seen in the top plot of the OP). $\endgroup$
    – Matt L.
    Feb 21, 2015 at 10:54
  • $\begingroup$ Sure thing, but I assumed he already knew about that. It is worth to update the answer. $\endgroup$
    – jojeck
    Feb 21, 2015 at 11:16
  • $\begingroup$ I was not aware that freqz() plots the answer in dB scale. Thanks for your answer. I'll crosscheck while asking the next question @jojek $\endgroup$
    – phanitej
    Feb 21, 2015 at 12:56
  • $\begingroup$ It is obviously mentioned on y axis label. Good luck! $\endgroup$
    – jojeck
    Feb 21, 2015 at 12:58

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.