Recent discussion of bin width got me thinking about that and the
how/why of windowing data before performing an FFT.
As one who always did better in lab courses than theory, I decided to do
some experiments. The attached program is my attempt to illustrate
effects of window width and sampling frequency. I plan to add
illustrations of effect of window type and numerical precision
(emulating 8,10 or 16 bit precision on an 32 bit machine with automatic
multiprecision floating point should be interesting ;)
I'd appreciate comments from:
1. fellow newbies/novices/STUPIDENTs
Did you find this helpful?
2. the DSP experts
1. First importance - any blatant errors?
2. Have I done anything that, although correct, would mislead?
3. Any suggestions?
PS - I explicitly avoid "normalization" as much as possible.
It has been a problem with DSP (and other) textbooks.
The following program is written for Scilab 4.1.2 (should be compatible
with Scilab 5.x) and has been run under WinXP.
drawlater
for i=240:250; f(i-239)=i; end;
N=100;
t=(0:N-1)*.001; // 1 kHz sample rate
w = window('hn',100); // .1 second window
subplot(3,2,1)
for i=1:11
plot2d( 1:N, abs(fft(sin(2*%pi*f(i)*t) .* w)), i);
end
title("100 SAMPLES -- NO PADDING")
N=1000;
t=(0:N-1)*.001; // 1 kHz sample rate
w = window('hn',100); // .1 second window
w(101:1000)=0; // zero pad
subplot(3,2,3)
for i=1:11
plot2d( 1:N, abs(fft(sin(2*%pi*f(i)*t) .* w)), i);
end
title("100 SAMPLES ZERO PADDED TO 1000")
w = window('hn',200); // .1 second window
w(201:1000)=0; // zero pad
subplot(3,2,5)
for i=1:11
plot2d( 1:N, abs(fft(sin(2*%pi*f(i)*t) .* w)), i);
end
title("200 SAMPLES ZERO PADDED TO 1000")
// =========================================================
for i=240:250; f(i-239)=10*i; end;
N=1000;
t=(0:N-1)*.0001; // 10 kHz sample rate
w = window('hn',1000); // .1 second window
subplot(3,2,2)
for i=1:11
plot2d( 1:N, abs(fft(sin(2*%pi*f(i)*t) .* w)), i);
end
title("1000 SAMPLES -- NO PADDING")
N=10000;
t=(0:N-1)*.0001; // 10 kHz sample rate
w = window('hn',1000); // .1 second window
w(1001:10000)=0; // zero pad
subplot(3,2,4)
for i=1:11
plot2d( 1:N, abs(fft(sin(2*%pi*f(i)*t) .* w)), i);
end
title("1000 SAMPLES ZERO PADDED TO 10000")
w = window('hn',2000); // .1 second window
w(2001:10000)=0; // zero pad
subplot(3,2,6)
for i=1:11
plot2d( 1:N, abs(fft(sin(2*%pi*f(i)*t) .* w)), i);
end
title("2000 SAMPLES ZERO PADDED TO 10000")
drawnow