msqms.libs.pyprep.removeTrend module

msqms.libs.pyprep.removeTrend module#

High-pass filter and locally detrend the EEG signal.

Summary#

Functions:#

removeTrend

Remove trends (i.e., slow drifts in baseline) from an array of EEG data.

runline

Perform local linear regression on a channel of EEG data.

Reference#

msqms.libs.pyprep.removeTrend.removeTrend(EEG, sample_rate, detrendType='high pass', detrendCutoff=1.0, detrendChannels=None, matlab_strict=False)[source]#

Remove trends (i.e., slow drifts in baseline) from an array of EEG data.

Parameters:
  • EEG (np.ndarray) – A 2-D array of EEG data to detrend.

  • sample_rate (float) – The sample rate (in Hz) of the input EEG data.

  • detrendType (str, optional) – Type of detrending to be performed: must be one of ‘high pass’, ‘high pass sinc, or ‘local detrend’. Defaults to ‘high pass’.

  • detrendCutoff (float, optional) – The high-pass cutoff frequency (in Hz) to use for detrending. Defaults to 1.0 Hz.

  • detrendChannels ({list, None}, optional) – List of the indices of all channels that require detrending/filtering. If None, all channels are used (default).

  • matlab_strict (bool, optional) – Whether or not detrending should strictly follow MATLAB PREP’s internal math, ignoring any improvements made in PyPREP over the original code (see matlab-diffs for more details). Defaults to False.

Returns:

EEG – A 2-D array containing the filtered/detrended EEG data.

Return type:

np.ndarray

Notes

High-pass filtering is implemented using the MNE filter function :func:mne.filter.filter_data unless matlab_strict is True, in which case it is performed using a minimal re-implementation of EEGLAB’s pop_eegfiltnew. Local detrending is performed using a Python re-implementation of the runline function from the Chronux package for MATLAB [1]_.

References

msqms.libs.pyprep.removeTrend.runline(y, n, dn)[source]#

Perform local linear regression on a channel of EEG data.

A re-implementation of the runline function from the Chronux package for MATLAB [1]_.

Parameters:
  • y (np.ndarray) – A 1-D array of data from a single EEG channel.

  • n (int) – Length of the detrending window.

  • dn (int) – Length of the window step size.

Returns:

y – The detrended signal for the given EEG channel.

Return type:

np.ndarray

References