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?

  • $\begingroup$ Why not to start marking your questions answered to encourage people answering them? $\endgroup$
    – jojek
    Feb 21 '15 at 10:58

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
[h_f, w_f] = freqz(b, 1);
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.

  • 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 '15 at 10:54
  • $\begingroup$ Sure thing, but I assumed he already knew about that. It is worth to update the answer. $\endgroup$
    – jojek
    Feb 21 '15 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 '15 at 12:56
  • $\begingroup$ It is obviously mentioned on y axis label. Good luck! $\endgroup$
    – jojek
    Feb 21 '15 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.