%% Power Spectrum of a Noisy Sinusoid
% Generate 1024 samples of a noisy sinusoid having a normalized frequency of  2\pi/3 rad/sample. Estimate the power spectrum of the signal using pwelch. Express the estimate in decibels and plot it.

n = 0:1024-1;
x = cos(2*pi*n/3) + randn(size(n));

[pxx,w] = pwelch(x,'power');

dB = pow2db(pxx);

plot(w/pi,dB)
xlabel('\omega / \pi')
ylabel('Power (dB)')

%
% Repeat the computation using pwelch without output arguments.

pwelch(x,'power')

% Copyright 2015 The MathWorks, Inc.