I've just stepped into the FFT's world since the last weeks, therefore I still don't have an clear overall idea of how to setup the frequency array.
In case of even
number N
, I usually do (with respect to the Nyquist cut-off frequency)
$f=\left(-N/2\,:\, N/2-1\right)*f_{s}$
but how does it work in case of odd
number N
. Is it just
$f=\left(-(N+1)/2\,:\,(N+1)/2-1\right)*f_{s}$
I thank you all in advance.
Answer
Short answer: yes, I think so.
Long answer: The FFT is just a fast implementation of the DFT. The frequency spacing of an N-point DFT operation is $\frac{f_s}{N}$. Samples of the DFT where $\omega \ge \pi$ correspond to the negative frequencies. If N is odd, then $\frac{N-1}{2} \cdot \frac{2\pi}{N}$ is less than $\pi$ and the next DFT frequency, $\frac{N+1}{2} \cdot \frac{2\pi}{N}$, is above $\pi$.
I think your answer is correct, and another way to think about it is that you have a DC bin, with (N-1)/2 negative frequencies, and (N-1)/2 positive frequencies.
update: MATLAB/Octave syntax for odd-N DFT frequencies:
freqs = (fs/N)*( (N-1)/2 : (N-1)/2 )
Python/Numpy/Scipy syntax for odd-N DFT frequencies:
freqs = (fs/N) * arange(-(N-1)/2,(N+1)/2)
Python/Numpy/Scipy syntax for even and odd N DFT frequencies ( via @endolith ):
fftshift(fftfreq(N,1./fs))
No comments:
Post a Comment