band_zero
Builtin index · Signal processing
result = band_zero(X, f0, f1)
Input: X, f0, f1 · Output: result
What it is
X: a spectrum; f0, f1: numbers (Hz, f1 >= f0).
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = band_zero(X, f0, f1) | X —X: a spectrum.f0 numberf0, f1: numbers (Hz, f1 >= f0).f1 numberf0, f1: numbers (Hz, f1 >= f0). | result — | Returns a new spectrum at the same Fs, N and scaling with that band cleared — an ideal brick-wall notch. On a full spectrum it also clears each bin's conjugate partner (N-k), which is what keeps the inverse transform real; clearing only the positive-frequency half is the classic way to get a silently complex signal back out of ifft. |
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