x=wavread('sample.wav');
x0=x';
x=x0(1:256);
z=zeros(1,256);
x1=x;
x2=[x z];
f1=fft(x1);
fmag1=abs(f1);
inc1=pi/128;
inc2=pi/256;
w1=-pi:inc1:pi-inc1;
w2=-pi:inc2:pi-inc2;
l1=w1/pi;
l2=w2/pi;
figure(1);
subplot(2,1,1);
plot(l1,fftshift(fmag1));
title('Magnitude of Signal');
subplot(2,1,2);
plot(l1,angle(f1));
title('Phase of Signal');
figure(2);
subplot(2,1,1);
f2=fft(x2);
fmag2=abs(f2);
plot(l2,fftshift(fmag2));
title('Magnitude of Signal with padded zeros');
subplot(2,1,2);
plot(l2,angle(f2));
title('Phase of Signal with padded zeros');

%These plots show the spectral resolution gets worse and density resolution gets better.

z2=zeros(1,139);
X0=[x0 z2];
%Three different filters 1)Butterworth(Bandpass) 2)Bessel(Highpass) 3)Chebyshev(Stopband)
figure(3);
W=[.1 .3]; 
%these cutoff frequencies will allow the large peaks to remain and all other frequencies
%are attenuated(in other words remove high and low frequencies)
[y,z]= butter(1,W);				
Y=filter(y,z,X0);
plot(Y);
title('Signal after Butterworth filter');
figure(4);
Y1=fft(Y);
fmagY1=abs(Y1);
plot(l2,fftshift(fmagY1));
title('Frequecy Response of Butterworth filtered signal');

%This shows that the two large peaks attenuated very little, but the rest of the frequencies were
%attenuated a lot.

figure(5);
W=[.4];
[y2,z2]=besself(1,W,'high');
Y2=filter(y2,z2,X0);
plot(Y2);
title('Signal after Bessel filter');
figure(6);
Y2=fft(Y2);
fmagY2=abs(Y2);
plot(l2,fftshift(fmagY2));
title('Frequency Response of Bessel filtered signal');
%This plot shows that the higher frequencies were passed and the large peaks as well as the peak in the 
%center were attenuated.

figure(7);
W=[.000001 .09];
[y3,z3]=cheby1(1,.5,W,'stop');
Y3=filter(y3,z3,X0);
plot(Y3);
title('Signal after Chebyshev filter');
figure(8);
Y3=fft(Y3);
fmagY3=abs(Y3);
plot(l2,fftshift(fmagY3));
title('Frequency Response of Chebyshev filtered signal');
%This plot shows the center peak is removed by using a stopband filter which took out those low 
%frequencies.


%The question asked to remove the high and low frequencies and this was done with the first filter, the 
%Butterworth. With just the certain frequencies allowed through, this will keep a very small range of
%frequencies to pass, thus preventing large deviations in frequencies when listening to it. This can be
%seen with the output waveform. It is much more smoother and not jumpy.  