line_filter

line_filter(raw: BaseRaw | BaseEpochs | Evoked, fs: float = None, freqs: int | float | ndarray | list | tuple = 60.0, filter_length: str = '10s', notch_widths: int | float | ndarray | list | tuple = 10.0, mt_bandwidth: float = None, p_value: float = 0.05, picks: list[int | str] = None, n_jobs: int = None, adaptive: bool = True, low_bias: bool = True, copy: bool = True, *, verbose: int | bool | str = None) BaseRaw | BaseEpochs | Evoked[source][source]

Apply a multitaper line noise notch filter for the signal instance.

Applies a multitaper power line noise notch filter to the signal, operating on the last dimension. Uses the F-test to find significant sinusoidal components to remove. This is done by fitting a sinusoid to the power spectrum at each time point and frequency, and testing whether the resulting fit is significantly different from a flat spectrum. The significance test is done using an F-test, which requires fitting two models (one flat, one sinusoidal) at each time point and frequency. The F-test is corrected for multiple comparisons using the Benjamini-Hochberg procedure.

Parameters:
  • raw (mt_utils.Signal) – Signal to filter.

  • fs (float, optional) – Sampling rate in Hz. Default is taken from the raw object.

  • freqs (float | array-like of float, optional) – Frequencies to notch filter in Hz, e.g. np.arange(60, 241, 60). None can only be used with the mode ‘spectrum_fit’, where an F test is used to find sinusoidal components.

  • filter_length (str | int, optional) – Length of the filter to use. If str, assumed to be human-readable time in units of “s” or “ms” (e.g., “10s” or “5500ms”). If an int, it is assumed to be in samples and used directly.

  • notch_widths (float | array of float, optional) – Width of the stop band (centred at each freq in freqs) in Hz. Default is 10.

  • mt_bandwidth (float, optional) – The bandwidth of the multitaper windowing function in Hz. Default will set the half frequency bathwidth to 4 Hz.

  • p_value (float, optional) – P-value to use in F-test thresholding to determine significant sinusoidal components to remove. Note that this will be Bonferroni corrected for the number of frequencies, so large p-values may be justified.

  • picks (str | array-like | slice | None) – Channels to include. Slices and lists of integers will be interpreted as channel indices. In lists, channel type strings (e.g., ['meg', 'eeg']) will pick channels of those types, channel name strings (e.g., ['MEG0111', 'MEG2623'] will pick the given channels. Can also be the string values 'all' to pick all channels, or 'data' to pick data channels. None (default) will pick all channels. Note that channels in info['bads'] will be included if their names or indices are explicitly provided.

  • n_jobs (int | None) – The number of jobs to run in parallel. If -1, it is set to the number of CPU cores. Requires the joblib package. None (default) is a marker for ‘unset’ that will be interpreted as n_jobs=1 (sequential execution) unless the call is performed under a joblib.parallel_config context manager that sets another value for n_jobs.

  • adaptive (bool, optional) – Use adaptive weights to combine the tapered spectra into PSD. Default is True.

  • low_bias (bool, optional) – Only use tapers with more than 90 percent spectral concentration within bandwidth. Default is True.

  • copy (bool, optional) – If True, a copy of x, filtered, is returned. Otherwise, it operates on x in place.

  • verbose (bool | str | int | None) – Control verbosity of the logging output. If None, use the default verbosity level. See the logging documentation and mne.verbose() for details. Should only be passed as a keyword argument.

Returns:

filt – The signal instance with the filtered data.

Return type:

mt_utils.Signal

Notes

The frequency response is (approximately) given by

1-|----------         -----------
  |          \       /
  |           \     /
  |            \   /
  |             \ /
0-|              -
  |         |    |    |         |
  0        Fp1 freq  Fp2       Nyq

For each freq in freqs, where Fp1 = freq - trans_bandwidth / 2 and Fs2 = freq + trans_bandwidth / 2.

References

Multi-taper removal is inspired by code from the Chronux toolbox, see www.chronux.org and the book “Observed Brain Dynamics” by Partha Mitra & Hemant Bokil, Oxford University Press, New York, 2008. Please cite this in publications if this function is used.

Examples

>>> import mne
>>> from bids import BIDSLayout
>>> from ieeg.io import raw_from_layout
>>> bids_root = mne.datasets.epilepsy_ecog.data_path(verbose=False)
>>> layout = BIDSLayout(bids_root)
>>> raw = raw_from_layout(layout, subject="pt1", preload=True,
... extension=".vhdr", verbose=False)
Reading 0 ... 269079  =      0.000 ...   269.079 secs...
>>> mne.set_log_level("WARNING")
>>> filt = line_filter(raw, freqs=[60, 120, 180])
>>> mne.set_log_level("INFO")

Examples using ieeg.mt_filter.line_filter

Line noise filtering script

Line noise filtering script

PCA-LDA Decoding

PCA-LDA Decoding