yodel.filter module

This module provides classes for audio signal filtering.

class yodel.filter.Biquad

Bases: builtins.object

A biquad filter is a 2-poles/2-zeros filter allowing to perform various kind of filtering. Signal attenuation is at a rate of 12 dB per octave.

Reference:
“Cookbook formulae for audio EQ biquad filter coefficients”, Robert Bristow-Johnson (http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt)
__init__()

Create an inactive biquad filter with a flat frequency response. To make the filter active, use one of the provided methods: low_pass(), high_pass(), band_pass(), all_pass(), notch(), peak(), low_shelf(), high_shelf() and custom().

all_pass(samplerate, center, resonance)

Make an all-pass filter.

Parameters:
  • samplerate – sample-rate in Hz
  • center – center frequency in Hz
  • resonance – resonance or Q-factor
band_pass(samplerate, center, resonance)

Make a band-pass filter.

Parameters:
  • samplerate – sample-rate in Hz
  • center – center frequency in Hz
  • resonance – resonance or Q-factor
custom(a0, a1, a2, b0, b1, b2)

Make a custom filter. If the provided coefficients are already normalized, make sure to set a0 to 1.

Parameters:
  • a0 – a[0] coefficient
  • a1 – a[1] coefficient
  • a2 – a[2] coefficient
  • b0 – b[0] coefficient
  • b1 – b[1] coefficient
  • b2 – b[2] coefficient
high_pass(samplerate, cutoff, resonance)

Make a high-pass filter.

Parameters:
  • samplerate – sample-rate in Hz
  • cutoff – cut-off frequency in Hz
  • resonance – resonance or Q-factor
high_shelf(samplerate, cutoff, resonance, dbgain)

Make a high-shelf filter.

Parameters:
  • samplerate – sample-rate in Hz
  • cutoff – cut-off frequency in Hz
  • resonance – resonance or Q-factor
  • dbgain – gain in dB
low_pass(samplerate, cutoff, resonance)

Make a low-pass filter.

Parameters:
  • samplerate – sample-rate in Hz
  • cutoff – cut-off frequency in Hz
  • resonance – resonance or Q-factor
low_shelf(samplerate, cutoff, resonance, dbgain)

Make a low-shelf filter.

Parameters:
  • samplerate – sample-rate in Hz
  • cutoff – cut-off frequency in Hz
  • resonance – resonance or Q-factor
  • dbgain – gain in dB
notch(samplerate, center, resonance)

Make a notch filter.

Parameters:
  • samplerate – sample-rate in Hz
  • center – center frequency in Hz
  • resonance – resonance or Q-factor
peak(samplerate, center, resonance, dbgain)

Make a peak filter.

Parameters:
  • samplerate – sample-rate in Hz
  • center – center frequency in Hz
  • resonance – resonance or Q-factor
  • dbgain – gain in dB
process(x, y)

Filter an input signal. Can be used for in-place filtering.

Parameters:
  • x – input buffer
  • y – output buffer
process_sample(x)

Filter a single sample and return the filtered sample.

Parameters:x – input sample
Return type:filtered sample
reset()

Make the filter inactive with a flat frequency response.

class yodel.filter.Comb(samplerate, delay, gain)

Bases: builtins.object

A comb filter combines the input signal with a delayed copy of itself. Three types are available: feedback, feedforward and allpass.

References:

