Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function [ P1, f ] = ssfft( X, Fs )
%ssfft Computes the single-sided amplitude spectrum of a signal.
% https://www.mathworks.com/help/matlab/ref/fft.html
% [ P1, f ] = ssfft( X, Fs )
%
% X Input signal.
% Fs Sampling frequency.
% P1 Single-sided Amplitude Spectrum.
% f Frequency range.
%
% Plot with e.g. stem(f, P1), plot(f, P1).
L = length(X);
Y = fft(X);
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment