%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Dhanushka Amarasinghe
% EE 416
% Project No.3
% Due-11/13/01
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all;

wp=0.4*pi;                          % Pass band cutoff frequency
n1=0:30;                            % Size of matrix n1    
h=sin(wp*(n1-15))./(pi*(n1-15));    % Impulse response  
h(16)=wp/pi;
%1
[H,W]=freqz(h,1,256);               % Frequency response of the signal    
mag=20*log10(abs(H));               % Magnitude of the frequency response in dB
figure(1);
plot(n1,h);                         % Plot of impulse response
title('Impulse response');
xlabel('n1');
ylabel('function of h');

figure(2);
plot(W/pi,mag);							% Phase of the impulse
title('Frequency respose');
xlabel('frequency range from 0 to 1');
ylabel('funtion of H');

%2
length(h)
win=hamming(31);							% Hamming window
length(win)
h1=h.*win';									
[H1,W1]=freqz(h1,1,256);
mag1=20*log10(abs(H1));
figure(3);
plot(n1,h1);								% Impulse of h1
title('Impulse response');
xlabel('n1');
ylabel('function of h1');

figure(4);
plot(W1/pi,mag1);							% Phase of h1
title('Frequency respose');
xlabel('frequency range from 0 to 1');
ylabel('funtion of H');

haa=fir1(30,0.4);							% FIR1 filter
[HAA,W2]=freqz(haa,1,256);
mag3=20*log10(abs(HAA));
figure(5);
plot(n1,haa);
title('Frequency respose');
xlabel('frequency range from 0 to 1');
ylabel('funtion of HAA');


%(c)

% Some of the diffterent types of Windows are HAMMING, KAISER and GAUSSIAN. 
% FIR1 uses a Hamming window of length N+1.
%The window method begins with an ideal lowpass filter, whose impulse 
%response is of infinite duration, and truncates it, producing a finite impulse response. 