%Attique Rehman.
%28395921
%Digital Signal processing.
%Proj 4.
%Presented To Tom Poonnen.

%*******The Kaiser Window Project*********

% Part 1; The Diff Types Of FIR Filters

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

clear all;

%Part 1.
% Different types of FIR Filters.

%Finite Impulse Responce filters have feed forward coefficients,
%but no feed back coefficients. These filters
%are easy to design, extremely flexib;e and always stable.
%The only draw back is that they require alot
%of CPU strokes for most applications. 
%The Advantage:

%The single biggest advantage to FIR filters is 
%they can implement any impulse respsonce, provided it is finite
%length. This is a big change from analogue filter design.

%FIR filters work by multiplying an array of the most recent n data
%samples by an array of constants and summing the elements of the resulting array.
% Four diff types Of FIR Filters are:

%1)FIR 1; It implements the classical mehtod of windowed linear
			%phase FIR digital filter design. It designs filters in
         %standard lowpass, bandpass, highpass and bandpass config.
         %

%2) FIR2; It designs windowed digital FIR filters with arbitrarily
				%shaped freq responce.

%2) FIR3; 

%3) FIR4

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


%Part 2.

clear all;

w1s=0.5*pi;
w1p=0.3*pi;
w2s=0.6*pi;
w2p=0.8*pi;
As=80;
width1=w1s-w1p;
width2=w2p-w2s;
w1c=(w1p+w1s)/2;
w2c=(w2p+w2s)/2;

As=80;
delta_f=min(width1/(2*pi),width2/(2*pi));

Z=(As-7.95)/(914.36*delta_f)+1;
Mc=ceil(Z);
beta=0.11*(As-8.7);
hd=ideal_lph(w1c,Z)-ideal_lph(w2c,Z)+ideal_lph(pi,Z);
w_kai=KAISER(beta);
h=hd.*w_kai;
[H,W]=freqz(h,1,500);
db=20*log10(abs(H));


%==================================================

%Part 3.
 
%Given, y(n) = x(n)*h(n).
%Plotting X(ejw) & Y(ejw).

%h(n) is the Type 1 FIR Filter.

%where magnitude = 20*log10(abs(H));
%====================================================

n=0:449             %n is defined between the range from 0 ----- 449.
x=cos(0.2*pi*n)+sin(0.54*pi*n)+sin(0.56*pi*n)+cos(0.58*pi*n)+cos(0.9*pi*n)
[H,W]=freqz(x,1,256);       %Frequency Responce 
mag=abs(H);     
figure(1);
plot(W/pi,mag);
title('Part 3, Fourier Transform');
xlabel('Frequency');
ylabel('Amplitude X(ejw)');


%Part 4.

%Explaining Gibbs Phenomenon.

%The non uniform convergence of the
%fourier series for discontinuous fiunctions and in particular
%theoscillatory behaviour of the finite sum is mainly referred as Gibbs
%Phenomenon.

%The Gibbs Phenomenon deals with the issue of recovering point values of a
%function from its expansion coeefficients.
%Alternatively it can viewed as the possibbility of the recovery of local
%information from global info.

%==============End Of The Project.===================

