What are the frequencies when N in fft(x,N) is odd?

I know when N is even, fft(x,N) corresponds to frequencies 0,df,...,N/2*df,-(N/2-2)*df,...,-df.
What about if N is odd?

 採用された回答

Honglei Chen
Honglei Chen 2014 年 7 月 10 日
編集済み: Honglei Chen 2014 年 7 月 10 日

4 投票

In general, you can do it as
f = (0:N-1)*fs/N
If you want to map it to negative frequencies
if N is even
f(N/2+1:end) = f(N/2+1:end)-fs % sample -fs/2
or
f(N/2+2:end) = f(N/2+2:end)-fs % sample fs/2
if N is odd
f((N+1)/2+1:end) = f((N+1)/2+1:end)-fs
HTH

5 件のコメント

Ray Lee
Ray Lee 2014 年 7 月 10 日
why there are different two for even N?
Honglei Chen
Honglei Chen 2014 年 7 月 10 日
編集済み: Honglei Chen 2014 年 7 月 10 日
-fs/2 and fs/2 are the same point due to periodicity. The difference is really just which one you want to display in your axis
Ray Lee
Ray Lee 2014 年 7 月 10 日
the output of fft is unique, but in the two formulae, the f axis is shifted by one point.
Honglei Chen
Honglei Chen 2014 年 7 月 10 日
編集済み: Honglei Chen 2014 年 7 月 10 日
That's not true. Only one point is changed, from fs/2 to -fs/2 and because the result is periodic, they are indeed the same so you can mark it either way
Eric
Eric 2024 年 6 月 4 日
To be clear, if you are using fftshift on your FFT data and N is even, use the first option (repeated here):
f(N/2+1:end) = f(N/2+1:end)-fs % sample -fs/2

サインインしてコメントする。

その他の回答 (1 件)

Michael scheinfeild
Michael scheinfeild 2014 年 7 月 10 日

0 投票

if x is ampled at fs you can generate frequency vector use
freqvec=linspace(0,fs,N);

3 件のコメント

Ray Lee
Ray Lee 2014 年 7 月 10 日
I don't think so. The negative frequencies are missing.
Honglei Chen
Honglei Chen 2014 年 7 月 10 日
This is incorrect. linspace always sample the last one, which you don't want.
CHAN  CHEN HUA
CHAN CHEN HUA 2021 年 10 月 7 日
@Honglei Chen Hi, can i know why last sample should not be taken into?

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2014 年 7 月 10 日

コメント済み:

2024 年 6 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by