Skip to content

Instantly share code, notes, and snippets.

@jlblancoc
Created December 15, 2022 20:09
Show Gist options
  • Save jlblancoc/fbe1b1f1b81abc981f2eb28bcca93f17 to your computer and use it in GitHub Desktop.
Save jlblancoc/fbe1b1f1b81abc981f2eb28bcca93f17 to your computer and use it in GitHub Desktop.
MATLAB function to draw the power spectral density of a time series
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