Skip to content

Instantly share code, notes, and snippets.

@MartinBloedorn
Created August 7, 2018 03:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MartinBloedorn/ac91a2dd894070daf6ed21c588534791 to your computer and use it in GitHub Desktop.
Save MartinBloedorn/ac91a2dd894070daf6ed21c588534791 to your computer and use it in GitHub Desktop.
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