%% Periodogram Input
% Determine the average power by first computing a PSD estimate using the periodogram. Input the PSD estimate to bandpower.
% Create a signal consisting of a 100 Hz sine wave in additive N(0,1) white Gaussian noise. The sampling frequency is 1 kHz. Obtain the periodogram and use the 'psd' flag to compute the average power using the PSD estimate. Compare the result against the average power computed in the time domain.

t = 0:0.001:1-0.001;
Fs = 1000;
x = cos(2*pi*100*t)+randn(size(t));

[Pxx,F] = periodogram(x,rectwin(length(x)),length(x),Fs);
p = bandpower(Pxx,F,'psd')
avpow = norm(x,2)^2/numel(x)

% Copyright 2015 The MathWorks, Inc.