MATLAB: Single sided amplitude fourier spectrum

fourier spectrumsingle-sided amplitude

Hello all, I am new user that trying to learn coding. I have an acceleration-time history with a time-step of 0.01 sec. The total duration is 14 sec. I would like to get a single-sided fourier spectrum of it. Is there any packed code for it? Any kind of help is appreciated. The attached file contains the data. Thank you.
Muhsin

Best Answer

See the documentation for fft (link).
The Code
D = dlmread('Muhsin A00.txt', '\t', 1,0);
t = D(:,1); % Time (s)
a = D(:,2); % Acceleration (g)
L = length(t);
Ts = t(2)-t(1); % Sampling Interval (sec)
Fs = 1/Ts; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
FTa = fft(a)/L; % Fourier Transform (Scaled)
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:length(Fv); % Index Vector
figure(1)
plot(Fv, abs(FTa(Iv))*2) % One-Sided Amplitude Plot
xlabel('Frequency (Hz)')
ylabel('Amplitude (g)')
grid
EDIT Changed ‘Ts’ calculation to accommodate ‘t(1)=0.01’ and ‘t(end)=0’.