FFT plot how to plot frequency
Ältere Kommentare anzeigen
hy, i have a set of data, time - velocity. i need to transform it in frequency-amplitude plot. so, i have this code:
load('x.txt');
X=x(:,2);
T=x(:,1);
Xf=fft(X);
l=length(Xf);
D=2*abs(Xf)/l; %%i understand this is the formula to plot exact amplitude
plot(D)
grid on
so.. i have the amplitude on Y axis, but on X axis it shows the time, it is like 2 minutes long in 500000 steps, so, many numbers, and i need to know the amplitudes for the first 50Hz. how can i have Hz= frequency on X axys, cause i don't think is the same at may time 500k+ values. p=plot(T,X)
2 Kommentare
Star Strider
am 12 Jun. 2018
You have to create a frequency vector for the plot.
andrei andrei1
am 12 Jun. 2018
Bearbeitet: andrei andrei1
am 12 Jun. 2018
Antworten (1)
Star Strider
am 12 Jun. 2018
I would create the frequency vector ‘Fv’ as:
Ts = mean(diff(T)); % Sampling Interval
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
Fv = linspace(0, 1, fix(l/2)+1)*Fn; % Frequency Vector (For One-Sided Fourier Transform)
Iv = 1:numel(Fv); % Index Vector (For One-Sided Fourier Transform)
Your plot call then changes to:
plot(Fv, D(Iv))
grid on
That should work (providing I did not make any typographical errors).
2 Kommentare
andrei andrei1
am 13 Jun. 2018
Bearbeitet: andrei andrei1
am 13 Jun. 2018
Star Strider
am 13 Jun. 2018
The ‘Fv’ variable goes from 0 Hz to the Nyquist frequency, that being half the sampling frequency.
Kategorien
Mehr zu Spectral Measurements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!