%Andrew Karkau
%EE416
%akarkaup2.m


[y,fs,nbits]=wavread('sample.wav');
y=y';
[Y,f]=fouriert_b(y,1/fs);				%freq spectrum of sample.wav
YdB=20.*log(abs(Y));
phi=angle(Y);
subplot(2,1,1)
plot(f,YdB)
title('Frequency spectrum of sample.wav')
xlabel('Hz')
ylabel('dB')
subplot(2,1,2)
plot(f,phi)
title('Phase')
xlabel('Hz')

z=zeros(1,139);							%force ypad to 512
ypad=[y,z];
[Ypad,fp]=fouriert_b(ypad,1/fs);
YpaddB=20.*log(abs(Ypad));
phip=angle(Ypad);
figure(2)
subplot(2,1,1)
plot(fp,YpaddB)
title('Frequency spectrum of sample.wav with zero padding')
xlabel('Hz')
ylabel('dB')
subplot(2,1,2)
plot(fp,phip)
title('Phase')
xlabel('Hz')


w1=300/(fs/2);
w2=7500/(fs/2);
b=fir1(36,[w1,w2]);							%36th order fir bandpass filter 300Hz to 7500Hz
xa=filter(b,1,ypad);								%apply filter to signal
[Xa,fx]=fouriert_b(xa,1/fs);
XadB=20.*log(abs(Xa));
figure(3)
plot(fx,XadB)
title('Frequency spectrum of sample.wav with fir bandpass')
xlabel('Hz')
ylabel('dB')

[b,a]=cheby2(9,20,[w1,w2]);				%9th order cheb bandpass filter 300Hz to 7500Hz
xb=filter(b,a,ypad);							
[Xb,fx]=fouriert_b(xb,1/fs);
XbdB=20.*log(abs(Xb));
figure(4)
plot(fx,XbdB)
title('Frequency spectrum of sample.wav with Chebyshev bandpass')
xlabel('Hz')
ylabel('dB')

wn=100/(fs/2);
[b,a]=butter(9,wn,'high');					%9th order Butterworth highpass at 100Hz
xc=filter(b,a,ypad);
[Xc,fx]=fouriert_b(xc,1/fs);
XcdB=20.*log(abs(Xc));
figure(5)
plot(fx,XcdB)
title('Frequency spectrum of sample.wav with Butterworth highpass')
xlabel('Hz')
ylabel('dB')
