%Damon Praefke
%Project 3
%25080241



function[]=dpraefke2();


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Output of the wavread and time vectors


t=-2.86:0.01:2.86;
[xc,FS,NBITS]=wavread('sample.wav')
x=[zeros(1,100),xc',zeros(1,100)];

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Impulse response of various bandpass and lowpass filters

[B,A]=butter(2,0.5);
h2=30*sinc(30*t).*cos(2*pi*25*t);
h3=15*sinc(15*t).*cos(2*pi*25*t);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Outputs of result of filtering x through various bandpass and lowpass filters

y=filter(B,A,x);
y2=filter(h2,1,x);
y3=filter(h3,1,x);

yn=y./(2*max(y));
yn2=y2./(2*max(y2));
yn3=y3./(2*max(y3));

%Write outputs to new wave files
%wavwrite(yn,22050,8,'filtwav');
%wavwrite(yn2,22050,8,'filtwav2');
%wavwrite(yn3,22050,8,'filtwav3');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Plot of the wavread result

figure(1);

plot(t,x);
title('Plot of x(t)');
xlabel('t');
ylabel('x(t)');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Plots of the various bandpass filters

figure(2);


subplot(2,1,1);
plot(t,h2);
title('Plot of h2(t) B=30');
xlabel('t');
ylabel('h2(t)');

subplot(2,1,2);
plot(t,h3);
title('Plot of h3(t) B=15');
xlabel('t');
ylabel('h3(t)');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Plots of the output of the filters

figure(3);

subplot(3,1,1);
plot(t,y);
title('Plot of y(t) (Butterworth filtered');
xlabel('t');
ylabel('y(t)');

subplot(3,1,2);
plot(t,y2);
title('Plot of y2(t) Bandpass filtered B=30');
xlabel('t');
ylabel('y2(t)');


subplot(3,1,3);
plot(t,y3);
title('Plot of y3(t) Bandpass filtered B=15');
xlabel('t');
ylabel('y3(t)');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

figure(4);

subplot(2,1,1);
[X,f]=fouriert(x,t);
plot(f,20*log10(abs(X)));
title('Plot of X(f)');
xlabel('f');
ylabel('|X|');

subplot(2,1,2);
[Y,f]=fouriert(y,t);
plot(f,20*log10(abs(Y)));
title('Plot of Y(f) of Butterworth output');
xlabel('f');
ylabel('|Y|');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

figure(5);

subplot(3,1,1);
[X,f]=fouriert(x,t);
plot(f,20*log10(abs(X)));
title('Plot of X(f)');
xlabel('f');
ylabel('|X|');

subplot(3,1,2);
[H2,f]=fouriert(h2,t);
plot(f,20*log10(abs(H2)));
title('Plot of H2(f)');
xlabel('f');
ylabel('|H2|');

subplot(3,1,3);
[Y2,f]=fouriert(y2,t);
plot(f,20*log10(abs(Y2)));
title('Plot of Y2(f)');
xlabel('f');
ylabel('|Y2|');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

figure(6);

subplot(3,1,1);
[X,f]=fouriert(x,t);
plot(f,20*log10(abs(X)));
title('Plot of X(f)');
xlabel('f');
ylabel('|X|');


subplot(3,1,2);
[H3,f]=fouriert(h3,t);
plot(f,20*log10(abs(H3)));
title('Plot of H3(f)');
xlabel('f');
ylabel('|H3|');


subplot(3,1,3);
[Y3,f]=fouriert(y3,t);
plot(f,20*log10(abs(Y3)));
title('Plot of Y3(f)');
xlabel('f');
ylabel('|Y3|');


