Start with what we know:
- 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.