ezmsg.sigproc.butterworthfilter#

Functions

butter(axis, order=0, cuton=None, cutoff=None, coef_type='ba', wn_hz=True)[source]#

Convenience generator wrapping filter_gen_by_design for Butterworth filters. Apply Butterworth filter to streaming data. Uses scipy.signal.butter to design the filter. See ButterworthFilterSettings.filter_specs for an explanation of specifying different filter types (lowpass, highpass, bandpass, bandstop) from the parameters.

Returns:

ButterworthFilterTransformer

Parameters:
Return type:

ButterworthFilterTransformer

butter_design_fun(fs, order=0, cuton=None, cutoff=None, coef_type='ba', wn_hz=True)[source]#

See ButterworthFilterSettings.filter_specs for an explanation of specifying different filter types (lowpass, highpass, bandpass, bandstop) from the parameters. You are likely to want to use this function with filter_by_design, which only passes fs to the design function (this), meaning that you should wrap this function with a lambda or prepare with functools.partial.

Parameters:
  • fs (float) – The sampling frequency of the data in Hz.

  • order (int) – Filter order.

  • cuton (float | None) – Corner frequency of the filter in Hz.

  • cutoff (float | None) – Corner frequency of the filter in Hz.

  • coef_type (str) – “ba”, “sos”, or “zpk”

  • wn_hz (bool) – Set False if provided Wn are normalized from 0 to 1, where 1 is the Nyquist frequency

Returns:

The filter coefficients as a tuple of (b, a) for coef_type “ba”, or as a single ndarray for “sos”, or (z, p, k) for “zpk”.

Return type:

tuple[ndarray[tuple[Any, …], dtype[_ScalarT]], ndarray[tuple[Any, …], dtype[_ScalarT]]] | ndarray[tuple[Any, …], dtype[_ScalarT]] | None

Classes

class ButterworthFilter(*args, settings=None, **kwargs)[source]#

Bases: BaseFilterByDesignTransformerUnit[ButterworthFilterSettings, ButterworthFilterTransformer]

Parameters:

settings (Settings | None)

SETTINGS#

alias of ButterworthFilterSettings

class ButterworthFilterSettings(axis=None, coef_type='ba', order=0, cuton=None, cutoff=None, wn_hz=True)[source]#

Bases: FilterBaseSettings

Settings for ButterworthFilter.

Parameters:
order: int = 0#

Filter order

cuton: float | None = None#

Cuton frequency (Hz). If cutoff is not specified then this is the highpass corner. Otherwise, if this is lower than cutoff then this is the beginning of the bandpass or if this is greater than cutoff then this is the end of the bandstop.

cutoff: float | None = None#

Cutoff frequency (Hz). If cuton is not specified then this is the lowpass corner. Otherwise, if this is greater than cuton then this is the end of the bandpass, or if this is less than cuton then this is the beginning of the bandstop.

wn_hz: bool = True#

Set False if provided Wn are normalized from 0 to 1, where 1 is the Nyquist frequency

filter_specs()[source]#

Determine the filter type given the corner frequencies.

Returns:

A tuple with the first element being a string indicating the filter type (one of “lowpass”, “highpass”, “bandpass”, “bandstop”) and the second element being the corner frequency or frequencies.

Return type:

tuple[str, float | tuple[float, float]] | None

__init__(axis=None, coef_type='ba', order=0, cuton=None, cutoff=None, wn_hz=True)#
Parameters:
Return type:

None

class ButterworthFilterTransformer(*args, **kwargs)[source]#

Bases: FilterByDesignTransformer[ButterworthFilterSettings, tuple[ndarray[tuple[Any, …], dtype[_ScalarT]], ndarray[tuple[Any, …], dtype[_ScalarT]]] | ndarray[tuple[Any, …], dtype[_ScalarT]]]

get_design_function()[source]#

Return a function that takes sampling frequency and returns filter coefficients.

Return type:

Callable[[float], tuple[ndarray[tuple[Any, …], dtype[_ScalarT]], ndarray[tuple[Any, …], dtype[_ScalarT]]] | ndarray[tuple[Any, …], dtype[_ScalarT]] | None]

