preprocessing#

syncopy.preprocessing(data, filter_class='but', filter_type='lp', freq=None, order=None, direction='twopass', window='hamming', polyremoval=None, zscore=False, rectify=False, hilbert=False, parallel=None, select=None, **kwargs)[source]#

Preprocessing of time continuous raw data with IIR and FIR filters

The parameters listed below can be provided as is or a via a cfg configuration ‘structure’, see Notes for details.

Parameters:
  • data (~syncopy.AnalogData) – A non-empty Syncopy AnalogData object

  • filter_class ({'but', 'firws'} or None) – Butterworth (IIR) or windowed sinc (FIR) Set to None to disable filtering altogether

  • filter_type ({'lp', 'hp', 'bp', 'bs'}, optional) – Select type of filter, either low-pass ‘lp’, high-pass ‘hp’, band-pass ‘bp’ or band-stop (Notch) ‘bs’.

  • freq (float or array_like) – Cut-off frequency for low- and high-pass filters or sequence of two frequencies for band-stop and band-pass filter.

  • order (int, optional) – Order of the filter, default is 4 for filter_class=’but’ and 1000 for filter_class=’firws’. Higher orders yield a sharper transition width or less ‘roll off’ of the filter, but are more computationally expensive.

  • direction ({'twopass', 'onepass', 'onepass-minphase'}) – Filter direction: ‘twopass’ - zero-phase forward and reverse filter, IIR and FIR ‘onepass’ - forward filter, introduces group delays for IIR, zerophase for FIR `’onepass-minphase’ - forward causal/minimum phase filter, FIR only

  • window ({"hamming", "hann", "blackman"}, optional) – The type of window to use for the FIR filter

  • polyremoval (int or None, optional) – Order of polynomial used for de-trending data in the time domain prior to filtering. A value of 0 corresponds to subtracting the mean (“de-meaning”), polyremoval = 1 removes linear trends (subtracting the least squares fit of a linear polynomial).

  • zscore (bool, optional) – Set to True to individually standardize all signals

  • rectify (bool, optional) – Set to True to rectify (after filtering)

  • hilbert (None or one of {'abs', 'complex', 'real', 'imag', 'absreal', 'absimag', 'angle'}) – Choose one of the supported output types to perform Hilbert transformation after filtering. Set to ‘angle’ to return the phase.

  • parallel (None or bool) – If None (recommended), processing is automatically performed in parallel (i.e., concurrently across trials/channel-groups), provided a dask parallel processing client is running and available. Parallel processing can be manually disabled by setting parallel to False. If parallel is True but no parallel processing client is running, computing will be performed sequentially.

  • select (dict or StructDict or str) – In-place selection of subset of input data for processing. Please refer to syncopy.selectdata() for further usage details.

Returns:

filtered – The filtered dataset with the same shape and dimord as the input data

Return type:

~syncopy.AnalogData

Examples

In the following adata is an instance of AnalogData

Low-pass filtering with a Butterworth filter and a cut-off of 100Hz:

>>> spy.preprocessing(adata, filter_class='but', filter_type='lp', freq=100)

Notch (band-stop) filtering with a FIR filter of order 2000 around 50Hz:

>>> spy.preprocessing(adata, filter_class='firws', filter_type='bs', freq=[49, 51], order=2000)

Remove linear trends and standardize but no filtering:

>>> spy.preprocessing(adata, filter_class=None, polyremoval=1, zscore=True)