Monday, June 11, 2012

Power Spectral Density matlab code

Power Spectral Density matlab code

To verify Power Spectral Density


Operating System         – Windows XP
Constructor                  Simulator
Software                      - CCStudio 3 & MATLAB 7.5


The power spectral density(P.S.D) is a measurement of the energy at various frequencies.


%Power spectral density
t = 0:0.001:0.6;
x = sin(2*pi*50*t)+sin(2*pi*120*t);
y = x + 2*randn(size(t));
title('Signal Corrupted with Zero-Mean Random Noise')
xlabel('time (milliseconds)');
Y = fft(y,512);
%The power spectral density, a measurement of the energy at various frequencies, is:
Pyy = Y.* conj(Y) / 512;
f = 1000*(0:256)/512;
title('Frequency content of y');
xlabel('frequency (Hz)');


You might also like:


  1. If I have an image with size 512 x 512. How can I calculate the power spectral of the image?

  2. Hi

    I´m trying to get the SNR of a signa, but first i want to plot the PSD of the signal. Now i´m worry about the amplitud of the spectrum, because in your example the spectrum don´t show the correct amplitud of the signals, so my first question is, how can i fix it? and later, how can i get the SNR.

    I´m thinking to sum all the components of the PSD vector and then substract the amplitud of the frecuency that belong to the input signal, that would be the noise power, and then i'm going to apply de formula:

    SNR=10 log (Signapower/noisepower)

    Is this right??