class ButterworthFilterSettings(axis=None, coef_type='ba', order=0, cuton=None, cutoff=None, wn_hz=True)[source]#

Bases: FilterBaseSettings

Settings for ButterworthFilter.

Parameters:
order: int = 0#

Filter order

cuton: float | None = None#

Cuton frequency (Hz). If cutoff is not specified then this is the highpass corner. Otherwise, if this is lower than cutoff then this is the beginning of the bandpass or if this is greater than cutoff then this is the end of the bandstop.

cutoff: float | None = None#

Cutoff frequency (Hz). If cuton is not specified then this is the lowpass corner. Otherwise, if this is greater than cuton then this is the end of the bandpass, or if this is less than cuton then this is the beginning of the bandstop.

wn_hz: bool = True#

Set False if provided Wn are normalized from 0 to 1, where 1 is the Nyquist frequency

filter_specs()[source]#

Determine the filter type given the corner frequencies.

Returns:

A tuple with the first element being a string indicating the filter type (one of “lowpass”, “highpass”, “bandpass”, “bandstop”) and the second element being the corner frequency or frequencies.

Return type:

tuple[str, float | tuple[float, float]] | None

__init__(axis=None, coef_type='ba', order=0, cuton=None, cutoff=None, wn_hz=True)#
Parameters:
Return type:

None

butter_design_fun(fs, order=0, cuton=None, cutoff=None, coef_type='ba', wn_hz=True)[source]#

See ButterworthFilterSettings.filter_specs for an explanation of specifying different filter types (lowpass, highpass, bandpass, bandstop) from the parameters. You are likely to want to use this function with filter_by_design, which only passes fs to the design function (this), meaning that you should wrap this function with a lambda or prepare with functools.partial.

Parameters:
  • fs (float) – The sampling frequency of the data in Hz.

  • order (int) – Filter order.

  • cuton (float | None) – Corner frequency of the filter in Hz.

  • cutoff (float | None) – Corner frequency of the filter in Hz.

  • coef_type (str) – “ba”, “sos”, or “zpk”

  • wn_hz (bool) – Set False if provided Wn are normalized from 0 to 1, where 1 is the Nyquist frequency

Returns:

The filter coefficients as a tuple of (b, a) for coef_type “ba”, or as a single ndarray for “sos”, or (z, p, k) for “zpk”.

Return type:

tuple[ndarray[tuple[Any, …], dtype[_ScalarT]], ndarray[tuple[Any, …], dtype[_ScalarT]]] | ndarray[tuple[Any, …], dtype[_ScalarT]] | None

class ButterworthFilterTransformer(*args, **kwargs)[source]#

Bases: FilterByDesignTransformer[ButterworthFilterSettings, tuple[ndarray[tuple[Any, …], dtype[_ScalarT]], ndarray[tuple[Any, …], dtype[_ScalarT]]] | ndarray[tuple[Any, …], dtype[_ScalarT]]]

get_design_function()[source]#

Return a function that takes sampling frequency and returns filter coefficients.

Return type:

Callable[[float], tuple[ndarray[tuple[Any, …], dtype[_ScalarT]], ndarray[tuple[Any, …], dtype[_ScalarT]]] | ndarray[tuple[Any, …], dtype[_ScalarT]] | None]

class ButterworthFilter(*args, settings=None, **kwargs)[source]#

Bases: BaseFilterByDesignTransformerUnit[ButterworthFilterSettings, ButterworthFilterTransformer]

Parameters:

settings (Settings | None)

SETTINGS#

alias of ButterworthFilterSettings

butter(axis, order=0, cuton=None, cutoff=None, coef_type='ba', wn_hz=True)[source]#

Convenience generator wrapping filter_gen_by_design for Butterworth filters. Apply Butterworth filter to streaming data. Uses scipy.signal.butter to design the filter. See ButterworthFilterSettings.filter_specs for an explanation of specifying different filter types (lowpass, highpass, bandpass, bandstop) from the parameters.

Returns:

ButterworthFilterTransformer

Parameters:
Return type:

ButterworthFilterTransformer