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?

采纳的回答

Geoff Hayes
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
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
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
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
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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matched Filter and Ambiguity Function 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by