Contenuto principale

bandpower

Description

p = 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.

example

p = bandpower(x,Fs,freqRange) returns the average power in the frequency range freqRange. You must input the sample rate Fs to return the power in a specified frequency range. bandpower uses a modified periodogram to determine the average power in freqRange.

example

p = 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 "psd" option indicates that the input is a PSD estimate and not time series data.

example

p = 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 "psd" option indicates the input is a PSD estimate and not time series data.

example

Examples

collapse all

Create a signal consisting of a 100 Hz sine wave in additive N(0,1) white Gaussian noise. The sample rate is 1 kHz. Determine the average power and compare it against the 2 norm.

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

p = bandpower(x)
p = 
1.5264
l2norm = norm(x,2)^2/numel(x)
l2norm = 
1.5264

Determine the percentage of total power in specified frequency intervals.

Create a signal consisting of a 100 Hz sine wave and a chirp signal with frequency content between 220 Hz and 270 Hz, all in additive N(0,1) white Gaussian noise. The sample rate is 1 kHz. Reset the random number generator for reproducible results.

rng("default")

t = 0:0.001:1-0.001;
x = cos(2*pi*100*t) + t.*chirp(t,220,t(end),270) + 0.2*randn(size(t));

Determine the percentage of total power in the frequency intervals between 50 Hz and 150 Hz and between 200 Hz and 300 Hz.

powBands = bandpower(x,1000,[50 150;200 300]);
powTotal = bandpower(x,1000,[0 500]);
powPercent = 100*(powBands/powTotal)
powPercent = 2×1

   76.0390
   20.6880

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 sample rate 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")
p = 
1.5264
avpow = norm(x,2)^2/numel(x)
avpow = 
1.5264

Determine the percentage of total power in specified frequency intervals using the periodogram as the input.

Create a signal consisting of a 100 Hz sine wave and a chirp signal with frequency content between 220 Hz and 270 Hz, all in additive N(0,1) white Gaussian noise. The sample rate is 1 kHz. Obtain the periodogram and the corresponding frequency vector. Reset the random number generator for reproducible results. Plot the periodogram of the signal.

rng("default")

Fs = 1000;
t = 0:1/Fs:1-0.001;
x = cos(2*pi*100*t) + t.*chirp(t,220,t(end),270) + 0.2*randn(size(t));

[Pxx,F] = periodogram(x,hamming(length(x)),length(x),Fs);
periodogram(x,hamming(length(x)),length(x),Fs)

Figure contains an axes object. The axes object with title Periodogram Power Spectral Density Estimate, xlabel Frequency (Hz), ylabel Power/Frequency (dB/Hz) contains an object of type line.

Using the PSD estimate, determine the percentage of total power in the frequency intervals between 50 Hz and 150 Hz and between 200 Hz and 300 Hz.

powBands = bandpower(Pxx,F,[50 150;200 300],"psd");
powTotal = bandpower(Pxx,F,[0 500],"psd");
powPercent = 100*(powBands/powTotal)
powPercent = 2×1

   76.0390
   20.6880

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 sample rate 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 2 norm.

p = bandpower(x)
p = 1×3

    1.5264    1.5382    1.4717

l2norm = dot(x,x)/length(x)
l2norm = 1×3

    1.5264    1.5382    1.4717

Input Arguments

collapse all

Input time series data, specified as a row or column vector or as a matrix. If x is a matrix, then its columns are treated as independent channels.

Example: cos(pi/4*(0:159))'+randn(160,1) is a single-channel column-vector signal.

Example: cos(pi./[4;2]*(0:159))'+randn(160,2) is a two-channel noisy sinusoid.

Data Types: double | single
Complex Number Support: Yes

Sample rate for the input time series data, specified as a positive scalar.

Data Types: double | single

Frequency range for the band-power computation, specified as a two-element real-valued vector or as an M-by-2 real-valued matrix. M is the number of intervals along which to compute the band power.

If the input signal x contains N samples, the freqRange vector or each row of the freqRange matrix must be within these intervals:

  • [0, Fs/2] if x is real-valued and N is even

  • [0, (N – 1)Fs/(2N)] if x is real-valued and N is odd

  • [–(N – 2)Fs/(2N), Fs/2] if x is complex-valued and N is even

  • [–(N – 1)Fs/(2N), (N – 1)Fs/(2N)] if x is complex-valued and N is odd

Data Types: double | single

One- or two-sided PSD estimates, specified as a real-valued column vector or matrix with nonnegative elements.

  • The function associates each row of pxx to an element of f and treats each column of pxx as a PSD estimate.

  • The power spectral density must be expressed in linear units, not decibels. Use db2pow to convert decibel values to power values.

Example: [pxx,f] = periodogram(cos(pi./[4;2]*(0:159))'+randn(160,2)) specifies the periodogram PSD estimate of a noisy two-channel sinusoid sampled at 2π Hz and the frequencies at which it is computed.

Data Types: double | single

Frequencies for PSD estimates, specified as a vector with real-valued elements. The vector f contains the frequencies corresponding to the PSD estimates in pxx.

Data Types: double | single

Output Arguments

collapse all

Average band power, returned as a nonnegative vector with a number of elements equal to the number of rows of freqRange.

Data Types: double | single

Algorithms

To determine the band power, bandpower computes a periodogram power spectrum estimate using a Hamming window.

You can obtain the same value of band power, bPow, over the frequency interval [fMin fMax] from a signal x at a sample rate Fs in these three ways.

Directly from the signal
bPow = bandpower(x,Fs,[fMin fMax])
From the periodogram of the signal
[P,F] = periodogram(x,hamming(length(x)),length(x),Fs);
bPow = bandpower(P,F,[fMin fMax],"psd")
From the power spectral estimate (Welch's PSD) of the signal
[P,F] = pwelch(x,hamming(length(x)),[],length(x),Fs);
bPow = bandpower(P,F,[fMin fMax],"psd")

Note

Because bandpower uses an intermediary representation to transform the input signal from the time domain to frequency domain, the returned band power might vary, depending on the signal transformation method, number of DFT points, and window size.

References

[1] Hayes, Monson H. Statistical Digital Signal Processing and Modeling. New York: John Wiley & Sons, 1996.

[2] Stoica, Petre, and Randolph Moses. Spectral Analysis of Signals. Upper Saddle River, NJ: Prentice Hall, 2005.

Extended Capabilities

expand all

Version History

Introduced in R2013a

expand all

See Also

| | |