If a fft of vector x is plotted then what would be the x-axis?

조회 수: 295(최근 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
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.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by