“Physical Audio Signal Processing”, Julius O. Smith (https://ccrma.stanford.edu/~jos/pasp/Comb_Filters.html)

“Introduction to Computer Music”, Nick Collins

__init__(samplerate, delay, gain)

Create a comb filter. By default, it is an allpass but one can select another type with feedback(), feedforward() and allpass() methods.

Parameters:
  • samplerate – sample-rate in Hz
  • delay – delay in ms
  • gain – gain between -1 and +1
allpass(delay, gain)

Make a feedforward comb filter.

Parameters:
  • delay – delay in ms
  • gain – gain between -1 and + 1
feedback(delay, gain)

Make a feedback comb filter.

Parameters:
  • delay – delay in ms
  • gain – gain between -1 and + 1
feedforward(delay, gain)

Make a feedforward comb filter.

Parameters:
  • delay – delay in ms
  • gain – gain between -1 and + 1
process(input_signal, output_signal)

Filter an input signal.

Parameters:
  • input_signal – input signal
  • output_signal – filtered signal
process_sample(input_sample)

Filter a single sample.

Parameters:input_sample – input sample
Returns:filtered sample
reset()

Clear the current comb filter state.

set_delay(delay)

Change the current delay of the comb filter.

Parameters:delay – delay in ms
set_gain(gain)

Change the current gain of the comb filter.

Parameters:gain – gain between -1 and + 1
class yodel.filter.Convolution(framesize, impulse_response)

Bases: builtins.object

The convolution filter performs FIR filtering using a provided impulse response signal.

Warning:
It should not be used in practice for computational reasons, and should only be used for testing purposes. Instead, prefer using the FastConvolution.
Reference:
“Digital Signal Processing, a practical guide for engineers and scientists”, Steven W. Smith
__init__(framesize, impulse_response)

Create a convolution filter.

Parameters:
  • framesize – framesize of input buffers to be filtered
  • impulse_response – the impulse response signal to used
process(input_signal, output_signal)

Filter an input signal with the impulse response. The length of the input signal must be the one defined at filter creation.

The filtered output signal will be of the same length. The ‘tail’ of the convolution will be added to the beginning of the next filtered signal.

To obtain the ‘tail’ of the convolution without filtering another signal, simply process an input signal filled with zeros.

Parameters:
  • input_signal – input signal to be filtered
  • output_signal – filtered signal
class yodel.filter.Custom(samplerate, framesize)

Bases: builtins.object

A custom filter allows to design precisely the frequency response of a digital filter. The filtering is then performed with a FastConvolution filter.

Reference:
“Digital Signal Processing, a practical guide for engineers and scientists”, Steven W. Smith
__init__(samplerate, framesize)

Create a custom filter with a flat frequency response. By default, the filter has a latency of (framesize/2) samples.

Parameters:
  • samplerate – sample-rate in Hz
  • framesize – framesize of input buffers to be filtered
design(freqresponse, db=True)

Create the filter impulse response from the specified frequency response.

The response must represent the desired spectrum, and of size (Nfft/2+1). The latency of the filter will be of (Nfft/2) samples.

The values of the frequency bands can either be specified in linear scale (1 being flat) or in dB scale (0 being flat).

Parameters:
  • freqresponse – desired frequency response
  • db – True if the frequency response is specified in dB
process(input_signal, output_signal)

Filter an input signal with the custom impulse response. The length of the input signal must be the one defined at filter creation.

As with Convolution, the filtered output signal will be of the same length. The ‘tail’ of the convolution will be added to the beginning of the next filtered signal.

To obtain the ‘tail’ of the convolution without filtering another signal, simply process an input signal filled with zeros.

Parameters:
  • input_signal – input signal to be filtered
  • output_signal – filtered signal
class yodel.filter.FastConvolution(framesize, impulse_response)

Bases: builtins.object

The fast convolution filter performs FIR filtering using a provided impulse response signal.

This filter uses a faster algorithm than standard Convolution, based on the yodel.analysis.FFT.

Reference:
“Digital Signal Processing, a practical guide for engineers and scientists”, Steven W. Smith
__init__(framesize, impulse_response)

Create a fast convolution filter.

Parameters:
  • framesize – framesize of input buffers to be filtered
  • impulse_response – the impulse response signal to used
process(input_signal, output_signal)

Filter an input signal with the impulse response. The length of the input signal must be the one defined at filter creation.

The filtered output signal will be of the same length. The ‘tail’ of the convolution will be added to the beginning of the next filtered signal.

To obtain the ‘tail’ of the convolution without filtering another signal, simply process an input signal filled with zeros.

Parameters:
  • input_signal – input signal to be filtered
  • output_signal – filtered signal
class yodel.filter.ParametricEQ(samplerate, bands)

Bases: builtins.object

A parametric equalizer provides multi-band equalization of audio signals. The center frequency, the resonance and the amplification (in dB) can be controlled individually for each frequency band.

__init__(samplerate, bands)

Create a parametric equalizer with a given number of frequency bands.

Parameters:
  • samplerate – sample-rate in Hz
  • bands – number of bands (at least 2)
process(input_signal, output_signal)

Filter an input signal. Can be used for in-place filtering.

Parameters:
  • input_signal – input buffer
  • output_signal – filtered buffer
set_band(band, center, resonance, dbgain)

Change the parameters for the selected frequency band.

Parameters:
  • band – index of the band (from 0 to (total number of bands - 1))
  • cutoff – cut-off frequency in Hz
  • resonance – resonance or Q-factor
  • dbgain – gain in dB
class yodel.filter.SinglePole

Bases: builtins.object

A single pole filter is used to perform low-pass and high-pass filtering. Signal attenuation is at a rate of 6 dB per octave.

Reference:
“Digital Signal Processing, a practical guide for engineers and scientists”, Steven W. Smith
__init__()

Create an inactive single pole filter with a flat frequency response. To make the filter active, use one of the provided methods: low_pass() and high_pass().

high_pass(samplerate, cutoff)

Make a high-pass filter.

Parameters:
  • samplerate – sample-rate in Hz
  • cutoff – cut-off frequency in Hz
low_pass(samplerate, cutoff)

Make a low-pass filter.

Parameters:
  • samplerate – sample-rate in Hz
  • cutoff – cut-off frequency in Hz
process(x, y)

Filter an input signal. Can be used for in-place filtering.

Parameters:
  • x – input buffer
  • y – output buffer
process_sample(x)

Filter a single sample and return the filtered sample.

Parameters:x – input sample
Return type:filtered sample
reset()

Create an inactive single pole filter with a flat frequency response. To make the filter active, use one of the provided methods.

class yodel.filter.StateVariable

Bases: builtins.object

A state variable filter provides simultaneously low-pass, high-pass, band-pass and band-reject filtering. Like the Biquad filter, signal attenuation is at a rate of 12 dB per octave. Nevertheless, the filter becomes unstable at higher frequencies (around one sixth of the sample-rate).

__init__()

Create an inactive state variable filter with a flat frequency response. To make the filter active, use the set() method.

process(x, hp, bp, lp, br)

Filter an input signal. Can be used for in-place filtering.

Parameters:
  • x – input buffer
  • hp – high-pass filtered output
  • bp – band-pass filtered output
  • lp – low-pass filtered output
  • br – band-reject filtered output
process_sample(x)

Filter a single sample and return the filtered samples.

Parameters:x – input sample
Return type:tuple (high-pass, band-pass, low-pass, band-reject)
reset()

Make the filter inactive with a flat frequency response.

set(samplerate, cutoff, resonance)

Specify the parameters of the filter.

Parameters:
  • samplerate – sample-rate in Hz
  • cutoff – cut-off frequency in Hz
  • resonance – resonance or Q-factor
class yodel.filter.WindowedSinc(samplerate, framesize)

Bases: builtins.object

A windowed sinc filter allows to separate one frequency band from another, using low_pass(), high_pass(), band_pass() and band_reject() forms. Windowing is done using a Blackman yodel.analysis.Window. The filtering is performed with a FastConvolution filter.

Reference:
“Digital Signal Processing, a practical guide for engineers and scientists”, Steven W. Smith
__init__(samplerate, framesize)

Create a windowed sinc filter with a flat frequency response.

Parameters:
  • samplerate – sample-rate in Hz
  • framesize – framesize of input buffers to be filtered
band_pass(center, bandwidth)

Make a band-pass filter with given center frequency and bandwidth. Lowering the bandwidth will increase the size of the kernel filter, thus increasing the roll-off rate but also the computation cost.

Parameters:
  • center – center frequency in Hz
  • bandwidth – frequency band width in Hz
band_reject(center, bandwidth)

Make a band-reject filter with given center frequency and bandwidth. Lowering the bandwidth will increase the size of the kernel filter, thus increasing the roll-off rate but also the computation cost.

Parameters:
  • center – center frequency in Hz
  • bandwidth – frequency band width in Hz
high_pass(cutoff, bandwidth)

Make a high-pass filter with given cutoff frequency and bandwidth. Lowering the bandwidth will increase the size of the kernel filter, thus increasing the roll-off rate but also the computation cost.

Parameters:
  • cutoff – cut-off frequency in Hz
  • bandwidth – frequency band width in Hz
low_pass(cutoff, bandwidth)

Make a low-pass filter with given cutoff frequency and bandwidth. Lowering the bandwidth will increase the size of the kernel filter, thus increasing the roll-off rate but also the computation cost.

Parameters:
  • cutoff – cut-off frequency in Hz
  • bandwidth – frequency band width in Hz