bandpower() - Signal Processing
examplep = bandpower(x) returns
the average power in the input signal, x. If x is
a matrix, then bandpower computes the average power
in each column independently.
examplep = bandpower(x,fs,freqrange) returns
the average power in the frequency range, freqrange,
specified as a two-element vector. You must input the sampling frequency, fs,
to return the power in a specified frequency range. bandpower uses
a modified periodogram to determine the average power in freqrange.
examplep = bandpower(pxx,f,'psd') returns
the average power computed by integrating the power spectral density
(PSD) estimate, pxx. The integral is approximated
by the rectangle method. The input, f, is a vector
of frequencies corresponding to the PSD estimates in pxx.
The string 'psd' indicates the input is a PSD estimate
and not time series data.
examplep = bandpower(pxx,f,freqrange,'psd') returns
the average power contained in the frequency interval, freqrange.
If the frequencies in freqrange do not match
values in f, the closest values are used. The
average power is computed by integrating the power spectral density
(PSD) estimate, pxx. The integral is approximated
by the rectangle method. The string 'psd' indicates
the input is a PSD estimate and not time series data.
Syntax
p = bandpower(x) examplep = bandpower(x,fs,freqrange) examplep = bandpower(pxx,f,'psd') examplep = bandpower(pxx,f,freqrange,'psd') example
Example
Comparison with Euclidean NormOpen This ExampleCreate a signal consisting of a 100 Hz sine wave in additive N(0,1) white Gaussian noise. The sampling frequency is 1 kHz. Determine the average power and compare it against the
norm.t = 0:0.001:1-0.001;
x = cos(2*pi*100*t)+randn(size(t));
p = bandpower(x)
l2norm = norm(x,2)^2/numel(x)
p =
1.5264
l2norm =
1.5264
Percentage of Total Power in Frequency IntervalOpen This Example
Determine the percentage of the total power in a specified frequency interval.
Create a signal consisting of a 100 Hz sine wave in additive N(0,1) white Gaussian noise. The sampling frequency is 1 kHz. Determine the percentage of the total power in the frequency interval between 50 Hz and 150 Hz. Reset the random number generator for reproducible results.rng('default')
t = 0:0.001:1-0.001;
x = cos(2*pi*100*t)+randn(size(t));
pband = bandpower(x,1000,[50 150]);
ptot = bandpower(x,1000,[0 500]);
per_power = 100*(pband/ptot)
per_power =
51.9591
Periodogram InputOpen This Example
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)
p =
1.5264
avpow =
1.5264
Percentage of Power in Frequency Band (Periodogram)Open This Example
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 100],'psd');
ptot = bandpower(Pxx,F,'psd');
per_power = 100*(pband/ptot)
per_power =
42.0767
Average Power of a Multichannel SignalOpen This Example
Create a multichannel signal consisting of three sinusoids in additive N(0,1) white Gaussian noise. The sinusoids' frequencies are 100 Hz, 200 Hz, and 300 Hz. The sampling frequency is 1 kHz, and the signal has a duration of 1 s.
Fs = 1000;
t = 0:1/Fs:1-1/Fs;
f = [100;200;300];
x = cos(2*pi*f*t)'+randn(length(t),3);
Determine the average power of the signal and compare it to the
norm.p = bandpower(x)
l2norm = dot(x,x)/length(x)
p =
1.5264 1.5382 1.4717
l2norm =
1.5264 1.5382 1.4717
Output / Return Value
Limitations
Alternatives / See Also
Reference