%% PSD Estimate Using Hann Window
% Define a cosine of 200 Hz embedded in white noise.

Fs = 1000;
t = 0:1/Fs:0.3;
x = cos(2*pi*t*200)+randn(size(t));

%
% Compute Welch's power spectral density estimate of the signal using a Hann window.

window = 33;
noverlap = 32;
nfft = 4097;

h = spectrum.welch('Hann',window,100*noverlap/window);
hpsd = psd(h,x,'NFFT',nfft,'Fs',Fs);

%
% Visualize the power spectral density expressed in decibels.

Pw = hpsd.Data; 
Fw = hpsd.Frequencies;
plot(Fw,pow2db(Pw))
xlabel('Hz')
ylabel('dB')

% Copyright 2012 The MathWorks, Inc.