# Spectral Leakage in layman's terms

I'm trying to understand the concept of spectral leakage for the DFT, without going deep to the mathematical intricacies (it's for practical purposes). I've read from the book "Introduction to Digital Signal Processing Using MATLAB with Application to Digital Communications" that:

One reason for using DFT is to determine the spectrum of a discrete-time signal. If a frequency in the input signal does not coincide with one of the DFT bins, then the magnitude of the DFT of that particular signal will not be an impulse-like in shape. Instead, it will spread over the entire DFT bins. That is to say that the energy of the input discrete-time sequence in a particular frequency will leak into other neighboring bins. It smears the impulse-like frequency over the entire frequency bins. Therefore, the corresponding spectrum is only approximate. This is what is called the DFT leakage.

However it seems not clear to me. Are you able to explain more clearly the concept of spectral leakage for the DFT ? Maybe with an example if you can

• The DFT works perfectly for a single cycle waveform input. For a single cycle waveform, all harmonics have an integer number of cycles (by the definition of “harmonic”).
• “Spectral leakage” occurs when the input is not a single cycle waveform. As such, at least one frequency component is not represented by an integer number of cycles.

One way to view the DFT is as an algorithm that probes all possible sinusoids of the input waveform, determining frequency and phase of each. Fortunately, we have a limited number of sinusoids to probe for, knowing they must be harmonics.

One way to probe for a specific frequency, if you know the phase to expect, is to multiply by a sinusoid of the same frequency you’re looking for, at the same phase. If you take the average value of that point-by-point multiplication, it gives a value proportional to the amplitude of the component you’re looking for. Against any non-matching harmonic, the result averages to zero. Otherwise, it’s proportional to the amplitude of that frequency in the input. This is true with any number of harmonics present in the input.

Here's an example, probing for the first harmonic. There average of the results of the multiplication, averaged, yields exactly half the peak of the target:

And here is an example of the target not being the same frequency as the probe—the result wave has positive and negative points that average to zero, indicating no match:

The shortcoming for this scenario is that you need to know the phase of the harmonic component in advance. However, an alternative is to probe twice, once with a cosine wave and again with a sine wave. Because of the phase relationship they have, between the two results we can determine both amplitude and phase of the input harmonic under test. Please see my article A gentle introduction to the FFT for the finer details. In the DFT, the real part of the complex “bin” value represents its cosine result, and the imaginary part the sine result.

But, if a frequency component in the input is not an integer number of cycles, it isn’t really a sinusoid and isn’t a harmonic—easy to see if you try to repeat it end to end. And it won’t line up with any of the probe frequencies, and the math can’t have the property of either exactly matching or fully cancelling the individual probes. If the input is very close to a single cycles sinusoid, for instance, but having more than a single cycle, the probe-and-average with the expected first harmonic will give a value a bit less then a perfect match, the subsequent harmonic tests won’t full cancel either. That’s the “leakage”, if you want to view it as the missed energy spilling elsewhere.

• Wonderful answer, one of the most intuitive explanations I have seen around. – MattSt Apr 5 '20 at 14:31

Imagine that a continuous signal has a frequency component of amplitude $$A$$ at exactly 20 Hz (you can imagine it is alone, a single perfect wave).

With a FFT, or any discrete Fourier transform, you could hope that, if you have acquired the signal correctly (above Nyquist), the discrete spectrum will give you a clear peak with amplitude $$A$$ at 20 Hz. This is not the case in general. This is not the case in general, some of the energy $$A$$ will be spread around 20 Hz, at 20.1, 19.9, etc.

• but why is that, when you make the bins thinner and thinner and thinner, the spectral leakage doesn't decrease ? Intuitively, would think that, as the bins are made thinner and thinner, the spectral leakage would decrease ? But maybe that's wrong intuition. – mark leeds Jan 23 '20 at 2:52
• @Laurent Duval , in the DFT do also the frequency components that correspond to the bins frequencies produce this energy spreading ? Because, if you read the quote inside my post, it seems they don't. – themagiciant95 Jan 23 '20 at 7:43

IMHO, leakage is a poor term for it. Best representation is a much more descriptive though wordy description.

Imagine a stereo with one of those displays with the bars that correspond to frequency. They usually bounce around a lot, but they do give a representative view of the frequency content.

Now, let's take the stereo into the lab and feed it a sweep of steady tone signal starting at a low frequency going to a high one. Clearly when the tone hits the frequency of one of the bars, it should be pretty tall. But what about its neighboring bars? Leave them all zero for now.

What should happen when the tone is halfway between two bars' frequencies? Common sense would say that the two surrounding bars should be tall, the same height, but not as tall as if it hit a bar.

The DFT works sort of like that. When the frequency of a pure complex tone, measured in cycles per frame, is an integer value, then only the bin corresponding to that tone has a non-zero value. The bin index corresponds to the number of cycles per frame. For a real valued pure tone, which is the average of two opposing complex tones, two bins (conjugate pairs) are non-zero.

For a frequency that is half-way beteen two bins, the DFT is "messier" in a sense compared to the ideal stereo bars. You can think of the stereo bars as the magnitude of the bin value, which is a complex number.

Non only are the neighbor bars roughly the same height, the next out neighbors got some height too, and so on all the way around the circle.

• Is correct to say (in layman terms) that only the frequencies that not correspond to the frequencies of the bins cause the leakage ? – themagiciant95 Jan 23 '20 at 10:06
• ps: according to what you said the leakage is a problem of DFT/FTT and depends on the discrete nature of their spectrum. Is this true ? Or it happens also for DTFT ? – themagiciant95 Jan 23 '20 at 10:12
• @themagiciant95 Yes. When a pure tone is at the bin frequency there is no "leakage". This is handy because harmonics, which are multiples of the fundamental. will also fall on bins with no leakage. So, if you have a periodic siganl, if you frame it with a whole number of periods, the DFT gives you the coefficients for the Fpurier Series in nicely spaced bins. FYI, in real life, not all instrument overtones are harmonic. – Cedron Dawg Jan 23 '20 at 15:45
• ps: The term leakage implies it is a problem. That's why I think it is a bad term. It is not a problem, it how it works. Once you understand how it works, you'll know what the numbers mean. Here is a blog article of mine of another interpretation of the DFT you might find meaningful: dsprelated.com/showarticle/768.php Once you know what the numbers mean you can also figure out what the parameters of the tone are. In some cases to very high precision. That's what a lot of my other articles are about. – Cedron Dawg Jan 23 '20 at 15:45