pyrasa.irasa.irasa#
- pyrasa.irasa.irasa(data: ~numpy.ndarray, fs: int, band: tuple[float, float], nperseg: int | None = None, noverlap: int | None = None, nfft: int | None = None, detrend: str | ~collections.abc.Callable | ~typing.Literal[False] = 'constant', scaling: str = 'density', average: str = 'mean', win_func: ~collections.abc.Callable = <function hann>, win_func_kwargs: dict | None = None, dpss_settings_time_bandwidth: float = 2.0, dpss_settings_low_bias: bool = True, dpss_eigenvalue_weighting: bool = True, ch_names: ~numpy.ndarray | None = None, filter_settings: tuple[float | None, float | None] = (None, None), hset_info: tuple[float, float, float] = (1.05, 2.0, 0.05), hset_accuracy: int = 4) IrasaSpectrum [source]#
Computes the aperiodic and periodic components of the power spectrum from a time series using the Irregular Resampling Autocorrelation (IRASA) algorithm.
The IRASA algorithm works by resampling the signal using non-integer factors (h and 1/h), which causes narrowband oscillatory (periodic) peaks to shift in frequency, while leaving the aperiodic structure largely unaffected. By averaging the resulting power spectra across resampling pairs and computing the median across those averages, IRASA suppresses periodic components and isolates the aperiodic spectrum. Subtracting the aperiodic spectrum from the original spectrum recovers the periodic spectrum.
- Parameters:
data (np.ndarray) – Time series data, where the shape is expected to be either (Samples,) or (Channels, Samples).
fs (int) – Sampling frequency of the data in Hz.
band (tuple[float, float]) – The frequency range (lower and upper bounds in Hz) over which to compute the spectra.
nperseg (int | None) – Length of each segment. Defaults to None if window is array_like, is set to the length of the window.
noverlap (int | None) – Number of points to overlap between segments. If None, noverlap = nperseg // 2. Defaults to None.
nfft (int | None) – Length of the FFT used, if a zero padded FFT is desired. If None, the FFT length is nperseg. Defaults to None.
detrend (str | function | False) – Specifies how to detrend each segment. If detrend is a string, it is passed as the type argument to the detrend function. If it is a function, it takes a segment and returns a detrended segment. If detrend is False, no detrending is done. Defaults to ‘constant’.
scaling ('density') – Selects between computing the power spectral density (‘density’) where Pxx has units of V**2/Hz and computing the squared magnitude spectrum (‘spectrum’) where Pxx has units of V**2, if x is measured in V and fs is measured in Hz. Defaults to ‘density’
average (str) – Method to use when averaging periodograms. Defaults to ‘mean’ can also be ‘median’.
ch_names (np.ndarray | None, optional) – Channel names associated with the data, if available. Default is None.
win_func (Callable, optional) – Window function to be used in Welch’s method. Default is
dsp.windows.hann
.win_func_kwargs (dict | None, optional) – Additional keyword arguments for the window function. Default is None.
dpss_settings_time_bandwidth (float, optional) – Time-bandwidth product for the DPSS windows if used. Default is 2.0.
dpss_settings_low_bias (bool, optional) – Keep only tapers with eigenvalues > 0.9. Default is True.
dpss_eigenvalue_weighting (bool, optional) – Whether or not to apply eigenvalue weighting in DPSS. If True, spectral estimates weighted by the concentration ratio of their respective tapers before combining. Default is True.
filter_settings (tuple[float | None, float | None], optional) – Cutoff frequencies for highpass and lowpass filtering to avoid artifacts in the evaluated frequency range. Default is (None, None).
hset_info (tuple[float, float, float], optional) – Tuple specifying the range of the resampling factors as (min, max, step). Default is (1.05, 2.0, 0.05).
hset_accuracy (int, optional) – Decimal precision for the resampling factors. Default is 4.
- Returns:
- An object containing the following attributes:
- freqs: np.ndarray
Frequencies corresponding to the computed spectra.
- raw_spectrum: np.ndarray
The raw power spectrum.
- aperiodic: np.ndarray
The aperiodic (fractal) component of the spectrum.
- periodic: np.ndarray
The periodic (oscillatory) component of the spectrum.
- ch_names: np.ndarray
Channel names if provided.
- Return type:
IrasaSpectrum
Notes
This function provides fine-grained control over the IRASA parameters. For users working with MNE-Python, the irasa_raw and irasa_epochs functions from
pyrasa.irasa_mne
are recommended, as they handle additional preprocessing steps.References
Wen, H., & Liu, Z. (2016). Separating Fractal and Oscillatory Components in the Power Spectrum of Neurophysiological Signal. Brain Topography, 29(1), 13–26. https://doi.org/10.1007/s10548-015-0448-0