%Andrew Karkau
%Matlab project4
%November 13, 2001

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

width1=w1s-w1p;
width2=w2s-w2p;
w1c=0.4*pi;						%cutoff frequency
w2c=0.7*pi;						%cutoff frequency
Q1=width1/(2*pi);
Q2=width2/(2*pi);
deltaf=min(Q1,Q2);
deltaf=abs(deltaf);
M=ceil(((As-7.95)/(14.36*deltaf))+1);
M=M+1;
beta=0.1102.*(As-8.7);

w=kaiser(M,beta);						%Kaiser window
w=w';

m=0:1:(M-1);
m=m-26;

h1=(w1c*sinc(2*w1c*m));
h2=(w2c*sinc(2*w2c*m));

h_ideal=h1-h2;							%ideal filter

figure(1)
freqz(h_ideal)							%freq response of filter
title('Frequency Response of "Ideal" Filter')

%The Frequency response of the "ideal filter" does not attenuate the stopband as
%much as expected.  I'm not sure why.

h=h_ideal.*w;							%windowed
figure(2)
freqz(h)									%freq response of filter w/ window
title('Frequency Response of Windowed Filter')

n=0:1: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);
z=zeros(1,287);
xpad=[z,x,z];
figure(3)
[X,f]=freqz(xpad);					%Freq spectrum of x
plot(f,abs(X))
title('Frequency Spectrum of x')
xlabel('pi rad/sec')

y=conv(xpad,h);						%filter x
figure(4)
[Y,f]=freqz(y);						%Freq spectrum of x after filtering
plot(f,abs(Y))
title('Frequency Spectrum of y')
xlabel('pi rad/sec')

%from the the plots you can see some attenuation in the stop band.  The stop band 
%should be almost completly eliminated.
%The problem is probably with h_ideal.
