1
$\begingroup$

Disclaimer: I’m computer scientist, no math expert

I’m computing a frequency spectrum by applying an FFT on 10000 real numbers acquired at 10kHz. The FFT produce 10000 complex numbers. The frequency spectrum is obtained by computing the magnitude of the complex numbers and yields a symmetric array. I’m programming in Go if it matters.

I was expecting that the magnitude of 0Hz would be stored at index 5000, and 1kHz at index 6000 and 4000. But magnitude of 0Hz is stored at index 0, and 1kHz at index 1000 and 9000.

Is this normal, or is this a feature of the library I use ?

$\endgroup$
8
  • 1
    $\begingroup$ I'm not an expert on FFT implementations. However, usually FFT algorithms output the frequency bins in the following order [0, fs/N, 2*fs/N,...fs/2, -fs/N, -2*fs/N,... -fs/2]. In Matlab we usually use the fftShift function to shift the fft so that the most negative frequency is in the leftmost position. $\endgroup$
    – Ben
    Jan 29, 2021 at 14:26
  • $\begingroup$ @Ben it is thus a property of the algorithm. Thank you. When I compute the magnitude with sqrt(re*re+im*im), do I have to also divide the result by N or N/2 ? $\endgroup$
    – chmike
    Jan 29, 2021 at 14:29
  • 1
    $\begingroup$ You divide it by N/2. $\endgroup$
    – Ben
    Jan 29, 2021 at 14:32
  • $\begingroup$ @Ben that depends on the normalization that the individual implementation does and can't be generally answered. But, N/2 sounds wrong in any case. $\endgroup$ Jan 29, 2021 at 16:40
  • $\begingroup$ @chmike. FFT algorithms typically output the frequency bins in the following order [0, fs/N, 2*fs/N, 3*fs/N, ..., (N/2-1)*fs/N, (N/2)*fs/N, -(N/2-1)*fs/N, ..., -3*fs/N, -2*fs/N, -fs/N] $\endgroup$ Jan 29, 2021 at 17:50

1 Answer 1

5
$\begingroup$

Is this normal ?

Yes.

It follows the mathematical definition of the DFT.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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