17
$\begingroup$

The cyan plot is a spectrum of 50 Hz, and the magenta one is a 50.1 Hz sine wave (having amplitude 0.7). Both are sampled at 1024 samples/s. I performed a 1024 point FFT to get this spectrum.

Why is only the 50Hz spectrum a single value? Why does the 50.1 Hz sine consist of other frequencies apart from 50.1 Hz; where do these new frequencies come from?

I did not do any non-linear processing on the 50.1 Hz signal! Also the 50.1 Hz appears to have smaller maximum amplitude, i.e. it's not 0.7, when in fact the sine wave I generated has an amplitude of 0.7.

Why is this?

Two spectra, for 50Hz and 50.1Hz respectively Obtained by MATALB command fft();

$\endgroup$
4
  • $\begingroup$ Could you please post the code you used to produce this plot? My best guess, is that because your signals are so close together the fft can't properly resolve them. That, or some spectral smearing because the samples don't line up with the frequencies. $\endgroup$
    – Tom Kealy
    Apr 11, 2013 at 9:03
  • 5
    $\begingroup$ The answers below are correct. The term for what you're observing is called spectral leakage, and is observed when you analyze a sinusoid whose frequency does not lie exactly at the center of one of your DFT output bins. $\endgroup$
    – Jason R
    Apr 11, 2013 at 13:53
  • $\begingroup$ please can I know what u plotted against what for you to be able to get your spike at the 50Hz mark $\endgroup$ Dec 22, 2013 at 11:36
  • $\begingroup$ See this answer for a detailed description of what the issue is and how to fix it. $\endgroup$ Dec 22, 2013 at 14:20

5 Answers 5

17
$\begingroup$

Acually Matt's answer already gives one view on the problem here: the DFT is implicitly periodic in both time and frequency domain (see this question). From your parameters we can calculate that your observation period is 1 s. That means you observe 50 periods of a 50 Hz tone. Periodically extending that observation interval will always result in a seemless sine wave. If you take the 50.1 Hz tone, you're transforming 50.1 periods of an oscillation. Periodically extending that signal will result in phase jumps that cause additional spectral tributaries.

Another view is the frequency resolution that is defined as $f_\mathrm{s}/N_ \mathrm{DFT} = 1024 \text{Hz}/1024 = 1 \text{Hz}$. As 50 Hz is an integer multiple of 1 Hz, this tone can be reresented by a single DFT bin. As the result of the DFT is discrete values that are space 1 Hz apart, a 50.1 Hz cannot be represented by a single bin and the energy is smeared over the frequency domain. In your example this is the reason for the slightly asymmetric magenta spectrum and for the lower magnitude of the 50 Hz bin compared to the 0.7 magnitude of the 50 Hz spectrum.

Both effects described above contribute to the spectrum you're observing.

$\endgroup$
2
  • 1
    $\begingroup$ That makes sense. But just to be more clear spectral leakage that you described is a problem with the tool (FFT) for observing spectra. Its not a defect perse in the signal. Means If I 'hear' an audio signal of 50.1 Hz , it will appear to my ears as a single tone, and not some kind of 'noise'. Am I right? $\endgroup$
    – gpuguy
    Apr 12, 2013 at 10:27
  • 1
    $\begingroup$ You're absolutely right. It shows how important it is to understand what the DFT is actually doing in order to be able to interpret it correctly. As a sidenote: what you would "hear" in an actual implementation also depends on how you're converting the discrete to an analog signal. $\endgroup$
    – Deve
    Apr 12, 2013 at 10:42
12
$\begingroup$

This is the effect of truncating or windowing the sine signal. You need to truncate in such a way that if you add the shifted signal to the truncated one, it will still be the original sine wave.

$\endgroup$
8
$\begingroup$

You will only get a single result FFT point for a frequency of pure unmodulated sinusoid that is exactly integer periodic in the FFT aperture or width. Any other frequency of sinusoid will appear as convolved with the transform (a periodic Sinc) of the default window (a rectangle).

50.1 Hz is not exactly periodic in your FFT's 1 second window.

Those other "leakage" FFT result bins or frequencies are needed to represent the discontinuity produced between the window boundaries by any signal that is not exactly integer periodic in the FFT width. This is because all the basis vectors of a DFT are exactly integer periodic within the DFT's width, and thus have no sharp discontinuity between the end and beginning of the basis vector. So any signal that doesn't have those characteristics can't be represented by just one DFT basis vector (and its complex conjugate), so the information about the rest of the signal has to go somewhere.

Since the total energy is preserved by the FFT transform (Parseval'a theorem), the energy in the "leakage" bins takes away from the peak bin. Thus the magnitude of the peak bin must be lower.

$\endgroup$
5
$\begingroup$

I bet your sine wave is zero at the first and last sample? It shouldn't be. It should be lined up so that the next sample after the last sample is zero, so that you can copy and paste copies of the signal one after another and they will look continuous, with no duplicated samples. Maybe think of it like tiled desktop wallpaper, where one edge has to seamlessly meet the opposite edge when tiled. :)

See https://gist.github.com/endolith/236567 for a python example:

# Sampling rate
fs = 128 # Hz

# Time is from 0 to 1 seconds, but leave off the endpoint, so that 1.0 seconds is the first sample of the *next* chunk
length = 1 # second
N = fs * length
t = linspace(0, length, num = N, endpoint = False)

# Generate a sinusoid at frequency f
f = 10 # Hz
a = cos(2 * pi * f * t)

# Use FFT to get the amplitude of the spectrum
ampl = 1/N * abs(fft(a))

See how two copies of the signal fit together end-to-end to make a continuous wave:

enter image description here

When this happens, the FFT energy is contained entirely in a single bin:

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ I had same problem as OP. It was solved thanks to setting endpoint = False flag. I thought linespace is (closed, open) by default but it turns out to be (closed, closed). I found the bug thanks to your code. $\endgroup$ Oct 30, 2018 at 17:16
-1
$\begingroup$

This occurs due to Spectral Leakage and Windowing. The ideal response i.e. impulse function is for continuous time sine wave. When you take DFT of a discrete sine wave in a digital computer, you are basically taking Fourier Transform of windowed and sampled sine and then sampling it in frequency domain. This causes the spectral leakage. Refer: http://w.astro.berkeley.edu/~jrg/ngst/fft/leakage.html

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.