I'm currently trying to learn how to calculate DFT using FFT with Python. However, I have been struggling to find how should I choose the frequency grid when plotting the final calculated DFT values out of the data samples that I have. Any helpful insights will be appreciated!

  • 1
    $\begingroup$ you can't choose. The frequencies of the individual DFT coeffients are defined by your sampling rate and DFT length. Look at the DFT formula! $\endgroup$ Jun 8 '17 at 14:22
  • $\begingroup$ This will tell you what the frequencies are: scipy version, numpy version $\endgroup$
    – endolith
    Jun 8 '17 at 15:45

It really depends on your application and what you want to see and the actual FFT call you make. Typically if your time series is real valued, the DFT will be conjugate symmetric with respect to negative and positive frequencies and the magnitude information is redundant. Let assume your data consists of N samples and N is even and you used a complex DFT, also assume you use C style indexes, i.e. X[0] is the first element in your array. X[0] is going to correspond to the "DC" bin or a frequency of zero. X[N/2]will correspond to the Nyquist sample frequency. Most People with ignore X[N/2+ 1] to X[N-1] (or often X[N/2] to X[N]) The thing to remember is that each bin has a conjugate valued twin. X[0] and X[N/2] are pairs of a sort but don't follow this rule. X[1] is paired with X[N], X[2] with X[N-1] , X[3] with X[N-2], and so forth. One is the positive frequency and the other the corresponding negative frequency.

If you recall your sampling theory, the Discrete Frequency Spectra is periodic, so you can think of the values X[N/2] to X[N] as either the negative frequencies of the spectrum of the cycle centered at DC or the negative frequencies of the cycle centered at the twice the sample (+) frequency. I typically will reorder the upper frequencies so that they are displayed below so the DC bin is the center point of my plot and Matlab has a function called FFTSHIFT that does that, and it also works if N is odd.

If your time series is complex, there are different possibilities. If x is a Hilbert transpose, the negative frequencies are zero, so unless you want to verify that, it doesn't make much sense to display zeros.

If x is a signal such as an I and Q pair out of a demodulator, using a FFTSHIFT ordering is generally preferable because the frequency shifted carrier will be in the center.

The fact that the upper half of the output are actually the negative frequencies was something that confused me many moons ago.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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