%% Percentage of Power in Frequency Band (Periodogram)
% Determine the percentage of the total power in a specified frequency interval using the periodogram as the input.
% 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 corresponding frequency vector. Using the PSD estimate, determine the percentage of the total power in the frequency interval between 50 Hz and 150 Hz.

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

[Pxx,F] = periodogram(x,rectwin(length(x)),length(x),Fs);
pBand = bandpower(Pxx,F,[50 150],'psd');
pTot = bandpower(Pxx,F,'psd');
per_power = 100*(pBand/pTot)

% Copyright 2015 The MathWorks, Inc.