ezmsg.sigproc.firfilter#

Functions

firwin_design_fun(fs, order=0, cutoff=None, width=None, window='hamming', pass_zero=True, scale=True, wn_hz=True)[source]#

Design an order`th-order FIR filter and return the filter coefficients. See :obj:`FIRFilterSettings for argument description.

Returns:

The filter taps as designed by firwin

Parameters:
Return type:

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

Classes

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

Bases: BaseFilterByDesignTransformerUnit[FIRFilterSettings, FIRFilterTransformer]

Parameters:

settings (Settings | None)

SETTINGS#

alias of FIRFilterSettings

class FIRFilterSettings(axis=None, coef_type='ba', order=0, cutoff=None, width=None, window='hamming', pass_zero=True, scale=True, wn_hz=True)[source]#

Bases: FilterBaseSettings

Settings for FIRFilter. See scipy.signal.firwin for more details

Parameters:
order: int = 0#

Filter order/number of taps

cutoff: float | Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] | None = None#

Cutoff frequency of filter (expressed in the same units as fs) OR an array of cutoff frequencies (that is, band edges). In the former case, as a float, the cutoff frequency should correspond with the half-amplitude point, where the attenuation will be -6dB. In the latter case, the frequencies in cutoff should be positive and monotonically increasing between 0 and fs/2. The values 0 and fs/2 must not be included in cutoff.

width: float | None = None#

If width is not None, then assume it is the approximate width of the transition region (expressed in the same units as fs) for use in Kaiser FIR filter design. In this case, the window argument is ignored.

window: str | None = 'hamming'#

Desired window to use. See scipy.signal.get_window for a list of windows and required parameters.

pass_zero: bool | str = True#

If True, the gain at the frequency 0 (i.e., the “DC gain”) is 1. If False, the DC gain is 0. Can also be a string argument for the desired filter type (equivalent to btype in IIR design functions). {‘lowpass’, ‘highpass’, ‘bandpass’, ‘bandstop’}

scale: bool = True#

Set to True to scale the coefficients so that the frequency response is exactly unity at a certain frequency. That frequency is either: * 0 (DC) if the first passband starts at 0 (i.e. pass_zero is True) * fs/2 (the Nyquist frequency) if the first passband ends at fs/2

(i.e the filter is a single band highpass filter); center of first passband otherwise

__init__(axis=None, coef_type='ba', order=0, cutoff=None, width=None, window='hamming', pass_zero=True, scale=True, wn_hz=True)#
Parameters:
Return type:

None

wn_hz: bool = True#

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

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

Bases: FilterByDesignTransformer[FIRFilterSettings, tuple[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]]] | None]

class FIRFilterSettings(axis=None, coef_type='ba', order=0, cutoff=None, width=None, window='hamming', pass_zero=True, scale=True, wn_hz=True)[source]#

Bases: FilterBaseSettings

Settings for FIRFilter. See scipy.signal.firwin for more details

Parameters:
order: int = 0#

Filter order/number of taps

cutoff: float | Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] | None = None#

Cutoff frequency of filter (expressed in the same units as fs) OR an array of cutoff frequencies (that is, band edges). In the former case, as a float, the cutoff frequency should correspond with the half-amplitude point, where the attenuation will be -6dB. In the latter case, the frequencies in cutoff should be positive and monotonically increasing between 0 and fs/2. The values 0 and fs/2 must not be included in cutoff.

width: float | None = None#

If width is not None, then assume it is the approximate width of the transition region (expressed in the same units as fs) for use in Kaiser FIR filter design. In this case, the window argument is ignored.

window: str | None = 'hamming'#

Desired window to use. See scipy.signal.get_window for a list of windows and required parameters.

pass_zero: bool | str = True#

If True, the gain at the frequency 0 (i.e., the “DC gain”) is 1. If False, the DC gain is 0. Can also be a string argument for the desired filter type (equivalent to btype in IIR design functions). {‘lowpass’, ‘highpass’, ‘bandpass’, ‘bandstop’}

scale: bool = True#

Set to True to scale the coefficients so that the frequency response is exactly unity at a certain frequency. That frequency is either: * 0 (DC) if the first passband starts at 0 (i.e. pass_zero is True) * fs/2 (the Nyquist frequency) if the first passband ends at fs/2

(i.e the filter is a single band highpass filter); center of first passband otherwise

__init__(axis=None, coef_type='ba', order=0, cutoff=None, width=None, window='hamming', pass_zero=True, scale=True, wn_hz=True)#
Parameters:
Return type:

None

wn_hz: bool = True#

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

firwin_design_fun(fs, order=0, cutoff=None, width=None, window='hamming', pass_zero=True, scale=True, wn_hz=True)[source]#

Design an order`th-order FIR filter and return the filter coefficients. See :obj:`FIRFilterSettings for argument description.

Returns:

The filter taps as designed by firwin

Parameters:
Return type:

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

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

Bases: FilterByDesignTransformer[FIRFilterSettings, tuple[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]]] | None]

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

Bases: BaseFilterByDesignTransformerUnit[FIRFilterSettings, FIRFilterTransformer]

Parameters:

settings (Settings | None)

SETTINGS#

alias of FIRFilterSettings