%Vedrana Sarajlic
%ID#:2730-3757
%EE416
%Project 4: Kaiser Window


%Type 1 FIR filter has M even, while type 2 FIR filter has M odd.

%Type 1 FIR using Kaiser Window
Wp = 0.4*pi;
n=0:30;
hd = sin(Wp*n)/(pi*n);

w1p=0.3*pi;
w1s=0.5*pi;
Rp=1;
w2s=0.6*pi;
w2p=0.8*pi;
A=80;

width1=w1s-w1p;
width2=w2p-w2s;

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

M=[(A-7.95)/(1.36.*delta_f)+1];
B=0.1102*(A-8.7);

w_kai=kaiser(M,B);
h=hd.*w_kai';
figure(1);
freqz(h,1)

[H,W]=freqz(h,1,500);

%y(n)=x(n)*h(n)
n=0:449;
x=cos(.2*pi*n)+sin(.54*pi*n)+sin(.56*pi*n)+cos(.58*pi*n)+cos(.9*pi*n);
X=freqz(x,1,256);
figure(2);
freqz(x,1)



y=conv(x,h);
Y=freqz(y,1,256);
figure(3);
freqz(y,1)

%Gibbs Phenomenon occurs when function overshoots at the point of discontinuity,
%oscillations occur at the point of discontinuity.




