If a fft of vector x is plotted then what would be the x-axis?
91 ビュー (過去 30 日間)
古いコメントを表示
x=rand(1:1000)>0.5;
X=fft(x);
X_mag=abs(X);
plot(x_mag)
There would appear 1000 values in x-axis , is it frequency or what?
0 件のコメント
採用された回答
Geoff Hayes
2014 年 9 月 24 日
編集済み: Geoff Hayes
2014 年 9 月 24 日
The x-axis is frequency. You can calculate it as
freqHz = (0:1:length(X_mag)-1)*Fs/N;
where Fs is your sampling rate (Hz) and N is your FFT block size (in your case N=length(x)).
You can then plot the magnitude vs frequency as
plot(freqHz,X_mag);
5 件のコメント
Allen Goldstein
2019 年 10 月 16 日
編集済み: Allen Goldstein
2019 年 10 月 16 日
This "accepted answer" is not correct. The fft creates positive and negative frequencies and is invertable to the original signal. The frequency at either end of the fft vector is 0 and the center is length (X_mag)*Fs/N. The matlab help on fft gives a good example of how to display the spectrum by creating the "analytic" FFT (though the help does not call it analytic). The thing about the analytic FFT is that the inverse FFT creates the analytic signal which is complex with the imaginary part being phase shifted by 90 degrees (the imaginary part of the iFFT is the Hilbert transformation of the original signal). The original signal is the real part of the analytic signal.
I will try to provide a better answer...
Florian Behner
2021 年 1 月 27 日
編集済み: Florian Behner
2021 年 1 月 27 日
Geoff Hayes answer is indeed correct, although usually not what you expect. The result of the FFT is periodic in frequency, as it is also assumed for the time domain signal. Thus the frequency result is ambiguous with the sampling frequency. Any frequency bin may be shifted by integer multiples of the sample rate.
We are usually using the follwing code to determine the frequency of the bins:
frequency=[0:ceil(nbrSamples/2)-1,-floor(nbrSamples/2):-1]'/sampleInterval/nbrSamples;
%To plot the frequency vector and the FFT output in order use
plot(fftshift(frequency),fftshift(fftresult))
その他の回答 (1 件)
Allen Goldstein
2019 年 10 月 16 日
To plot the entire original fft use:
N = length(X_mag)
f = horzcat(-linspace(0,N/2,N/2)*Fs/N,linspace(N/2,0,N/2)*Fs/N);
To create the frequency spectrum and stem (f,X_Mag), This does a little weirdness behind the scenes because it splits the fft vector in half then plots the two ends of the vector in the middle. If you just plot(X_Mag) you will see what I mean..
One more thing, it is better to use stem() to plot ffts because the bins of the fft are independant (orthogonal) and plot interpolates a connection between the elements which can be misleading.
1 件のコメント
Darcy Cordell
2023 年 6 月 13 日
Thanks for the answer (and I agree that the other answer is incomplete). Just to clarify here though: does this mean that the MATLAB fft produces two identical f=0 frequency bins? In your frequency axis, you have a duplicate f=0 at f(1) and f(end).
Also, does this work for both even and odd-length functions?
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!