Documentation Center

  • Trials
  • Product Updates

bandpower

Syntax

  • p = bandpower(pxx,f,psdflag) example
  • p = bandpower(pxx,f,freqrange,psdflag) example

Description

example

p = bandpower(x) returns the average power in the input signal, x.

example

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

example

p = bandpower(pxx,f,psdflag) 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. psdflag is the string 'psd', which indicates the input is a PSD estimate and not time series data.

example

p = bandpower(pxx,f,freqrange,psdflag) 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.

Examples

expand all

Comparison with ℓ2 Norm

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 average power compare against the ℓ2 norm.

t = 0:0.001:1-0.001;
x = cos(2*pi*100*t)+randn(size(t));
p = bandpower(x)
norm(x,2)^2/numel(x)

Percentage of Total Power in Frequency Interval

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 [50,150] Hz interval.

t = 0:0.001:1-0.001;
x = cos(2*pi*100*t)+randn(size(t));
pband = bandpower(x,1000,[50 100]);
ptot = bandpower(x,1000,[0 500]);
per_power = 100*(pband/ptot)

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 psdflag, 'psd', 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')
norm(x,2)^2/numel(x)

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 interval [50,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)

Input Arguments

expand all

x — Time series inputrow or column vector

Input time series data, specified as a row or column vector

Example: cos(pi/4*(0:159))+randn(1,160)

Data Types: double | single
Complex Number Support: Yes

fs — Sampling frequency1 (default) | positive scalar

Sampling frequency for the input time series data, specified as a positive scalar.

Data Types: double | single

freqrange — Frequency range for band power computationtwo-element real-valued row or column vector

Frequency range for the band power computation, specified as a two-element real-valued row or column vector. If the input signal, x, contains N samples, freqrange must be within the following 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

pxx — PSD estimatesreal-valued column vector with nonnegative elements

One- or two-sided PSD estimate, specified as a column vector with nonnegative elements.

Data Types: double | single

f — Frequency vector for PSD estimatescolumn vector with real-valued elements

Frequency vector, specified as a column vector. The frequency vector, f, contains the frequencies corresponding to the PSD estimates in pxx.

Data Types: double | single

psdflag — Power spectrum input flag'psd'

Flag indicating that the input data is a PSD estimate, specified as the string 'psd'.

Output Arguments

expand all

p — Average band powernonnegative scalar

Average band power, specified as a nonnegative scalar.

Data Types: double | single

See Also

|

Was this topic helpful?