Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
PSD (Power Spectral Density)

Subject: PSD (Power Spectral Density)

From: Derrick Powell

Date: 2 Mar, 2012 18:49:35

Message: 1 of 3

Hi All,
  I am new to the field of DSP. Can you please tell me if this is how you compute and plot power spectral density (PSD):

N=1024; % Number of samples
fs=1000; % Sampling frequency
dt=1/fs; % Time step
f1=100;
f2=50;
t=(0:N-1)*dt;
x=sin(2*pi*f1*t)+sin(2*pi*f2*t);
figure
psd=(abs(fft(x)*dt).^2)/df; % square the absolute value of {fft(x)*dt} and then divide % by df
df=1/(N*dt); %frequency resolution
f=(0:N-1)*df;

plot(f(1:0.5*N+1),20*log10(psdx((1:0.5*N+1))))
grid

The other thing which bothers me is that when i square the fft(x), DC component and Nyquist also get squared, but that can't be correct, because they both are unique when N is even.

Thanks,
Derrick

Subject: PSD (Power Spectral Density)

From: Derrick Powell

Date: 2 Mar, 2012 18:59:12

Message: 2 of 3

"Derrick Powell" <dpowell2412@yahoo.com> wrote in message <jir4nv$r7$1@newscl01ah.mathworks.com>...
> Hi All,
> I am new to the field of DSP. Can you please tell me if this is how you compute and plot power spectral density (PSD):
>
> N=1024; % Number of samples
> fs=1000; % Sampling frequency
> dt=1/fs; % Time step
> f1=100;
> f2=50;
> t=(0:N-1)*dt;
> x=sin(2*pi*f1*t)+sin(2*pi*f2*t);
> figure
> psd=(abs(fft(x)*dt).^2)/df; % square the absolute value of {fft(x)*dt} and then divide % by df
> df=1/(N*dt); %frequency resolution
> f=(0:N-1)*df;
>
> plot(f(1:0.5*N+1),20*log10(psdx((1:0.5*N+1))))
> grid
>
> The other thing which bothers me is that when i square the fft(x), DC component and Nyquist also get squared, but that can't be correct, because they both are unique when N is even.
>
> Thanks,
> Derrick

Sorry it should be:
plot(f(1:0.5*N+1),20*log10(psd((1:0.5*N+1))))

- Derrick

Subject: PSD (Power Spectral Density)

From: Greg Heath

Date: 4 Mar, 2012 17:56:12

Message: 3 of 3

"Derrick Powell" <dpowell2412@yahoo.com> wrote in message <jir5a0$2vn$1@newscl01ah.mathworks.com>...
> "Derrick Powell" <dpowell2412@yahoo.com> wrote in message <jir4nv$r7$1@newscl01ah.mathworks.com>...
> > Hi All,
> > I am new to the field of DSP. Can you please tell me if this is how you compute and plot power spectral density (PSD):
> >
> > N=1024; % Number of samples
> > fs=1000; % Sampling frequency
> > dt=1/fs; % Time step
> > f1=100;
> > f2=50;
> > t=(0:N-1)*dt;
> > x=sin(2*pi*f1*t)+sin(2*pi*f2*t);
> > figure
> > psd=(abs(fft(x)*dt).^2)/df; % square the absolute value of {fft(x)*dt} and then divide % by df
> > df=1/(N*dt); %frequency resolution
> > f=(0:N-1)*df;
> >
> > plot(f(1:0.5*N+1),20*log10(psdx((1:0.5*N+1))))
> > grid
> >
> > The other thing which bothers me is that when i square the fft(x), DC component and Nyquist also get squared, but that can't be correct, because they both are unique when N is even.
> >
> > Thanks,
> > Derrick
>
> Sorry it should be:
> plot(f(1:0.5*N+1),20*log10(psd((1:0.5*N+1))))

When combining the power of positive and negative frequencies, do not double the DC and Nyquist components. Therefore use the single sided convention

psdss = [ psd(1), 2*psd(2:N/2), psd(N/2+1) ];

Hope this helps,

Greg

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us