MATLAB Answers

How come the frequency vector starts at 0 for even length FFT ?

조회 수: 81(최근 30일)
In many examples including the documentation about fft, the one-sided frequency vector is defined as: f = Fs*(0:(L/2))/L where L=length of the FFT. However it seems to me that for even-length FFT, the DC component is missing and so on. So you would plot at 0 the component computed for (+delta f /2 ) which is fairly ok because it is averaged of the 2 points around 0, but also the component plotted at frequency (+delta f) is the one computed for (+3.delta f/2), which is false. How do you explain that ?
And what would be the definition of a two-sided frequency vector for both even and odd lengths ? None of the answers provided on the forum are satisfying... Thank you for your help.

  댓글 수: 0

댓글을 달려면 로그인하십시오.

채택된 답변

Rick Rosson
Rick Rosson 2 Apr 2016
편집: Rick Rosson 2 Apr 2016
Regardless of whether L is even or odd, the first element of the vector returned by fft is always the DC component. No matter what.
So, using the full frequency span, the frequency vector is computed as
L = length(X);
dF = Fs/L;
f = dF*(0:L-1)';
This code is correct for any length L, whether even or odd.
For the one-sided span, the code becomes:
f = dF*(0:floor(L/2)-1)';
For the two-sided span centered on DC, the code becomes:
f = (-Fs/2:dF:Fs/2-dF)' + mod(L,2)*dF/2;
Again, this code is correct for both even and odd L.

  댓글 수: 2

Galdir Reges
Galdir Reges 27 Dec 2019
I think this solution is discarding the highest frequency on odd sized vector.
maybe the solution is using ceil and not floor
Fernando Zigunov
Fernando Zigunov 13 Aug 2020
I think his answer is correct, but perhaps this is a better way of interpreting.
The actual spectrum is always one-sided:
f = dF*(0:(L-1))';
But since it exceeds the Nyquist frequency (dF*L/2), the frequencies higher than (dF*L/2) will alias and become negative. In general:
f(f>(dF*L/2))=f(f>(dF*L/2))-(dF*L);
We're subtracting dF*L from all over-Nyquist frequencies, making them negative. This helps when doing some PDE solving operations, where the negative frequencies need to be used with their original sign.
Please correct me if I'm mistaken!

댓글을 달려면 로그인하십시오.

추가 답변(0개)

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by