%% Resolve Signal Components
% Estimate the one-sided power spectral density of a noisy sinusoidal signal with two frequency components.

Fs = 32e3;   
t = 0:1/Fs:2.96;
x = cos(2*pi*t*1.24e3)+ cos(2*pi*t*10e3)+ randn(size(t));
nfft = 2^nextpow2(length(x));
Pxx = abs(fft(x,nfft)).^2/length(x)/Fs;

%
% Store the spectrum in a PSD data object and plot the result.

Hpsd = dspdata.psd(Pxx(1:length(Pxx)/2),'Fs',Fs);  
plot(Hpsd)

%
% Create a two-sided spectrum and plot it.

Hpsd = dspdata.psd(Pxx,'Fs',Fs,'SpectrumType','twosided');
plot(Hpsd)

% Copyright 2012 The MathWorks, Inc.