# LowPass Filter & Window *Img & Code* - Frequency Response has no lobe roll off

Not sure if I am doing something silly but I am not seeing lobe roll off on the frequency response of my windows and the low pass filter I made in MATLAB. Please can you help ... several hours just looking at this and my textbook -.-

It should be like this showing lobe roll off

%% Low Pass Filter
Fs=10*10^3; cutoff = 1000; %100 Hz
fc = cutoff / Fs ;
b = 800/Fs ;%Transition bandwidth of 800 Hz
M = 51 ; %Length of Filter
n = 0:1:M-1;
blackman_window = 0.42 - 0.50 * cos((2*pi*n)/(M-1)) + 0.08*cos( (4*pi*n) / (M-1));
hamming_window  = 0.54 - 0.46 * cos((2*pi.*n)/(M-1));
hanning_window  = 0.50 - 0.50 * cos((2*pi.*n)/(M-1));
blackman_window_ft = fftshift(fft(blackman_window)/M);
hamming_window_ft  = fftshift(fft(hamming_window)/M);
hanning_window_ft  = fftshift(fft(hanning_window)/M);

sinc_func = sin(2*pi*fc.*(n-((M-1)/2))) ./ (2*pi*fc.* (n-((M-1)/2)));
sinc_func((M+1)/2) = 1 ;
sinc_func_ft = fftshift(fft(sinc_func)/M);

h_lpf = sinc_func .* blackman_window;
h_lpf = h_lpf ./ sum(h_lpf); %Normalise
H_lpf = fft(h_lpf);
H_lpf = fftshift(H_lpf);

figure(1);cla;clf
subplot(3,2,1);hold on;
plot(blackman_window,'DisplayName','Blackman')
plot(hamming_window,'DisplayName','Hamming')
plot(hanning_window,'DisplayName','Hanning')
plot(sinc_func,'DisplayName','Sinc')
legend
title('Windows and Sinc Impulse Response');hold off

subplot(3,2,2);hold on;
plot(20*log10(abs(blackman_window_ft)),'DisplayName','Blackman')
plot(20*log10(abs(hamming_window_ft)),'DisplayName','Hamming')
plot(20*log10(abs(hanning_window_ft)),'DisplayName','Hanning')
plot(20*log10(abs(sinc_func_ft )),'DisplayName','Sinc')
legend
title('Window and Sinc Frequency Response (dB)');hold off;

subplot(3,2,3);hold on;
plot(h_lpf);
title('Low Pass Filter Impulse Response');hold off;

subplot(3,2,5);hold on;
plot(abs(H_lpf),'DisplayName','Magnitude');
plot(real(H_lpf),'DisplayName','Real');
plot(imag(H_lpf),'DisplayName','Imag');
legend
title('Low Pass Filter Frequency Response');hold off;

subplot(3,2,6);
plot(20*log10(abs(H_lpf)));
title('Low Pass Filter Frequency Response (dB)');


You need to zero pad the FFT so that it reveals more of the frequency response (increasing the resolution of the plot). I corrected your code (while taking fft, I took 1024 point FFT for windows as well as h_lpf)

%% Low Pass Filter
Fs=10*10^3; cutoff = 1000; %100 Hz
fc = cutoff / Fs ;
b = 800/Fs ;%Transition bandwidth of 800 Hz
M = 51 ; %Length of Filter
n = 0:1:M-1;
blackman_window = 0.42 - 0.50 * cos((2*pi*n)/(M-1)) + 0.08*cos( (4*pi*n) / (M-1));
hamming_window  = 0.54 - 0.46 * cos((2*pi.*n)/(M-1));
hanning_window  = 0.50 - 0.50 * cos((2*pi.*n)/(M-1));
blackman_window_ft = fftshift(fft(blackman_window,1024)/M);
hamming_window_ft  = fftshift(fft(hamming_window,1024)/M);
hanning_window_ft  = fftshift(fft(hanning_window,1024)/M);

sinc_func = sin(2*pi*fc.*(n-((M-1)/2))) ./ (2*pi*fc.* (n-((M-1)/2)));
sinc_func((M+1)/2) = 1 ;
sinc_func_ft = fftshift(fft(sinc_func,1024)/M);

h_lpf = sinc_func .* blackman_window;
h_lpf = h_lpf ./ sum(h_lpf); %Normalise
H_lpf = fft(h_lpf,1024);
H_lpf = fftshift(H_lpf);

figure(1);cla;clf
subplot(3,2,1);hold on;
plot(blackman_window,'DisplayName','Blackman')
plot(hamming_window,'DisplayName','Hamming')
plot(hanning_window,'DisplayName','Hanning')
plot(sinc_func,'DisplayName','Sinc')
legend
title('Windows and Sinc Impulse Response');hold off

subplot(3,2,2);hold on;
plot(20*log10(abs(blackman_window_ft)),'DisplayName','Blackman')
plot(20*log10(abs(hamming_window_ft)),'DisplayName','Hamming')
plot(20*log10(abs(hanning_window_ft)),'DisplayName','Hanning')
plot(20*log10(abs(sinc_func_ft )),'DisplayName','Sinc')
legend
title('Window and Sinc Frequency Response (dB)');hold off;

subplot(3,2,3);hold on;
plot(h_lpf);
title('Low Pass Filter Impulse Response');hold off;

subplot(3,2,5);hold on;
plot(abs(H_lpf),'DisplayName','Magnitude');
plot(real(H_lpf),'DisplayName','Real');
plot(imag(H_lpf),'DisplayName','Imag');
legend
title('Low Pass Filter Frequency Response');hold off;

subplot(3,2,6);
plot(20*log10(abs(H_lpf)));
title('Low Pass Filter Frequency Response (dB)');


• Your FFT size should not be equal to window size. So even if you increase window size you still won't be seeing those lobes. You need to choose a higher FFT size. Apr 27 '20 at 18:34
• Thanks. I did attempt to increase the number of samples by increasing M, the length of my filter from M=51 to M=1025. But this did not do the same as what you showed, I had the same result. I thought frequency resolution was related to length of the input of the fft? Apr 27 '20 at 18:37
• "Your FFT size should not be equal to window size" . Why? Apr 27 '20 at 18:40
• No, what I meant is unlike a sinc pulse, the zero crossings for other windows occur much more lesser intervals so you should have enough resolution to see them. You can just plot a blackman window and see this. The plot you showed in your question (where you see lobes) was plotted with much higher FFT size. Apr 28 '20 at 2:51
• If you increase M and use the same size for FFT, then the FFT bins would still be positioned along the maxima of the bins. So you wouldn't really see the dips in the lobes. I am not exactly sure how to mathematically show this. Apr 28 '20 at 10:16