WindowingRemover

class WindowingRemover(sfreq: float, line_freqs: int | float | ndarray | list | tuple, notch_width: int | float | ndarray | list | tuple, filter_length: int, low_bias: bool, adaptive: bool, bandwidth: float, p_value: float, verbose: bool = None)[source][source]

Removes windowing artifacts from data.

Parameters:
  • sfreq (float) – The sampling frequency of the data.

  • line_freqs (list of float) – The frequencies of the line noise.

  • notch_width (list of float) – The notch widths for each line frequency.

  • filter_length (int) – The length of the filter to use.

  • low_bias (bool) – Whether to use a low bias filter.

  • adaptive (bool) – Whether to use an adaptive filter.

  • bandwidth (float) – The bandwidth of the multitaper windowing function.

  • p_value (float) – The p-value to use in the F-test.

  • verbose (bool) – Whether to print information.

__call__(x: ndarray) ndarray[source][source]

Remove line frequencies from data using multitaper method.

Parameters:

x (ndarray)

Return type:

ndarray

dpss_windows(N: int, half_nbw: float, Kmax: int, *, sym: bool = True, norm: int | str = None) tuple[ndarray, ndarray][source][source]

Compute Discrete Prolate Spheroidal Sequences.

Will give of orders [0,Kmax-1] for a given frequency-spacing multiple NW and sequence length N.

Note

Copied from NiTime.

Parameters:
  • N (int) – Sequence length.

  • half_nbw (float) – Standardized half bandwidth corresponding to 2 * half_bw = BW*f0 = BW*N/dt but with dt taken as 1.

  • Kmax (int) – Number of DPSS windows to return is Kmax (orders 0 through Kmax-1).

  • sym (bool) – Whether to generate a symmetric window (True, for filter design) or a periodic window (False, for spectral analysis). Default is True.

  • norm (2 | 'approximate' | 'subsample' | None) – Window normalization method. If 'approximate' or 'subsample', windows are normalized by the maximum, and a correction scale-factor for even-length windows is applied either using N**2/(N**2+half_nbw) (“approximate”) or a FFT-based subsample shift (“subsample”). 2 uses the L2 norm. None (the default) uses "approximate" when Kmax=None and 2 otherwise.

Returns:

v, e – The v array contains DPSS windows shaped (Kmax, N). e are the eigenvalues.

Return type:

tuple,

Notes

Tridiagonal form of DPSS calculation (Slepian, 1978)

References

David S. Slepian. Prolate spheroidal wave functions, fourier analysis, and uncertainty-V: the discrete case. Bell System Technical Journal, 57(5):1371–1430, 1978. doi:10.1002/j.1538-7305.1978.tb02104.x.

get_thresh(n_times: int = None) tuple[ndarray, float][source][source]

Get the window function and threshold for given time points.

Parameters:

n_times (int | None) – The number of time points. If None, the filter length will be used.

Returns:

  • window_fun (array, shape=(n_tapers, n_times)) – The window functions for each taper

  • threshold (float) – The threshold for the F-statistic.

Return type:

tuple[ndarray, float]

params(n_times: int) tuple[ndarray, ndarray, bool][source][source]

Triage windowing and multitaper parameters.

Parameters:

n_times (int) – The number of time points.

Returns:

  • window_fun (array, shape=(n_tapers, n_times)) – The window functions for each taper.

  • eigenvals (array, shape=(n_tapers,)) – The eigenvalues for each taper.

  • adaptive (bool) – Whether to use adaptive weights to combine the tapered spectra into PSD

Return type:

tuple[ndarray, ndarray, bool]