% Jonathon Panek   
% EE 416
% Project 3
% Due 11/13/01
% ===================================================================
    clear all;
% The impulse response of a lowpass filter h(n)=sin(wp*n-15)/pi*n-15
% Passband cutoff=wp
	n=0:30;
	wp=0.4.*pi;
	h=sin(wp*(n-15))./(pi*(n-15));
% The zero element h(0)=wp/pi
    h(16)=0.4;
% Plot h(n)=hd(n-15) for 0<n<30
	figure(1);
    stem(n,h), grid;
    title('Impulse Response of a Lowpass Filter');
    xlabel('n');
    ylabel('h(n)');
% Plot H(e^jw)
    figure(2);
    [H,W]=freqz(h,1,2001);
    plot(W/pi,20*log10(abs(H))), grid;
    title('Magnitude');
    xlabel('W/pi');
    ylabel('|H(e^jw)| (dB)');
% FIR filter hf(n)=h(n)w(n) where is a Hamming window
    win=hamming(31);
    h1 = h.*win';
    figure(3);
    [H1,W1]=freqz(h1,1,2001);
    plot(W1/pi,20*log10(abs(H1))), grid;
    title('Hamming Window');
    xlabel('W1/pi');
    ylabel('|H1(e^jw)| (dB)');
% Verify the filter design
% y(n)=x(n)*h(n)
    figure(4);
    n=0:1:499;
    x=cos(.2*pi*n)+sin(.54*pi*n)+sin(.56*pi*n)+cos(.58*pi*n)+cos(.9*pi*n);
    [X,W]=freqz(x,1,512);
    subplot(2,1,1);
    plot(W/pi,abs(X));
    title('Before Filter');
    xlabel('W1/pi');
    ylabel('|X(e^jw)| (dB)'); 
    y=conv(x,h);
    [Y,W2]=freqz(y,1,512);
    subplot(2,1,2);
    plot(W/pi,abs(Y));
    title('After Filter');
    xlabel('W1/pi');
    ylabel('|X(e^jw)H(e^jw)| (dB)'); 
% ===================================================================
% Different types of windows and their application in DSP
% ===================================================================
% Window Function: 		w(k)=0 for |k|>(N-1)/2
% Rectangular Window:	1
% Hanning Window:		0.5[1+cos(2pik/(N-1))]
% Hamming Window:		0.54+0.46cos(2pik/(N-1))
% Blackman Window:		0.42+0.5cos(2pik/(N-1))+0.08cos(4pik/(N-1))
% ===================================================================
% The windowing method of FIR filter design bases the filter impulse 
% response sequence (and the filter transfer function) on the 
% coefficients of the Fourier series expansion of the desired 
% frequency response function. Since this series will be infinite, 
% the series must be truncated. This means of truncating the series
% is a technique known as windowing. A causal filter can be produced
% by delaying the impulse response by an appropriate number of 
% discrete time units.

  
  
   