% CS484-F13, FFT windowing effects

T=256;
lambda=12.5;
f=T/lambda;
phi=pi/3; % 60 degrees
t=0:255;
ft=cos(2*pi*f*t/T + phi);
figure; subplot(2,1,1); plot(t,ft,'b.-'); title('f(t)');

Ft=fftshift(fft(ft));
subplot(2,1,2); plot(-128:127,abs(Ft),'b.-'); title('F(f)');
title('abs(F(f)), no windowing');
h=gcf;
set(h,'PaperOrientation','landscape');
set(h,'PaperUnits','normalized');
set(h,'PaperPosition', [0 0 1 1]);
print(gcf, '-dpdf', 'FourierNoWindow.pdf');

fw=hamming(T)';
figure; subplot(2,1,1);
for i=1:10,
subplot(2,1,1); plot(fw,':'); hold on;
plot(ft.*fw,'-'); hold off;

ftw=ft.*fw;
Ft=fftshift(fft(ftw));
subplot(2,1,2); plot(abs(Ft));

% This line narrows the window.
fw=fw.*fw;
drawnow;
h=gcf;
set(h,'PaperOrientation','landscape');
set(h,'PaperUnits','normalized');
set(h,'PaperPosition', [0 0 1 1]);
print(gcf, '-dpdf', sprintf('FourierWindow%d.pdf',i));
% waitforbuttonpress;
end