Sunday, February 21, 2010

DSP: Tutorial Post #10: Windowing




- DFT can only be performed over a finite-time sample interval

- We can think of the DFT input singal as the product of an input signal existing for all time and a rectangualr window whose magnitude is 1 over the sample interval

- Anytime we take the DFT of a finite-extent input sequence we are, by default, multiplying that sequence by a window of all ones and effectively multiplying the input values outside the window by zeros

- Remember: The continuous Fourier transform of the rectangular window IS the sinc function

Windowing premultiplies input data supplied to the FFT with a value that smoothly decreases to zero at each end of data. The purpose is to reduce "leakage" aberrations in the FFT output that are introduced by sudden changes in the data at the start and end of data. Windowing reduces DFT leakage by minimizing the magnitude of the sinc function’s sin(x) / x sidelobes. This is accomplished by forcing the amplitude of the input time sequence at both the beginning and the end of the sample interval to go smoothly toward a single common amplitude value. (taken from Understanding Digital Signal Processing – Lyons).

Matlab supports the following windows:
barthannwin,bartlett, blackman,blackmanharris,bohmanwin,chebwin,flattopwin,gausswin, hamming,hann,kaiser, nuttallwin,parzenwin,rectwin,triang,tukeywin

In this example we will compare the sidelobes created by the rectangle window as compared to the blackman window.


%% Example of Windowing
close all;
clear all;
% Example of windowing
freq = 12; % continues time signal frequency in Hz
fs=800; % sample frequency 800Hz (how many samples per second)
Ts=1/fs; % sample period (time between consecutive digital captures of the continues time sigal)
n=0:1*fs; % sample index (fs=samples per second), 2 second (how long to watch the signal)
tn=n*Ts; % our x axis, descrete measurements
x=cos(2*pi*freq*tn); % create signal
w=blackman(length(x)) % create a blackman window the same length as x(t)
c = x.*w'; % multiply our signal and window, the ".*" completes element by
% element multiplication. The "'" transposes our window matrix
figure('Color',[1 1 1]);
plot(tn,c,tn,w,'--r');
title('x(t) windowed with Blackman');
axis([-.5 1.5 -1.5 2.5]);
% Freq domain plot
[Y,f]=ComputeSpectrum(x,fs,2^14);
[X,f]=ComputeSpectrum(c,fs,2^14);
figure('Color',[1 1 1]);
plot(f,20*log(Y),f,20*log(X),'--g');box off;hold on;
xlabel('Frequency');
ylabel('Amplitude');
title('Spectrum w/ Window');
axis('tight');
legend('Rectangular Window','Blackman Window');

1 comment:

Unknown said...

Though you posted this long time ago, I must say it has helped me A LOT, Thank you!