Butterworth

class gpype.backend.filters.base.butterworth.Butterworth[source]

Bases: IONode

Butterworth filter implementation for real-time signal processing.

Implements a Butterworth digital filter using second-order sections for numerical stability. Supports lowpass, highpass, bandpass, and bandstop filtering with configurable order and maintains state for streaming data.

DEFAULT_ORDER = 2

Default filter order for Butterworth filters

class Configuration[source]

Bases: Configuration

Configuration class for Butterworth filter parameters.

class Keys[source]

Bases: Keys

Configuration keys for Butterworth filter settings.

FN = 'fn'

Cutoff frequencies configuration key

BTYPE = 'btype'

Filter type configuration key

ORDER = 'order'

Filter order configuration key

__init__(fn, btype, order=None, **kwargs)[source]

Initialize the Butterworth filter with specified parameters.

Parameters:
  • fn (list) – List of cutoff frequencies in Hz. Single value for lowpass/ highpass, two values [low, high] for bandpass/bandstop.

  • btype (str) – Filter type (‘lowpass’, ‘highpass’, ‘bandpass’, ‘bandstop’).

  • order (int) – Filter order. Defaults to 2 if not specified.

  • **kwargs – Additional arguments passed to parent IONode class.

Raises:

ValueError – If fn is not a list, btype is invalid, or order <= 0.

setup(data, port_context_in)[source]

Setup the Butterworth filter before processing begins.

Initializes filter coefficients and state based on sampling rate and channel configuration from input context.

Parameters:
  • data (dict[str, ndarray]) – Initial data dictionary (not used in setup).

  • port_context_in (dict[str, dict]) – Input port context with sampling_rate and channel_count metadata.

Return type:

dict[str, dict]

Returns:

Output port context dictionary with updated metadata.

Raises:

ValueError – If required context keys are missing.

step(data)[source]

Apply Butterworth filter to input data.

Processes input data through the filter while maintaining filter state for continuous operation.

Parameters:

data (dict[str, ndarray]) – Dictionary containing input data with key PORT_IN. Input should be 2D array (samples x channels).

Return type:

dict[str, ndarray]

Returns:

Dictionary with filtered data under key PORT_OUT.

Raises:

ValueError – If input data is not 2D array.