% Design example comparing various FIR windows for % same length filter % % Here we have a lowpass filter with a cutoff frequency of 100 Hz % The sampling frequency is 1000 Hz and a transition width of 75 Hz % % The Blackman window needs the most coefficients so we will compute % the length of the filter for it and compare all others to it. % % Normalized transition width is (75 Hz/1000 Hz) = 0.075 % The length of the filter is then N = 5.5/(0.075) = 73. FS = 1000; FN = 500; N = 73; FC = 100/FN; hn = fir1(N-1, FC, boxcar(N)); [H,f] = freqz(hn, 1, 512, FS); % Compute frequency response mag = 20*log10(abs(H)); subplot(3,2,1), plot (f, mag), grid on xlabel ('Frequency (Hz)') ylabel ('Magnitude Response (dB)') title ('Rectangular Window') hn = fir1(N-1, FC, bartlett(N)); [H,f] = freqz(hn, 1, 512, FS); % Compute frequency response mag = 20*log10(abs(H)); subplot(3,2,2), plot (f, mag), grid on xlabel ('Frequency (Hz)') ylabel ('Magnitude Response (dB)') title ('Bartlett Window') hn = fir1(N-1, FC, hamming(N)); [H,f] = freqz(hn, 1, 512, FS); % Compute frequency response mag = 20*log10(abs(H)); subplot(3,2,3), plot (f, mag), grid on xlabel ('Frequency (Hz)') ylabel ('Magnitude Response (dB)') title ('Hamming Window') hn = fir1(N-1, FC, hann(N)); [H,f] = freqz(hn, 1, 512, FS); % Compute frequency response mag = 20*log10(abs(H)); subplot(3,2,4), plot (f, mag), grid on xlabel ('Frequency (Hz)') ylabel ('Magnitude Response (dB)') title ('Hanning Window') hn = fir1(N-1, FC, blackman(N)); [H,f] = freqz(hn, 1, 512, FS); % Compute frequency response mag = 20*log10(abs(H)); subplot(3,2,5), plot (f, mag), grid on xlabel ('Frequency (Hz)') ylabel ('Magnitude Response (dB)') title ('Blackman Window')