WHEN THE INPUT DOESN’T “FIT”
THE PHENOMENON OF LEAKAGE

Up until now, I’ve tried to contrive signals which will produce clean DFT output. Unfortunately, almost every “real-world” signal that you’ll process using the DFT will produce somewhat messy results. You probably noticed in the last section that signals which were composed of only one sinusoid were capable of producing spectra with many strange peaks and valleys when we started zero-padding them.

As it turns out, when any frequency component of the input signal does not perfectly match up with an available bin frequency, the energy related to that frequency component will “spill” out into all of the other bins. This is a phenomenon known as spectral leakage.

Figure 1 Allows you to see the effect of spectral leakage by altering the frequency of the input signal. The slider at the top of the figure allows you to change the input frequency smoothly from 1Hz to 3Hz. Notice that when the frequency of the input signal perfectly matches one of the available bin frequencies, there is no leakage. As soon as the frequency varies even slightly from a bin frequency, all of the other bins will assume a non-zero magnitude.


Figure 1.  DFT Response to Different Input Frequencies






LEAKAGE
SAMPLING A CONTINUOUS SPECTRUM

To understand leakage, we must appreciate that the Discrete Fourier Transform actually produces a sampled version of a Continuous Fourier Transform. The continuous frequency spectrum of a sampled sine wave is approximated by the Sinc function shown in Figure 2.1



Figure 2.  The Sinc Function.
The DFT of a Sampled Sine Wave is Approximated by the Sinc Function.

The Discrete Fourier Transform actually gives us a sampled version of this continuous spectrum. In Figure 3, each sample of the DFT output is plotted as a blue square on this continuous curve. When the input signal has an integral number of periods, all of the DFT samples will lie at either zero magnitude or on the very tip of the continuous curve’s main “bump”. As soon as the frequency of the input signal drifts away from an available bin frequency, the other bins assume a non-zero magnitude due to the shape of the continuous curve.


Figure 3.  Viewing Leakage as the Sampling of a Continuous Spectrum


Now that we understand the sampled nature of the DFT, the results we saw when zero-padding our signal in the previous section might make a bit more sense.

1. The continuous curve has this distinct shape because we’re actually sort of misusing the Fourier Transform. The Fourier Transform assumes that the input signal is periodic and infinitely long. When we feed a finite-length input signal into the Fourier Transform we are actually implicitly multiplying the input signal with a rectangular window (A rectangular window is just a signal with ones for each its samples) The spectrum of a rectangular window is approximated by the so-called sinc function which is defined as, sin(x) / x (shown in Figure 2). When we multiply our input signal with this rectangular window, the DFT output will be affected. Specifically, the output spectra of our signal will be convolved with the spectra of a rectangular window. When we convolve the two signals we are left with this characteristic sinc spectrum. To really understand this phenomenon, we need to introduce and understand the notion of convolution. If there's enough interest, I'll create a section on convolution and attempt to dig further into this topic. In the meantime, let's slowly back away and go read Wikipedia's page on the convolution theorem.

WINDOWING
REDUCING LEAKAGE

A first step towards understanding leakage is to think about the discontinuities that would exist at the endpoints of our input signal if we were to loop it. Figure 4 shows an imaginary “unrolling” of our input signal in the top row of the figure.2 Discontinuities (instantaneous jumps) are shown in red. Notice that whenever leakage occurs, there are discontinuities present. When the leakage is at its worst, there is no jump, but rather a very sharp V-shaped corner in the waveform.

We might assume that these discontinuities are the cause of the leakage. In order to remove the discontinuities, we can window our signal.3 Windowing is a fancy term for multiplying the input signal with a “window” signal. We can craft a window signal which tapers off to zero at its ends in order to remove the discontinuities in our looped signal. In Figure 4, the window is shown in grey. You can see that the windowed signal loops smoothly without discontinuities and ugly corners. The continuous spectrum of a this windowed sine wave is shown in green. You’ll notice that the effect of leakage would be less pronounced if we chose to sample the windowed curve.


Figure 4.  Windowing The DFT's Input Signal



You should be aware that there are many types of windows, and each can be appropriate depending upon the circumstances and needs of your analysis task. I suggest that you refer to the Wikipedia article on windowing if you want to know more about the various window functions and their properties.




2. To accommodate the visualization of the looping, please note that I’ve reduced the frequency of the input signal to the range between 1 and 2 Hz.

3. Windowing isn’t a panacea. For example, windowing can be very destructive to low frequency signals.