%Demo of window FIR filtering using windows .....
% Effect of window duration



% And now superimposing ....




a = 1;
wc = .4*pi;
N = 51;
n = -(N-1)/2:(N-1)/2;


%Time domain response
w = hamming(N);
h = w'.*sinc(n*wc/pi);
subplot(2,1,1),stem(n,h)
title('h[n] for LPF with Hamming window, N = 51','fontsize',14)
xlabel('n','fontsize',14)
ylabel('h[n]','fontsize',14)


%Frequency domain response
[H,W] = freqz(h,1 );
subplot(2,1,2),plot(W/pi,20*log10(abs(H)))
title('LPF with Hamming window, N = 51','fontsize',14)
xlabel('\omega/\pi','fontsize',14)
ylabel('|H(\omega)|, dB','fontsize',14)
axis([0 1 -100 10])
pause



N = 101;
n = -(N-1)/2:(N-1)/2;

%Time domain response
w = hamming(N);
h = w'.*sinc(n*wc/pi);
subplot(2,1,1),stem(n,h)
title('h[n] for LPF with Hamming window, N = 101','fontsize',14)
xlabel('n','fontsize',14)
ylabel('h[n]','fontsize',14)


%Frequency domain response
[H,W] = freqz(h,1 );
subplot(2,1,2),plot(W/pi,20*log10(abs(H)))
title('LPF with Hamming window, N = 101','fontsize',14)
xlabel('\omega/\pi','fontsize',14)
ylabel('|H(\omega)|, dB','fontsize',14)
axis([0 1 -100 10])
pause



N = 201;
n = -(N-1)/2:(N-1)/2;


%Time domain response
w = hamming(N);
h = w'.*sinc(n*wc/pi);
subplot(2,1,1),stem(n,h)
title('h[n] for LPF with Hamming window, N = 201','fontsize',14)
xlabel('n','fontsize',14)
ylabel('h[n]','fontsize',14)


%Frequency domain response
[H,W] = freqz(h,1 );
subplot(2,1,2),plot(W/pi,20*log10(abs(H)))
title('LPF with Hamming window, N = 201','fontsize',14)
xlabel('\omega/\pi','fontsize',14)
ylabel('|H(\omega)|, dB','fontsize',14)
axis([0 1 -100 10])
pause







a = 1;
wc = .4*pi;
N = 51;
n = -(N-1)/2:(N-1)/2;


%Time domain response
w = hamming(N);
h = w'.*sinc(n*wc/pi);
title('h[n] for LPF with Hamming window, N = 51','fontsize',14)
xlabel('n','fontsize',14)
ylabel('h[n]','fontsize',14)


%Frequency domain response
[H,W] = freqz(h,1 );
subplot(1,1,1),plot(W/pi,20*log10(abs(H)))
title('LPF with Hamming window, N = 51','fontsize',14)
xlabel('\omega/\pi','fontsize',14)
ylabel('|H(\omega)|, dB','fontsize',14)
axis([0 1 -100 10])
hold on
pause



N = 101;
n = -(N-1)/2:(N-1)/2;

%Time domain response
w = hamming(N);
h = w'.*sinc(n*wc/pi);
title('h[n] for LPF with Hamming window, N = 101','fontsize',14)
xlabel('n','fontsize',14)
ylabel('h[n]','fontsize',14)


%Frequency domain response
[H,W] = freqz(h,1 );
plot(W/pi,20*log10(abs(H)),'m')
title('LPF with Hamming window, N = 101','fontsize',14)
xlabel('\omega/\pi','fontsize',14)
ylabel('|H(\omega)|, dB','fontsize',14)
axis([0 1 -100 10])
pause



N = 201;
n = -(N-1)/2:(N-1)/2;


%Time domain response
w = hamming(N);
h = w'.*sinc(n*wc/pi);
title('h[n] for LPF with Hamming window, N = 201','fontsize',14)
xlabel('n','fontsize',14)
ylabel('h[n]','fontsize',14)


%Frequency domain response
[H,W] = freqz(h,1 );
plot(W/pi,20*log10(abs(H)),'r')
title('LPF with Hamming window, N = 201','fontsize',14)
xlabel('\omega/\pi','fontsize',14)
ylabel('|H(\omega)|, dB','fontsize',14)
axis([0 1 -100 10])
pause
