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

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`.

Take a look at my answer here.

The FFT actually calculates the cross-correlation of the input signal with sine and cosine functions (basis functions) at a range of equally spaced frequencies. For a given FFT output, there is a corresponding frequency (F) as given by the answer I posted. The real part of the output sample is the cross-correlation of the input signal with `cos(2*pi*F*t)` and the imaginary part is the cross-correlation of the input signal with `sin(2*pi*F*t)`. The reason the input signal is correlated with `sin` and `cos` functions is to account for phase differences between the input signal and basis functions.

By taking the magnitude of the complex FFT output, you get a measure of how well the input signal correlates with sinusoids at a set of frequencies regardless of the input signal phase. If you are just analyzing frequency content of a signal, you will almost always take the magnitude or magnitude squared of the complex output of the FFT.

I have used the following:

```public static double Index2Freq(int i, double samples, int nFFT) {
return (double) i * (samples / nFFT / 2.);
}

public static int Freq2Index(double freq, double samples, int nFFT) {
return (int) (freq / (samples / nFFT / 2.0));
}
```

The inputs are:

• `i`: Bin to access
• `samples`: Sampling rate in Hertz (i.e. 8000 Hz, 44100Hz, etc.)
• `nFFT`: Size of the FFT vector

The FFT output coefficients (for complex input of size N) are from 0 to N - 1 grouped as [LOW,MID,HI,HI,MID,LOW] frequency.

I would consider that the element at k has the same frequency as the element at N-k since for real data, FFT[N-k] = complex conjugate of FFT[k].

The order of scanning from LOW to HIGH frequency is

```0,

1,
N-1,

2,
N-2

...

[N/2] - 1,
N - ([N/2] - 1) = [N/2]+1,

[N/2]
```

There are [N/2]+1 groups of frequency from index i = 0 to [N/2], each having the `frequency = i * SamplingFrequency / N`

So the frequency at bin FFT[k] is:

```if k <= [N/2] then k * SamplingFrequency / N
if k >= [N/2] then (N-k) * SamplingFrequency / N
```

Your kth FFT result's frequency is 2*pi*k/N.

1. #### Patel

• 2018/9/5

in FFT. Where Fs is sample frequency, N is number of data points used in the FFT. For example, if the sample frequency is 1000 Hz and the number of data points used by you in FFT is 1000. Then the frequency resolution is equal to 1000 Hz/1000 = 1 Hz.

2. #### Pellegrino

• 2018/10/6

There are [N/2]+1 groups of frequency from index i = 0 to [N/2], each having the frequency = i * SamplingFrequency / N. So the frequency at bin FFT [k] is: if k <= [N/2] then k * SamplingFrequency / N if k >= [N/2] then (N-k) * SamplingFrequency / N. Share. Improve this answer.

3. #### Chance

• 2019/8/2

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.

4. #### Roy

• 2019/1/7

Edited: Wayne King on 7 Nov 2013. dpb is correct, you can use that to create a meaningful frequency vector. For an even length signal, the most common interval is (-Fs/2, Fs/2] Fs = 1000; t = 0:1/Fs:1-0.001; x = cos (2*pi*100*t)+randn (size (t)); xdft = fftshift (fft (x)); df = Fs/length (x); freq = -Fs/2:df:Fs/2-df;

5. #### Alvin

• 2019/12/12

For each slice, calculate the DFT, which returns both positive and negative frequencies (more on that in “Frequencies and Their Ordering”), so we slice out

6. #### Gage

• 2018/6/29

From this, I also understand how to obtain the frequencies in x- and y- direction. What I do not fully understand is what the direction-independent frequencies of my output values are. Intuitively, I would expect to calculate them like so: // from output to frequencies to periods fx = kx / N; fy = ky / M px = 1/fx; py = 1/fy // direction independent frequency of output value period = sqrt(px*px + py*py) frequency = 1/p

7. #### Jax

• 2016/6/11

How do I obtain the frequencies of each value in an FFT? I have an FFT result. These are stored in two double arrays: a real part array and an imaginary part

8. #### Quentin

• 2018/12/25

Thus, for the first plot, which used every 50th of points that were taken at a frequency of 2 GHz, the sample frequency would be 40 MHz. Thus, f = (0:n-1)*4*10^7/(25000/50) It goes on to show how to use the fftshift function to put the center of the output of the fft function at 0, but it's clear you already did that and chopped off the negative part.

9. #### Kelly

• 2019/3/29

We can obtain the magnitude of frequency from a set of complex numbers obtained after performing FFT i.e Fast Fourier Transform in Python. The

10. #### Greyson

• 2015/5/25

The FFT returns a two-sided spectrum in complex form (real and imaginary parts), which you must scale and convert to polar form to obtain magnitude and phase. The frequency axis is identical to that of the two-sided power spectrum. The amplitude of the FFT is related to the number of points in the time-domain signal. Use the following equation to

11. #### Raylan

• 2017/8/18

For example, you can effectively acquire time-domain signals, measure values are proportional to the amplitude squared of each frequency component

12. #### Silas

• 2016/11/29

df=fs/N; %frequency resolution sampleIndex = -N/2:N/2-1; %ordered index for FFT plot f=sampleIndex*df; %x-axis index converted to ordered frequencies stem(f,abs(X)); %magnitudes vs frequencies xlabel('f (Hz)'); ylabel('|X(k)|');

13. #### Cullen

• 2019/8/4

It's not over your Nyquist limit, because you're doing sampling at your nyquist rate in two independent dimensions and look at the combined

14. #### Lorenzo

• 2015/7/3

You can compute the accumulated energy as follows. samplerate = 48000 Nfft = 8192 freqs = librosa.fft_frequencies (sr=sr, n_fft=Nfft) plt.loglog (freqs, np.mean (mag**2, axis=1)/ (Nfft/2)**2) plt.xlabel ('freq [Hz]') If you want to sum the energy in a frequency range you can use index mag on freqs, e.g.

15. #### Emiliano

• 2021/1/19

Each bucket is 5000/256 Hz of spectrum width, so the zeroeth starts at DC, First, the FFT coefficients you get are not broken down into 256 sine and 256

16. #### Kameron

• 2019/2/22

np.fft.fftfreq tells you the frequencies associated with the coefficients: import numpy as np x = np.array([1, 2, 1, 0, 1, 2, 1, 0]) w = np.fft.fft(x) freqs

17. #### Duke

• 2016/2/6

Learn more about fft, frequency MATLAB. after the fft of the input signal,how to get the frequencies? Plot time data, separate for each PCA axes.