Created
December 15, 2022 20:09
-
-
Save jlblancoc/fbe1b1f1b81abc981f2eb28bcca93f17 to your computer and use it in GitHub Desktop.
MATLAB function to draw the power spectral density of a time series
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 [] = dibuja_dep(x, Fs) | |
% Dibuja la densidad espectral de potencia (dep) | |
% o power spectral density (psd) de una señal "x" muestreada a una | |
% frecuencia de muestreo "Fs" (Hz) | |
N = length(x); | |
X = fft(x); | |
X = X(1:N/2+1); | |
psdx = (1/(Fs*N)) * abs(X).^2; | |
psdx(2:end-1) = 2*psdx(2:end-1); | |
freq = 0:Fs/length(x):Fs/2; | |
plot(freq,10*log10(psdx)); | |
grid on; | |
xlabel('Frecuencia (Hz)'); | |
ylabel('PSD Potencia/frecuencia (dB/Hz)'); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment