Effacer les filtres
Effacer les filtres

Fft code; differences between scripts.

2 vues (au cours des 30 derniers jours)
Guglielmo Giambartolomei
Guglielmo Giambartolomei le 11 Oct 2016
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!

Réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by