I've plotted the response of a high-pass filter x=[1 -1]
;
freqz(x)
gave me
where as the magnitude plot for the fft
gave me
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.
For more info you can see my previous answer.
No comments:
Post a Comment