%**************************************************************************************

%Hok-Lim Li (29045906) 
%EE 416 Project 3
%11-13-2001

%**************************************************************************************

% (1) If h(n)=hd(n-15)for 0<=n<=30, plot h(n) and H(e^jw)

wp=0.4*pi;										% Define passband cutoff
n1=0:30;											% set sample range
h1=sin(wp*(n1-15))./(pi*(n1-15));		% Define h(n) 
h1(16)=wp./pi;									% Define h(n) when n=16

figure(1)
plot(n1,h1)										% Set plot 1
title('Impulse Response');	
xlabel('sample');
ylabel('Amplitude of h(n)');


[H,W]=freqz(h1,1,256);							% Take the Fourier Transform
mag=20*log10(abs(H));							% Define the magnitude of filter in db
figure(2)	
subplot(2,1,1);
plot(W/pi,mag);									% Plot H(e^jw)
title('Magnitude H(e^jw)');
xlabel('Frequency');
ylabel('Amplitude');

phase=unwrap(angle(H));							% Define phase
subplot(2,1,2);
plot(phase);
title('Magnitude H(e^jw)');
xlabel('Frequency');
ylabel('Amplitude');


% (2) Desigh an FIR filter defined by hf(n)-h(n)w(n) denotes the Hamming 
% window verify the design.

Win=hamming(31);									% Set the length of Hamming Window
ha=h1.*Win';										% Define the FIR filter
Ha=freqz(ha,1,256);								% Find the frequency Response
mag1=20*log10(abs(Ha));							% Find the magnitude of filter

figure(3)
subplot(2,1,1);
plot(n1,ha);										% Plot the FIR filter
title('FIR Filter Design with Hamming Window');
xlabel('Frequency');
ylabel('angle');

subplot(2,1,2);
phase2=unwrap(angle(Ha));						% Find the phase
plot(phase2);										% Plot Phase
title('Phase H(e^jw)');
xlabel('Frequency');
ylabel('Angle');


% (3) explain the different types of Windows and
%the applications of windows in signal processing. Emphasize on FIR filter design 
%using Windows.

% 		In Matlab, we have lots kind of Windows. For example, Kaiser,Blackman, 
% Hamming, Hann, Bartlett, Boxcar and Cheby window. Let me explain some of
% them.
% 
% Kaiser   :   Kaiser window has an adjustable parameter beta which controls
%           how quickly it approaches zero at the edges, defined by
%           Kaiser(x,tau,beta)=Io(beta(sqrt(1-(x/beta)^2)))/Io(beta)
%           where Io(beta) is simplified Bessel function.
%				w = kaiser(n,beta) returns an n-point Kaiser (I0 - sinh) window 
%				in the column vector w. beta is the Kaiser window  parameter that 
%				affects the sidelobe attenuation of the Fourier transform of the window.


% Hamming  : Hamming window is defined by
%            Hamming(x,tau,beta)=beta+(1-beta)*cos(x*pi/tau)
%            where beta=0.54. This window has disadvantage of being discontinous
%            at the edges. w = hamming(n,'sflag') returns an n-point Hamming window 
%				 using the window sampling specified by 'sflag', which can be either 
%				'periodic' or 'symmetric' (the default). When 'periodic' is specified, 
%				 hamming computes a length n+1 window and returns the first n points.

% Blackman : The blackman window is similar ro Hann and Hamming window
%            with one addtional term
%            Blackman(x,tau)= 0.42+0.5*cos(pi*x/tau)+0.8*cos(2pi*x/tau)
%            it approaches zero more smoothly above pi, although it has a 
%            bad frequency response below pi. w = blackman(n,'sflag') returns an n-point 
%				 Blackman window using the window sampling specified by 'sflag', which 
%				 can be either 'periodic' or 'symmetric' (the default). When 'periodic' 
%				 is specified, blackman computes a length n+1 window and returns the first 
%				 n points.




