# spectral leakage for integral number of periods

I'm attempting to understand spectral leakage and read the following quote on wikipedia:

Windowing a sinusoid causes spectral leakage, even if the sinusoid has an integer number of cycles within a rectangular window.

This confuses me, since I thought using an integral number of periods caused the leakage to disappear. Moreover, my attempts to quantify/simulate this corroborate my beliefs. For example, take the following sampled, 1Hz simple sinusoid.

import numpy as np

f = 1
ts = f / 3
fs = 1 / ts
t = np.arange(0, 5.1 * f, step=ts)
s = np.sin(2*np.pi*f*t)


with fft:

fft = np.absolute(np.fft.rfft(s))
fft /= np.sum(fft)
bins = np.fft.rfftfreq(len(t))


import numpy as np

f = 1
ts = f / 3
fs = 1 / ts
t = np.arange(0, 5.1 * f, step=ts)
s = np.sin(2*np.pi*f*t)


As expected, I get spectral leakage.

Is the Wikipedia quote incorrect, or did I misinterpret it?

Note: I think a better tag for this is spectral-leakage, but I don't have enough reputation to add it.

• The article seems to refer to a rectangular window that's shorter than the actual FFT length. Jan 23 '20 at 20:26
• Where does it say that? I missed that part when I read it. Jan 23 '20 at 22:03
• If you look at the image above it shows it Jan 24 '20 at 0:13

If you have an integer number of cycles (exactly) within a DFT frame, and the signal is not windowed (aside from the rectangular window extending to the edges of the DFT fram that would result), there is no spectral leakage. What the article is referring to I believe is more commonly called zero padding which would then cause the DFT to approach the DTFT, interpolating frequency samples between the bins. I personally wouldn't call this spectral leakage although you could mathematically get to the same conclusion in that energy in a DFT bin simply represents correlation to the input signal. If energy is there, and the bin isn't your true frequency, then sure, it is "spectral leakage". In that paradigm however of zero-padding, I prefer to associate it with the concept of frequency interpolation (again the math and the results are the same, so no disagreement - just convention).

Spectral leakage occurs when you have a non-integer number of cycles such that your true frequency is mid way between DFT bins. Each DFT bin actually has a very wide frequency response with nulls at every other bin. So a frequency that is in between bins will show up within the response of the other bins, while a frequency that is exactly on bin center (integer number of cycles) will be in the null of the responses of the other bins. There is therefore no leakage under this condition (that is not an illusion as the article suggests- there is simply no leakage - but I do see how the author presented both options and stated "depending on your point of view"). And for the other conditions the signal "leaks" into the response of the other bins.

I explain this further here at this post.

Intuition for sidelobes in FFT

When there is an exact integer number of cycles of a periodic signal in the FFT aperture, there is no spectral leakage.

I said this before but the DFT maps a periodic sequence of length $$N$$ to another periodic sequence of length $$N$$ and the iDFT maps it back. That is fundamentally what the Discrete Fourier Transform does.

More elaboration here and here.

An infinitely long sinusoid has a Fourier transform that is non-zero at only one frequency. Multiplying that sinusoid by any window function is a non-linear operation that always creates new Fourier transform components (leakage), whether or not the number of cycles in the window length is an integer. But when the window is rectangular and the number of cycles in the window length is an integer, it is possible to sample the transform (a sinc function) at only the main lobe and the zero-crossings, leaving the false impression of no leakage. But the unsampled sidelobes are frequencies of potential other signals that will be distorted by the sinusoid and (conversely) frequencies of other signals that can leak into and distort the desired one.