← [Documentation index](README.md)
# API Reference
All core functionality can be imported directly from the `pyoctaveband` package.
| Name | Type | Description (Inputs) | Usage Snippet (Outputs) |
| :--- | :--- | :--- | :--- |
| `octavefilter` | `function` | **High-level analysis.**
• `x`: Signal array
• `fs`: Sample rate [Hz]
• `fraction`: 1, 3, etc. (Default: 1)
• `order`: Filter order (Default: 6)
• `limits`: [f_min, f_max] (Default: [12, 20000])
• `filter_type`: 'butter', 'cheby1', 'cheby2', 'ellip', 'bessel' (Default: 'butter')
• `sigbands`: Return time signals (Default: False)
• `detrend`: Remove DC offset (Default: True)
• `calibration_factor`: Sensitivity multiplier (Default: 1.0)
• `dbfs`: Output in dBFS instead of dB SPL (Default: False)
• `mode`: 'rms' or 'peak' (Default: 'rms')
• `nominal`: IEC 61260-1 nominal labels (Default: False)
• `show`: Plot response (Default: False)
• `plot_file`: Path to save plot (Default: None)
• `ripple`: Passband ripple [dB] (for cheby1/ellip)
• `attenuation`: Stopband atten. [dB] (for cheby2/ellip) | `spl, freq = octavefilter(x, fs, ...)`
• `spl`: levels [dB]
• `freq`: frequencies [Hz]
**With `sigbands=True`:**
`spl, freq, xb = octavefilter(x, fs, sigbands=True)`
• `xb`: List of filtered signals (one per band)
**Calibrated usage:**
`spl, f = octavefilter(x, fs, calibration_factor=0.05)` |
| `OctaveFilterBank` | `class` | **Efficient bank implementation.**
• `fs`: Sample rate [Hz]
• `fraction`: 1, 3, etc.
• `order`: Filter order
• `limits`: [f_min, f_max] (Default: [12, 20000])
• `filter_type`: Architecture name
• `show`: Plot response (Default: False)
• `plot_file`: Path to save the plot (Default: None)
• `calibration_factor`: Sensitivity multiplier
• `dbfs`: Use dBFS (Default: False)
• `stateful`: Carry filter state between calls (Default: False)
• `steady_ic`: Steady-state initial conditions (Default: False)
• `resample`: Multirate decimation (Default: True)
• `ripple`: Passband ripple [dB]
• `attenuation`: Stopband attenuation [dB] | `bank = OctaveFilterBank(fs=48000, fraction=3, order=6, filter_type='butter')`
`spl, f = bank.filter(x, sigbands=False, mode='rms', detrend=True, zero_phase=False)`
• `bank`: Instance of the filter bank
• `bank.freq` / `bank.freq_d` / `bank.freq_u` / `bank.sos`: computed properties |
| `OctaveFilterBank.spectrogram` | `method` | **Band levels over time.**
• `x`: Signal array (1D or 2D)
• `window_time`: Window length [s] (Default: 0.125)
• `overlap`: Fraction in [0, 1) (Default: 0.5)
• `mode`: 'rms' or 'peak'
• `zero_phase`: Group-delay-free frames (Default: False) | `levels, freq, times = bank.spectrogram(x)`
• `levels`: (bands, frames) or (channels, bands, frames)
• `times`: window centers [s] |
| `weighting_filter` | `function` | **Acoustic weighting.**
• `x`: Signal array
• `fs`: Sample rate [Hz]
• `curve`: 'A', 'C', or 'Z' (Default: 'A')
• `high_accuracy`: IEC class 1 HF accuracy via internal oversampling (Default: True) | `y = weighting_filter(x, fs, curve='A')`
• `y`: weighted signal |
| `WeightingFilter` | `class` | **Reusable weighting filter.**
• `fs`: Sample rate [Hz]
• `curve`: 'A', 'C' or 'Z'
• `stateful`: Block processing (Default: False)
• `steady_ic`: Steady-state initial conditions (Default: False)
• `high_accuracy`: Defaults to True except stateful | `wf = WeightingFilter(fs, 'A')`
`y = wf.filter(x)` |
| `time_weighting` | `function` | **Energy capture.**
• `x`: Raw signal array (squared internally; time is the last axis)
• `fs`: Sample rate [Hz]
• `mode`: 'fast', 'slow', or 'impulse'
• `initial_state`: None, 'zero', 'first', scalar, or array (Default: None) | `env = time_weighting(x, fs, mode='fast')`
• `env`: energy envelope (Mean Square), same shape as `x` |
| `TimeWeighting` | `class` | **Stateful time weighting.**
• `fs`: Sample rate [Hz]
• `mode`: 'fast', 'slow', 'impulse' (Default: 'fast') | `tw = TimeWeighting(fs, mode='fast')`
`env = tw.process(block)` per block
`tw.reset()` to start over |
| `leq` | `function` | **Equivalent level (Leq).**
• `x`: Signal array (1D or 2D)
• `calibration_factor`: Sensitivity multiplier (Default: 1.0)
• `dbfs`: Output in dBFS (Default: False) | `level = leq(x, calibration_factor=s)`
• `level`: Scalar (1D) or per-channel array (2D) |
| `laeq` | `function` | **A-weighted Leq (LAeq).**
• `x`: Signal array (1D or 2D)
• `fs`: Sample rate [Hz]
• `calibration_factor` / `dbfs`: as `leq` | `level = laeq(x, fs, calibration_factor=s)`
• `level`: Scalar (1D) or per-channel array (2D) |
| `ln_levels` | `function` | **Statistical levels (LN).**
• `x`: Signal array (1D or 2D)
• `fs`: Sample rate [Hz]
• `n`: Exceedance percentiles (Default: (10, 50, 90))
• `mode`: 'fast', 'slow', 'impulse' (Default: 'fast')
• `weighting`: 'A', 'C', 'Z' or None (Default: None)
• `calibration_factor` / `dbfs`: as `leq` | `stats = ln_levels(x, fs, n=(10, 50, 90), weighting='A')`
• `stats`: Dict `{10: L10, 50: L50, 90: L90}` |
| `linkwitz_riley` | `function` | **Audio crossover.**
• `x`: Signal array
• `fs`: Sample rate [Hz]
• `freq`: Crossover frequency [Hz]
• `order`: Any even number (Default: 4) | `lo, hi = linkwitz_riley(x, fs, freq=1000, order=4)`
• `lo`: Low-pass filtered signal
• `hi`: High-pass filtered signal |
| `calculate_sensitivity` | `function`| **SPL Calibration.**
• `ref_signal`: Calibration signal
• `target_spl`: Level of calibrator (Default: 94.0)
• `ref_pressure`: Reference pressure (Default: 20e-6) | `s = calculate_sensitivity(ref_signal, target_spl=94.0)`
• `s`: Float (multiplier for pressure) |
| `verify_filter_class` | `function` | **IEC 61260-1:2014 class check.**
• `bank`: an `OctaveFilterBank`
• `num_points`: frequency grid points per band (Default: 32768) | `result = verify_filter_class(bank)`
• `result["overall_class"]`: 1, 2 or None
• `result["bands"]`: per-band class and margins [dB] |
| `getansifrequencies` | `function` | **ANSI Frequency generator.**
• `fraction`: 1, 3, etc. (Required)
• `limits`: [f_min, f_max] (Default: [12, 20000]) | `f_cen, f_low, f_high, labels = getansifrequencies(fraction=3)`
• `f_cen`: List of center frequencies [Hz]
• `f_low`: List of lower edges [Hz]
• `f_high`: List of upper edges [Hz]
• `labels`: IEC nominal frequency labels |
| `normalizedfreq` | `function` | **Standard IEC Frequencies.**
• `fraction`: 1 or 3 | `freqs = normalizedfreq(fraction=3)`
• `freqs`: List of standard center frequencies [Hz] |
## Notes
- `zero_phase=True` (in `OctaveFilterBank.filter` and `spectrogram`) filters
forward-backward (`sosfiltfilt`): no group delay, doubled effective
attenuation, offline analysis only. Incompatible with `stateful=True`.
- `mode='peak'` includes the filter's onset transient; a tone that starts
abruptly can overshoot by ~1 dB. See [Calibration and dBFS](calibration.md).
- `octavefilter()` caches filter bank designs internally (32 entries), so
repeated calls with the same parameters skip the design phase. For explicit
control use `OctaveFilterBank`.