% bonus problem solution for second midterm
%
fs=780;
T=1/fs;
t=0:T:1;
N=length(t);
fr=fs/N;
ff=0:fr:fs-fr;
xm=chirp(t,20,1,360);
xa=xm+cos(120*pi*t)+cos(240*pi*t)+cos(360*pi*t)+ ...
   cos(480*pi*t)+cos(600*pi*t)+cos(720*pi*t);
h=[1 zeros(1,12) -1];
y=filter(h,1,xa);
subplot(4,2,1);zplane(h);title('pole/zero diagram');
[H,w]=freqz(h,1,N,'whole');
subplot(4,2,2);plot(ff,abs(H));title('frequency response');
subplot(4,2,3);plot(xa);title('contaminated signal');
subplot(4,2,4);plot(ff,abs(fft(xa)));
title('Fourier spectrum of the contaminated signal');
subplot(4,2,5);plot(xm);title('desired signal');
subplot(4,2,6);plot(ff,abs(fft(xm)));
title('Fourier spectrum of the desired signal');
subplot(4,2,7);plot(y);title('filtered signal');
subplot(4,2,8);plot(ff,abs(fft(y)));
title('Fourier spectrum of the filtered signal');