How do I obtain the frequencies of each value in an FFT?

c#, fft, signal-processing

Solution

The first bin in the FFT is DC (0 Hz), the second bin is `Fs / N`, where `Fs` is the sample rate and `N` is the size of the FFT. The next bin is `2 * Fs / N`. To express this in general terms, the nth bin is `n * Fs / N`.

So if your sample rate, `Fs` is say 44.1 kHz and your FFT size, `N` is 1024, then the FFT output bins are at:

  0:   0 * 44100 / 1024 =     0.0 Hz
  1:   1 * 44100 / 1024 =    43.1 Hz
  2:   2 * 44100 / 1024 =    86.1 Hz
  3:   3 * 44100 / 1024 =   129.2 Hz
  4: ...
  5: ...
     ...
511: 511 * 44100 / 1024 = 22006.9 Hz

Note that for a real input signal (imaginary parts all zero) the second half of the FFT (bins from `N / 2 + 1` to `N - 1`) contain no useful additional information (they have complex conjugate symmetry with the first `N / 2 - 1` bins). The last useful bin (for practical aplications) is at `N / 2 - 1`, which corresponds to 22006.9 Hz in the above example. The bin at `N / 2` represents energy at the Nyquist frequency, i.e. `Fs / 2` ( = 22050 Hz in this example), but this is in general not of any practical use, since anti-aliasing filters will typically attenuate any signals at and above `Fs / 2`.

Problem

I have an FFT result. These are stored in two `double` arrays: a real part array and an imaginary part array. How do I determine the frequencies that correspond to each element in these arrays? In other words, I would like have create an array that stores the frequencies for each real and imaginary component of my FFT.

Original source

Related problems