%Demo done during Session 22 to illustrate %the FFT's of various windows % clf set(0,'defaultaxesfontsize',22); clear Nw=input('window length'); Nfft=input('FFT length'); woff=pi/Nw; coff=(Nw-1)/2; wrec=ones(1,Nw); wsin=cos(woff*((0:Nw-1)-coff)); whan=.5*wrec+.5*cos(2*woff*((0:Nw-1)-coff)); wham=.54*wrec+.46*cos(2*woff*((0:Nw-1)-coff)); xn=0:Nw-1; plot(xn,wrec,'y','LineWidth',4); axis([0 Nw-1 0 1]) xlabel('n') hold plot(xn,wsin,'m','LineWidth',4); plot(xn,whan,'c','LineWidth',4); plot(xn,wham,'r','LineWidth',4); legend('Rect','Sine','Hanning','Hamming'); title('Various Windows') hold off pause omega=linspace(-pi,pi,Nfft); frec=20*log10(abs(fftshift(fft(wrec,Nfft)))); fsin=20*log10(abs(fftshift(fft(wsin,Nfft)))); fham=20*log10(abs(fftshift(fft(wham,Nfft)))); fhan=20*log10(abs(fftshift(fft(whan,Nfft)))); frec=frec-max(frec); fsin=fsin-max(fsin); fhan=fhan-max(fhan); fham=fham-max(fham); absmin=min([min(frec) min(fsin) min(fhan) min(fham)]); plot(omega,frec,'y','LineWidth',4); axis([-pi pi -100 0]) xlabel('Omega (rps)') ylabel('Magnitude (dB)') hold on pause plot(omega,fsin,'m','LineWidth',4); pause plot(omega,fhan,'c','LineWidth',4); pause plot(omega,fham,'r','LineWidth',4); legend('Rect','Sine','Hanning','Hamming'); title('Spectra of Various Windows') hold off