Sunday, April 15, 2018

frequency response - Difference between $tt freqz()$ and $tt plot(abs(fft()))$ in MATLAB


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?



Answer



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.


No comments:

Post a Comment

periodic trends - Comparing radii in lithium, beryllium, magnesium, aluminium and sodium ions

Apparently the of last four, $\ce{Mg^2+}$ is closest in radius to $\ce{Li+}$. Is this true, and if so, why would a whole larger shell ($\ce{...