nnsa.preprocessing package
Submodules
nnsa.preprocessing.combine_channels module
Functions:
|
Combines multiple channels of a signal into one, by cutting the signals into pieces and pasting them together in an optimal way. |
- nnsa.preprocessing.combine_channels.combine_channels(x, preferred=None, min_nan_len=None)[source]
Combines multiple channels of a signal into one, by cutting the signals into pieces and pasting them together in an optimal way.
Segments the data based on the onsets and offsets of nans (disturbances). Then, for each segment the best channel is chosen, which is the channel with the least amount of NaNs. When multiple channels have the same amount of NaNs (e.g. zero), then preferred is used to prefer one signal over the others (see Args).
- Parameters:
x (np.ndarray) – 2D array with dimensions (channels, time) containing multiple channels of a certain signal.
preferred (int or list or function, optional) – indices for the channel dimension of x that specify which channels are preferred. If an int, specifies that a single channel is preferred. If a list, specifies a priority list of channels. If None, a channel is preferred such that the amount of switches between channels is minimized (sort of). If a function, takes in the two signals as a (n_channels, n_time) array and returns the index of the preferred signal segment.
min_nan_len (int, optional) – minimum number of consecutive nan samples to consider it as a disturbance and hence to consider it as a location to switch to another channel. If None, takes 5% of the total lenght.
- Returns:
x_combined (np.ndarray) – 1D array with dimension (time,) containing the combined signal.
Examples
>>> x = np.random.rand(3, 1000) >>> x[0, :200] = np.nan >>> x[1, 300:700] = np.nan >>> x[1, 250:260] = np.nan >>> x[0, 600:] = np.nan >>> preferred = [1, 2, 0] >>> x_combined = combine_channels(x, preferred=preferred)
# plt.figure() # ax = plt.subplot(211) # plt.plot(x.T) # plt.subplot(212, sharex=ax) # plt.plot(x.T) # plt.plot(x_combined, ‘–‘)
nnsa.preprocessing.data_cleaning module
Author: Tim Hermans (tim-hermans@hotmail.com).
Functions:
|
Identify transient bad EEG channels and substitute them by the mean of the good channels. |
- nnsa.preprocessing.data_cleaning.substitute_bad_channels(x, af_mask, fs=1, fs_grid=1, axis=0, aci_window=3, aci_threshold=50, max_channels=3, min_duration=0, transition_window=1, verbose=1)[source]
Identify transient bad EEG channels and substitute them by the mean of the good channels.
- The steps of the algorithm are:
- Compute the artefact contamination index (percentage of time where af_mask is True) in
a moving time window (aci_window).
Find samples with a moving ACI greater than the threshold (aci_threshold) and mark as artefact.
Find locations in time the amount of channels with an artefact does not exced max_channels.
Find segments during which the above holds and the same channels are marked as artefact.
- For all such segments that last at least min_duration, replace the artefact channels with the
mean of the non-artefact channels. To ensure a smooth transition, use a transition_window during which the original and the replaced signals linearly transition into each other. To do this, each segment is elongated left and right so that the transition happens outside the original segment.
- Parameters:
x (np.ndarray) – 2D array containg multi-channel data with shape (n_time, n_channels).
af_mask (np.ndarray) – boolean mask with shape (n_time, n_channels) containing True at locations of artefacts.
fs (float) – sampling frequency, scales the windows.
fs_grid (float) – sampling frequency of the grid onto which to snap the adaptive segments. If not None, the segments borders are snapped onto a grid with grid size 1/fs_grid.
axis (int) – time axis. If 1 or -1, the input shape is expected to be (n_channels, n_time).
aci_window (float) – time window in seconds in which to compute the moving ACI.
aci_threshold (float) – threshold in % for channel-ACI to consider the channel bad.
max_channels (int) – maximum number of channels that can be bad at the same time. If more channels in a segment are bad, no substitution is done.
min_duration (float) – minimum duration of artefact segment to subsitute. By default, half of aci_window is used.
transition_window (float) – time window in seconds used to transition from the original channel data to the substitute/clean data to ensure smooth transitions. This window falls completely within the to-be-substituted artefact.
verbose (int) – verbosity level.
- Returns:
x (np.ndarray) – new data.
af_mask (np.ndarray) – new af_mask.
nnsa.preprocessing.detrending module
Functions:
|
Detrend y=f(x) with a polynomial of specified order. |
- nnsa.preprocessing.detrending.detrend_poly(y, order, x=None)[source]
Detrend y=f(x) with a polynomial of specified order.
Can handle nan values (by ignoring the in the fit).
- Parameters:
y (np.ndarray) – 1D array with y values.
order (int) – order of the fitted polynomial.
x (np.ndarray) – optional array with x values (same shape as y). If not specified, x = np.arange(len(y)), assuming equidistant samples in y.
- Returns:
y_detrend (np.ndarray) – detrended signal.
nnsa.preprocessing.eeg module
EEG specific preprocessing routines.
Author: Tim Hermans (tim-hermans@hotmail.com).
Functions:
|
Clamp values outside [-250, 250] to limit the dynamic range. |
- nnsa.preprocessing.eeg.clamp_eeg(x)[source]
Clamp values outside [-250, 250] to limit the dynamic range.
References
Equation (1) in: L. Webb, M. Kauppila, J. A. Roberts, S. Vanhatalo, and N. J. Stevenson, “Automated detection of artefacts in neonatal EEG with residual neural networks,” Computer Methods and Programs in Biomedicine, vol. 208, p. 106194, Sep. 2021, doi: 10.1016/j.cmpb.2021.106194.
- Parameters:
x (np.ndarray) – array with values.
- Returns:
y (np.ndarray) – array with same shape as x but with values lower than -205 and higher than 250 clamped.
Examples
# Plot clamping function. >>> import matplotlib.pyplot as plt >>> x = np.linspace(-1000, 1000, 1000) >>> y = clamp_eeg(x) >>> plt.plot(x, x, linestyle=’–’, color=’C7’) #doctest:+ELLIPSIS [<matplotlib.lines.Line2D… >>> plt.plot(x, y) #doctest:+ELLIPSIS [<matplotlib.lines.Line2D…
nnsa.preprocessing.expansions module
Functions:
|
Create a (block) Hankel expansion for signals in x with specific window length and stride. |
- nnsa.preprocessing.expansions.create_hankel(x, window, stride=None, fs=1, concat=True)[source]
Create a (block) Hankel expansion for signals in x with specific window length and stride.
- Parameters:
x (np.ndarray) – 1D or 2D array with signal(s). If 2D, the size should be (n_samples, n_channels).
window (float) – length of a row of the hankel matrix in seconds (truncation order / fs).
stride (float, optional) – stride between the rows of the hankel matrix in seconds. If None, the stride is one sample (real hankel). Defaults to None.
fs (float, optional) – sample frequency in Hz. If 1, window and stride can be given in numbe of samples. Defaults to 1.
concat (bool, optional) – if True, concatenates the hankel matrices of each channel horizontally. If False, a list of hankel matrices per channel is returned. Defaults to True.
- Returns:
x_h_all (list or np.ndarray) – concatenation of channel-wise hankel matrices (if concat is True) or a list of the channel-wise hankel matrices (if concat is False).
Examples
>>> x = np.arange(10) # 10 samples. >>> x = np.vstack((x, 10*x, 100*x)).T # 3 channels. >>> print(x) [[ 0 0 0] [ 1 10 100] [ 2 20 200] [ 3 30 300] [ 4 40 400] [ 5 50 500] [ 6 60 600] [ 7 70 700] [ 8 80 800] [ 9 90 900]]
>>> xh = create_hankel(x, window=3, stride=2, fs=1, concat=True) >>> print(xh) [[ 0 1 2 0 10 20 0 100 200] [ 2 3 4 20 30 40 200 300 400] [ 4 5 6 40 50 60 400 500 600] [ 6 7 8 60 70 80 600 700 800]]
nnsa.preprocessing.filter module
Functions for filtering of signals.
Classes:
|
Create a Butterworth filter. |
|
Base class for a filter object with common utilities. |
|
Create a moving average (smoothening) filter. |
|
Create an assymetric FIR filter with specifications as done in the NEAT toolbox for MATLAB. |
|
Create an IIR notch (bandstop) filter. |
|
Design a minimax optimal filter using the Remez exchange algorithm. |
|
FIR filter design using the window method. |
Functions:
|
Filter the signal with the specified filter. |
|
Estimate the order of the FIR filter as computed with the Remez algorithm. |
- class nnsa.preprocessing.filter.Butterworth(tf=None, sos=None, fs=None, **kwargs)[source]
Bases:
FilterBaseCreate a Butterworth filter.
- Parameters:
FilterBase. (see) –
Examples
>>> fs = 2000 >>> t = np.linspace(0, 1.0, fs+1) >>> xlow = np.sin(2 * np.pi * 5 * t) # 5 Hz >>> xhigh = np.sin(2 * np.pi * 250 * t) # 250 Hz >>> x = xlow + xhigh >>> filt = Butterworth(fs=fs, passband=120, stopband=140) >>> y = filt.filtfilt(x) >>> print(np.abs(y - xlow).max()) 0.004803688903207593
Methods:
Return the default parameters.
- class nnsa.preprocessing.filter.FilterBase(tf=None, sos=None, fs=None, **kwargs)[source]
Bases:
ClassWithParametersBase class for a filter object with common utilities.
Child classes inheriting from this class need to implement at least one of _compute_sos() or _compute_tf(). Depending on which of these are implemented, the filtfilt() method will call the appropriate function to do the filtering (see filtfilt()).
- Parameters:
fs (float, optional) – frequency of the signal to filter in Hz.
tf (tuple, optional) – tuple of arrays (b, a) containing the transfer function filter coefficients.
sos (tuple, optional) – sos filter coefficients.
**kwargs – see ClassWithParameters.
Methods:
compute_frequency_response(**kwargs)Compute the frequency response of the filter.
Return the default parameters as a dictionary.
filter(x[, replace_nan, how])Filter the signal x by applying a digital filter.
filtfilt(x[, replace_nan, how])Filter the signal x by applying a digital filter forward and backward to a signal for zero-phase filtering.
plot_frequency_response([ax, angle])Plot the frequency response.
plot_impulse_response([ax, n])Plot the impulse response.
Attributes:
Sample frequency.
Second-order filter coefficients.
Transfer function coefficients.
- compute_frequency_response(**kwargs)[source]
Compute the frequency response of the filter.
- Returns:
w (np.ndarray) – the normalized frequencies at which h was computed, in radians/sample, see also scipy.signal.freqz().
h (np.ndarray) – the frequency response., see also scipy.signal.freqz().
**kwargs – optional keyword arguments for the scipy function.
- static default_parameters()[source]
Return the default parameters as a dictionary.
- Returns:
(dict or Parameters) – a default set of parameters for the object.
- filter(x, replace_nan=True, how='mean', **kwargs)[source]
Filter the signal x by applying a digital filter.
This is a wrapper of scipy.signal lfilter and sosfilt functions. See scipy.signal.lfilter() and scipy.signal.sosfilt() for more complete information.
- Parameters:
x (np.ndarray) – signal array.
replace_nan (bool, optional) – if True, replaces nans in the input with zeros and places nans in the output at the locations of nans in the input. Especially for IIR filters, this prevents the all subsequent output to become nan if there is a nan sample in the input. Defaults to True.
how (float, string) – how to deal with nans. If a float, this will be the fill value. If ‘mean’, nans will be replaced by the mean value. If ‘interpolate’, nans will be interpolated linearly.
**kwargs (optional) – see scipy.signal.lfilter() and scipy.signal.sosfilt().
- Returns:
y (np.ndarray) – the filtered output.
- Raises:
NotImplementedError if neither self.sos or self.tf are defined. –
- filtfilt(x, replace_nan=True, how='mean', **kwargs)[source]
Filter the signal x by applying a digital filter forward and backward to a signal for zero-phase filtering.
This is a wrapper of scipy.signal filtfilt functions. See scipy.signal.filtfilt() for more complete information.
- Parameters:
x (np.ndarray) – signal array.
replace_nan (bool, optional) – if True, replaces nans in the input with zeros and places nans in the output at the locations of nans in the input. Especially for IIR filters, this prevents the all subsequent output to become nan if there is a nan sample in the input. Defaults to True.
how (float, string) – how to deal with nans. If a float, this will be the fill value. If ‘mean’, nans will be replaced by the mean value. If ‘zeros’, nans will be replaced by zeros. If ‘interpolate’, nans will be interpolated linearly.
**kwargs (optional) – see scipy.signal.sosfiltfilt().
- Returns:
y (np.ndarray) – the filtered output.
- Raises:
NotImplementedError if neither self.sos or self.tf are defined. –
- property fs
Sample frequency.
- Returns:
self._fs (float) – Sample frequency.
- Raises:
AttributeError if self._fs is None. –
- plot_frequency_response(ax=None, angle=True, **kwargs)[source]
Plot the frequency response.
- Parameters:
ax – matplotlib axis object for plotting. If None, it plots in the current axis. Defaults to None.
angle (bool) – plot the phase angle or not.
**kwargs – optional arguments for self.compute_frequency_response()
- plot_impulse_response(ax=None, n=50, **kwargs)[source]
Plot the impulse response.
- Parameters:
ax – matplotlib axis object for plotting. If None, it plots in the current axis. Defaults to None.
n (int) – number of samples to plot the response for.
**kwargs – optional arguments for plt.stem().
- property sos
Second-order filter coefficients.
- Returns:
self._sos (np.ndarray) – see self._compute_sos().
- property tf
Transfer function coefficients.
- Returns:
self._tf (np.ndarray) – see self._compute_tf().
- class nnsa.preprocessing.filter.MovingAverage(tf=None, sos=None, fs=None, **kwargs)[source]
Bases:
FilterBaseCreate a moving average (smoothening) filter.
- Parameters:
FilterBase. (see) –
Examples
>>> np.random.seed(43) >>> N = 1000 >>> mean = 4.3 >>> x = mean + (np.random.rand(N) - 0.5)*abs(mean) >>> filt = MovingAverage(numtaps=200) >>> y = filt.filter(x) # Original signal at idx 500. >>> x[500] 5.322134095439112 # Moving averaged signal at idx 500. >>> y[500] 4.340021494627845
Methods:
Return the default parameters.
- class nnsa.preprocessing.filter.NeatFIR(tf=None, sos=None, fs=None, **kwargs)[source]
Bases:
FilterBaseCreate an assymetric FIR filter with specifications as done in the NEAT toolbox for MATLAB.
References
Z. A. Vesoulis, P. G. Gamble, S. Jain, N. M. E. Ters, S. M. Liao, and A. M. Mathur, “WU-NEAT: A clinically validated, open- source MATLAB toolbox for limited-channel neonatal EEG analysis,” 2018-05-11.
- Parameters:
FilterBase. (see) –
Methods:
Return the default parameters.
- class nnsa.preprocessing.filter.NotchIIR(tf=None, sos=None, fs=None, **kwargs)[source]
Bases:
FilterBaseCreate an IIR notch (bandstop) filter.
- Parameters:
FilterBase. (see) –
Examples
>>> fs = 2000 >>> t = np.linspace(0, 1.0, fs+1) >>> xlow = np.sin(2 * np.pi * 5 * t) # 5 Hz >>> xhigh = np.sin(2 * np.pi * 250 * t) # 250 Hz >>> x = xlow + xhigh >>> filt = NotchIIR(fs=fs, f0=250) >>> y = filt.filtfilt(x) >>> print(y[10]) 0.5425567000090112
Methods:
Return the default parameters.
- class nnsa.preprocessing.filter.RemezFIR(tf=None, sos=None, fs=None, **kwargs)[source]
Bases:
FilterBaseDesign a minimax optimal filter using the Remez exchange algorithm.
- Parameters:
FilterBase. (see) –
Examples
>>> fs = 2000 >>> t = np.linspace(0, 1.0, fs+1) >>> xlow = np.sin(2 * np.pi * 5 * t) # 5 Hz >>> xhigh = np.sin(2 * np.pi * 250 * t) # 250 Hz >>> x = xlow + xhigh >>> filt = RemezFIR(fs=fs, passband=120, stopband=140) >>> y = filt.filtfilt(x) >>> print(np.abs(y - xlow).max()) 0.05586442486553467
Methods:
Return the default parameters.
- class nnsa.preprocessing.filter.WinFIR(tf=None, sos=None, fs=None, **kwargs)[source]
Bases:
FilterBaseFIR filter design using the window method.
- Parameters:
FilterBase. (see) –
Examples
TODO
Methods:
Return the default parameters.
- nnsa.preprocessing.filter.filter_signal(x, specification, fs=None, axis=-1, **kwargs)[source]
Filter the signal with the specified filter.
If specification is a string, then a saved filter will be loaded and the signal will be filtered with this loaded filter(see filter_saved_filter()). If specification is a FilterBase object, the filtering will be perfomed by the filtfilt() function of that FilterBase object.
Note that the filters designed by scipy.signal package may be different from the filters as designed by MATLAB. To reproduce the result of MATLAB filtering, its best to create a new saved filter which laods/creates the filter coefficients using MATLAB (e.g. see filter_bandpassfir_a() and get_matlab_bandpassfir_coefs() in nnsa.preprocessing.saved_filters)
- Parameters:
x (np.ndarray) – signal to be filtered.
specification (str, FilterBase or None) – if a string, it is interpreted as a filter_name of a saved filter (see nnsa.filter_saved_filter()). If a FilterBase object, the objects filtfilt() function is used to do the filtering. If None, no filtering is applied to the segment.
fs (float, optional) – sample frequency of signal to be filtered. Needed for some saved filters that design the filter, see the code which saved_filter requires fs. If the fs is not needed, you need not specify fs (by default None will be assigned to fs). However, if uncertain, you may always pass the sample frequency.
axis (int, optional) – the axis of x to which the filter is applied. Default is -1.
**kwargs (optional) – optional keyword arguments passed on to the saved filter function (in the end these are typically passed on to the function from scipy.signal that performs the actual filtering).
- Returns:
signal_filtered (np.ndarray) – the filtered signal.
- nnsa.preprocessing.filter.remezord(bands, desired, deviations, fs=1)[source]
Estimate the order of the FIR filter as computed with the Remez algorithm.
Inspired by MATLAB’s firpmord function.
- Parameters:
bands (np.ndarray) – a monotonic sequence containing the band edges (including 0 and fs/2 Hz).
desired (np.ndarray) – a sequence the same size of bands containing the desired gain in each of the specified frequencies.
deviations (np.ndarray) – sequence the same size of bands containing the maximum deviations or ripples (in linear units) allowable for each band.
fs (float, optional) – sample frequency. Used for normalization of bands.
- Returns:
numtaps (int) – length of the filter.
weights (np.array) – a relative weighting to give to each band region
nnsa.preprocessing.normalization module
nnsa.preprocessing.resample module
Resampling of a data array.
Functions:
|
Resample the signal x to new sampling frequency fs_new, using polyphase filtering. |
|
Resample the signal data to new sampling frequency fs_new, using 1d interpolation. |
- nnsa.preprocessing.resample.resample_by_filtering(x, fs, fs_new, **kwargs)[source]
Resample the signal x to new sampling frequency fs_new, using polyphase filtering.
Interpolated nans prior to resampling and puts nans back in resampled signal.
- Parameters:
x (np.ndarray) – signal to resample.
fs (flaot) – current sample frequency of x.
fs_new (float) – new sampling frequency to resample to.
**kwargs (optional) – optional keyword arguments for scipy.signal.resample_poly.
- Returns:
(np.ndarray) – the resampled signal.
- nnsa.preprocessing.resample.resample_by_interpolation(x, t, fs_new, **kwargs)[source]
Resample the signal data to new sampling frequency fs_new, using 1d interpolation.
- Parameters:
x (np.ndarray) – signal to resample.
t (np.ndarray) – time array corresponding to x. Must be sorted in an increasing order and have same length as x.
fs_new (float) – new sampling frequency to resample to.
**kwargs (optional) – optional keyword arguments for the scipy.interpolate.interp1d() function.
- Returns:
(np.ndarray) – the resampled signal.
Examples
>>> np.random.seed(0) >>> x = np.random.rand(100) >>> t = np.random.rand(100)*100 # Simulate signal with average sample frequency of approximately 100 Hz. >>> t.sort() >>> resample_by_interpolation(x, t, fs_new=50, kind='quadratic') array([0.5488135 , 0.58892456, 0.62690337, ..., 0.07706016, 0.05019593, 0.02297912])
nnsa.preprocessing.saved_filters module
Module for filtering with saved filters, i.e. filters with known coefficients.
Functions:
|
Filter the signal x with a FIR bandpass filter with a fixed set of filter specifications defined in get_bandpassfir_a_coefs(). |
|
Filter the signal x with the same filter used by Ansari 2019 for 2-class sleep stage classification using a CNN. |
|
Filter the signal x with a saved filter. |
Return the filter coefficients for a FIR bandpass filter with a standard/fixed set of specifications, which are hardcoded in this function. |
|
|
Return a default FIR filter for filtering EEG. |
|
Helper function to get the filter object of a pre-defined bandpass filter. |
|
Load the coefficients of the FIR bandpass filter as computed by MATLAB's designfilt with specifications defined in filter_parameters. |
- nnsa.preprocessing.saved_filters.filter_bandpassfir_a(x, fs, axis=-1, **kwargs)[source]
Filter the signal x with a FIR bandpass filter with a fixed set of filter specifications defined in get_bandpassfir_a_coefs().
- Parameters:
x (np.ndarray) – signal array to be filtered.
fs (float) – sample frequency of x. This is needed in the filter design to compute (or load) the filter coefficients for the given frequency (but maintaining the standard/fixed set of filter specifications).
axis (int, optional) – the axis of x to which the filter is applied. Default is -1.
**kwargs (optional) – optional keyword arguments for the scipy.signal.filtfilt() function.
- Returns:
(np.ndarray) – filtered signal array (has same size as x).
- nnsa.preprocessing.saved_filters.filter_cnn_ansari_2019(x, fs, axis=-1, **kwargs)[source]
Filter the signal x with the same filter used by Ansari 2019 for 2-class sleep stage classification using a CNN.
The sos coefficients are hard-coded and copied from MATLABs output of: bpfilt = designfilt(‘bandpassiir’,…
‘PassbandFrequency1’,1,’PassbandFrequency2’,20, … ‘StopbandFrequency1’,0.01,’StopbandFrequency2’, 27,… ‘PassbandRipple’,1,… ‘StopbandAttenuation1’,40,’StopbandAttenuation2’,40,… ‘SampleRate’,fs);
Note that differences between SciPy’s sosfiltfilt and Matlab’s filtfilt result in differences at the borders of the signal. Fortunately, SciPy’s output looks better than Matlab’s output near the borders.
- Parameters:
x (np.ndarray) – signal array to be filtered.
fs (int) – sampling frequency of x.
axis (int, optional) – the axis of x to which the filter is applied. Default is -1.
**kwargs (optional) – optional keyword arguments for the scipy.signal.sosfiltfilt function.
- Returns:
(np.ndarray) – filtered signal array (has same size as x).
- nnsa.preprocessing.saved_filters.filter_saved_filter(x, filter_name, fs=None, axis=-1, **kwargs)[source]
Filter the signal x with a saved filter.
- Parameters:
x (np.ndarray) – signal to be filtered.
filter_name (str) – string specifying which saved filter to use. See the code for options.
fs (float, optional) – sample frequency of signal to be filtered. Needed for some saved filters that design the filter, see the code which saved_filter requires fs. If the fs is not needed, you need not specify fs. However, if uncertain, you may always pass the sample frequency. Defaults to None.
axis (int, optional) – the axis of x to which the filter is applied. Defaults to -1.
**kwargs (optional) – optional keyword arguments that are passed to the function that does the filtering.
- Returns:
signal_filtered (np.ndarray) – the filtered signal.
- nnsa.preprocessing.saved_filters.get_bandpassfir_a_coefs(fs)[source]
Return the filter coefficients for a FIR bandpass filter with a standard/fixed set of specifications, which are hardcoded in this function.
- Parameters:
fs (float) – sample frequency of x. This is needed in the filter design to compute (or load) the filter coefficients for the given frequency (but maintaining the standard/fixed set of filter specifications).
- Returns:
coefs (np.ndarray) – filter coefficients for the FIR bandpass filter.
- nnsa.preprocessing.saved_filters.get_eeg_fir_filter_a(**kwargs)[source]
Return a default FIR filter for filtering EEG.
- Returns:
fir (nnsa.RemezFIR) – nnsa filter object.
- nnsa.preprocessing.saved_filters.get_filter(which)[source]
Helper function to get the filter object of a pre-defined bandpass filter.
- Returns:
fir (nnsa.FilterBase) – nnsa FilterBase-derived object.
- nnsa.preprocessing.saved_filters.get_matlab_bandpassfir_coefs(filter_parameters)[source]
Load the coefficients of the FIR bandpass filter as computed by MATLAB’s designfilt with specifications defined in filter_parameters. If it cannot find the file to load the coefficients from, it will automatically create this file by calling designfilt in a MATLAB engine. The name of this file contains the filter_parameters.
- Parameters:
filter_parameters (dict) – dictionary containing parameters for MATLAB’s designfilt (see the which items this dictionary must contain).
- Returns:
(np.ndarray) – the coefficients of the filter (the Coefficients field of MATLAB’s designfilt object). Those correspond to the b coefficients (since the a coefficients equal 1 in a FIR filter).
Module contents
Package for filtering (mainly wrapping scipy.signal functions).