Fft code; differences between scripts.

1 回表示 (過去 30 日間)
Guglielmo Giambartolomei
Guglielmo Giambartolomei 2016 年 10 月 11 日
Goodmorning everyone, I want to perform a fft of an accelerometric signal and I'd like to know what's the best way to do that. What script is more correct?
Code 1:
%%Time domain analysis of channel 2
x2=x0(:,3);
N2=length(x2);
Fs=2400;
T=1/Fs;
t2=linspace(0,N2*T,N2);
figure
plot(t2,x2)
grid on
title('Acc. on the sparger (ch. 2)')
xlabel('t (s)')
ylabel('x2(t), Acceleration (g)')
%%Frequency domain analys of channel 2
xdft2=fft(x2-mean(x2))/N2;
xdft2=xdft2(1:floor(N2/2)+1);
freq2=0:Fs/length(x2):Fs/2;
figure;
plot(freq2,abs(xdft2))
grid on
title('Single-Sided Amplitude Spectrum of x2(t)')
xlabel('f (Hz)')
ylabel('X2(f)')
Code 2:
x2=x0(:,3);
Fs = 2400; % Sampling frequency
T = 1/Fs; % Sample time
N2=length(x2); % Length of signal
t=(0:N2-1)*T; % Time vector
% Time domain analysis
plot(t,x2)
NFFT = 2^nextpow2(N2); % Next power of 2 from length of y
Y = fft(x2,NFFT)/N2;
f = Fs/2*linspace(0,1,NFFT/2+1);
% Plot single-sided amplitude spectrum.
figure
plot(f,2*abs(Y(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
The code 2 is recommended in the matlab help. Thank you very much!

回答 (0 件)

カテゴリ

Help Center および File ExchangeFourier Analysis and Filtering についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by