x=wavread('sample.wav');

y=x(1:256); 	%adjusts length to a power of 2
stem(y);			%Plots in discreet time the initial function
title('Sample wave');

Y=fft(y);		%Takes DTFT of initial signal
Yp=fft(y,500);	%Takes DTFT of signal padded with zeros
subplot(211);   %Subplots
stem(Y);
ylabel('Y(f)');
xlabel('f');
title('DTFT of sample.wav');
subplot(212)
stem(Yp);
ylabel('Y(f)-Padded');
xlabel('f');
title('DTFT of sample.wav padded with zeros');

Ys=fftshift(Y); %Shifts the DTFT of signal
Yps=fftshift(Yp);

subplot(211)
stem(Y);
xlabel('f');
ylabel('Y(f)-Shifted');
title('DTFT of sample.wav shifted');

subplot(212)
stem(Yp);
ylabel('Y(f)-Padded&Shifted');
xlabel('f');
title('DTFT of sample.wav padded with zeros and shifted');

subplot(221)
stem(abs(Y));
ylabel('|Y(f)|');
xlabel('f');
title('Magnitude of Shifted Signal');
subplot(222)
stem(angle(Y));
ylabel('angle[Y(f)]');
xlabel('f');
title('Frequency Response of Shifted Signal');
subplot(223)
stem(abs(Yp));
ylabel('|Y(f)|');
xlabel('f');
title('Magnitude of Padded & Shifted Signal');
subplot(224)
stem(angle(Yp));
ylabel('angle[Y(f)]');
xlabel('f');
title('Frequency Response of Padded & Shifted Signal');


% FIR1 filter
Wn=[.3 .5];              %Filter Specifications 
B=fir1(32,Wn);
clf;
z=filter(B,1,y);        %Filters the origional function
Z=fftshift(fft(z,500)); %Takes DTFT shifted of filtered signal
subplot(221)
stem(abs(Z));
ylabel('magnitude[Y(f)]');
xlabel('f');
title('Magnitude of FIR1 filter');
subplot(222)
stem(angle(Z));
ylabel('angle[Y(f)]');
xlabel('f');
title('Frequency Response of FIR1 filter');

subplot(212)
stem(z);
title('fir1.wav output file')
wavwrite(z,'fir1.wav')

% FIR2 filter
F=[0 .2 .5 1];
M=[0 .1 .9 1];
B=fir2(32,F,M);
clf;
z=filter(B,1,y);
Z=fftshift(fft(z,500));
subplot(221)
stem(abs(Z));
ylabel('magnitude[Y(f)]');
xlabel('f');
title('Magnitude of FIR2 filter');
subplot(222)
stem(angle(Z));
ylabel('angle[Y(f)]');
xlabel('f');
title('Frequency Response of FIR2 filter');

subplot(212)
stem(z);
title('fir2.wav output file')
wavwrite(z,'fir2.wav')

% Butter filter
Wn=[.3 .75];
B=butter(32,Wn);
clf;
z=filter(B,1,y);
Z=fftshift(fft(z,500));
subplot(221)
stem(abs(Z));
ylabel('magnitude[Y(f)]');
xlabel('f');
title('Magnitude of Butter filter');
subplot(222)
stem(angle(Z));
ylabel('angle[Y(f)]');
xlabel('f');
title('Frequency Response of Butter filter');

subplot(212)
stem(z);
title('butter.wav output file')
wavwrite(z,'butter.wav')


