FFT plot how to plot frequency

조회 수: 2 (최근 30일)
andrei andrei1
andrei andrei1 2018년 6월 12일
댓글: Star Strider 2018년 6월 13일
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
Star Strider
Star Strider 2018년 6월 12일
See the documentation on fft (link).
You have to create a frequency vector for the plot.
andrei andrei1
andrei andrei1 2018년 6월 12일
편집: andrei andrei1 2018년 6월 12일
can you tell me how? it should be function of T, obviously, and should have same length as D. frequency normally is 1/T .. but how to apply that here? maybe.. if T=1:500000 totally meaning 2 minutes, then freq=1:1/500000:1/120*500000) ?

댓글을 달려면 로그인하십시오.

답변 (1개)

Star Strider
Star Strider 2018년 6월 12일
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
andrei andrei1
andrei andrei1 2018년 6월 13일
편집: andrei andrei1 2018년 6월 13일
ok, so, for example if T has 500000 values between 0 and 10 seconds, this Fv will have 250001 values cause of the Nyquist mirroring, but the values would be from what frequency to what frequency? how to show on x axis the real values of frequency, and not the full 250001 steps, and how to show frequencys till 50 Hz, plot(Fv(1:50), D(1:50)) is good?
in my method, the x axis was till 250000 bins, and on yours till 25000 bins. these values are in fact 250000 Hz?
Star Strider
Star Strider 2018년 6월 13일
The ‘Fv’ variable goes from 0 Hz to the Nyquist frequency, that being half the sampling frequency.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

태그

제품


릴리스

R2013b

Community Treasure Hunt

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

Start Hunting!

Translated by