If a fft of vector x is plotted then what would be the x-axis?
조회 수: 87 (최근 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?
참고 항목
카테고리
Help Center 및 File Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!