"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:N1)*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:N1)*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
