The practicing instrumentation engineer's guide to the DFT - Part 2: Spectral leakage and windowing
Author's note: There are many books and articles on the Fourier Transform and its implementation available. A quick survey of these resources shows that they are not geared to the needs of the "Practicing Instrumentation Engineer" but to the needs of DSP engineers who work in many fields. This article explains some of the math required to get "Calibrated" Fourier Transforms.[Part 1 of this article looked at understanding DFT and FFT implementations.]
Spectral Leakage and Windowing
What happens if we change the number of cycles of our input data to a non-integer number? With that in mind let's generate 10.5 cycles of sine wave data to use as the input to our DFT.
Remember that a DFT calculates the Fourier spectra by assuming that the input waveform that you feed it repeats forever. Looking at figure 1's plot we can see that if we kept repeating the waveform it would always be a nice perfect sine wave with no discontinuities.
But looking at Figure 5's plot we see that adding this waveform results in a large glitch where the waveforms repeat as shown in Figure 7. The DFT can't tell that this is not what we had in mind, it just thinks that this waveform with the glitch repeats forever. And that waveform produces the DFT as shown in figure 6.
So if we input a coherent, even number of sine wave cycles that happens to fall exactly on a bin center, we get a textbook perfect DFT output.
But real world signals won't have frequencies exactly at bin centers and this causes a problem that is called "Spectral Leakage". Not only is the amplitude wrong in the resulting DFT, but the waveform gets smeared across all frequencies, thus making for a not very textbook display and potentially obscuring waveform features that are below the new higher noise floor.
What is wrong with our data? The middle is fine, it's the ends that have the issue.
This Spectral Leakage problem is commonly solved by applying a Window to our input data, that tapers the data off at both ends - so the DFT never sees any discontinuity.
A common window is the Hanning window (More properly known as the Hann Window as Mr. von Hann first presented it, but everyone calls it "Hanning" so we will too), this window is defined as,
This term Wj is a window factor and it is multiplied to our raw waveform data point by point. Figure 8 shows the function of this window for j=0 to j=499.
Applying this Hanning window to our existing 10.5 cycle sinewave waveform produces a new data set and DFT as shown in figures 9 and 10.
The Windowed DFT of Figure 10 shows a great improvement in spectral leakage to adjacent bins, but the absolute amplitude is still in error and by a greater amount than by not using any window at all!