Biquad Filter

Second-order IIR (biquad) filter supporting seven filter types. Based on the Audio EQ Cookbook by Robert Bristow-Johnson.

Transfer function:

\[H(z) = \frac{b_0 + b_1 z^{-1} + b_2 z^{-2}}{a_0 + a_1 z^{-1} + a_2 z^{-2}}\]

Only five multiplications and four additions per sample, making it efficient for real-time audio.

Filter types

Constant

Type

Description

LPF

Low-pass

Passes frequencies below the cutoff

HPF

High-pass

Passes frequencies above the cutoff

BPF

Band-pass

Passes frequencies near the centre frequency

NOTCH

Notch

Rejects frequencies near the centre frequency

PEQ

Peaking EQ

Boost or cut at the centre frequency

LSH

Low shelf

Boost or cut all frequencies below the cutoff

HSH

High shelf

Boost or cut all frequencies above the cutoff

class pyminidsp.BiquadFilter(filter_type, freq, sample_rate, db_gain=0.0, bandwidth=1.0)[source]

Biquad (second-order IIR) filter.

Supports low-pass, high-pass, band-pass, notch, peaking EQ, low shelf, and high shelf filter types.

Example

>>> filt = BiquadFilter(LPF, freq=1000.0, sample_rate=44100.0)
>>> for sample in signal:
...     output = filt.process(sample)
# Low-pass at 1 kHz, process a full signal
lpf = md.BiquadFilter(md.LPF, freq=1000.0, sample_rate=44100.0)
filtered = lpf.process_array(signal)

# Peaking EQ: +6 dB at 3 kHz
eq = md.BiquadFilter(md.PEQ, freq=3000.0, sample_rate=44100.0, db_gain=6.0)

# Sample-by-sample processing
for sample in signal:
    out = lpf.process(sample)
process(sample)[source]

Process a single sample through the filter.

process_array(signal)[source]

Process an entire signal through the filter.

Parameters:

signal – Input numpy array.

Returns:

Filtered numpy array.