Qu

band_power

Builtin index · Signal processing

result = band_power(X, f0, f1)

Input: X, f0, f1 · Output: result

What it is

X: a raw_transform-scaled spectrum; f0, f1: numbers (Hz, f1 >= f0).

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = band_power(X, f0, f1)
X —X: a raw_transform-scaled spectrum.
f0 numberf0, f1: numbers (Hz, f1 >= f0).
f1 numberf0, f1: numbers (Hz, f1 >= f0).
result —
Returns the power in that frequency band by Parseval, normalised by N^2 so a tone of amplitude A reads A^2/2. On a full spectrum each conjugate pair is counted once, since the pair is one physical tone. Refuses an "amplitude"/"rms"-scaled X today — call spectrum_unnormalize(X) first.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

fs  = 1000
t   = (0 to 999) / fs
x   = sin(2*pi*100*t) + 0.5*sin(2*pi*300*t)
sig = signal(x, fs)

X = fft(sig)
print("df = {X.df} Hz, Nyquist = {X.nyquist} Hz")
print("power at 100 Hz: {band_power(X, 90, 110)}")     # 0.5  = 1.0^2/2

print("power at 300 Hz: {band_power(X, 290, 310)}")    # 0.125 = 0.5^2/2


clean = ifft(band_zero(X, 250, 350))                    # notch out the 300 Hz tone

print("residual imaginary part: {max(abs(imag(clean)))}")   # ~1e-16, still real

output
df = 1 Hz, Nyquist = 500 Hz
power at 100 Hz: 0.5
power at 300 Hz: 0.125
residual imaginary part: 3.079059e-16

from signal-processing