mne_denoise.dss.variants.narrowband_scan#
- mne_denoise.dss.variants.narrowband_scan(data: ndarray, sfreq: float, *, freq_range: tuple[float, float] = (1, 40), freq_step: float = 1.0, bandwidth: float = 2.0, n_components: int = 1, **dss_kws) tuple[DSS, ndarray, ndarray][source]#
Scan frequencies to find optimal narrowband DSS components.
Sweeps through a frequency range, computing DSS at each frequency. Returns the fitted DSS at the best frequency, along with the full eigenvalue spectrum for visualization.
- Parameters:
data (ndarray, shape (n_channels, n_times) or (n_channels, n_times, n_epochs)) – Input data.
sfreq (float) – Sampling frequency in Hz.
freq_range (tuple of float) – (min_freq, max_freq) range to scan. Default (1, 40).
freq_step (float) – Frequency step size in Hz. Default 1.0.
bandwidth (float) – Bandwidth of bandpass filter at each frequency. Default 2.0.
n_components (int) – Number of DSS components to compute at each frequency. Default 1.
**dss_kws – Additional keyword arguments passed to DSS.
- Returns:
best_dss (DSS) – Fitted DSS at the frequency with highest eigenvalue.
frequencies (ndarray, shape (n_freqs,)) – Frequencies that were scanned.
eigenvalues (ndarray, shape (n_freqs,)) – First eigenvalue at each frequency.
Examples
>>> # Find dominant alpha frequency >>> best_dss, freqs, eigs = narrowband_scan(data, sfreq=250, freq_range=(7, 14)) >>> print(f"Peak alpha at {freqs[np.argmax(eigs)]:.1f} Hz") >>> alpha_sources = best_dss.transform(data)
>>> # Plot eigenvalue spectrum >>> import matplotlib.pyplot as plt >>> plt.plot(freqs, eigs) >>> plt.xlabel("Frequency (Hz)") >>> plt.ylabel("DSS Eigenvalue")