Created
August 7, 2018 03:31
-
-
Save MartinBloedorn/ac91a2dd894070daf6ed21c588534791 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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