neurodsp.aperiodic.dfa.compute_fluctuations

neurodsp.aperiodic.dfa.compute_fluctuations(sig, fs, n_scales=10, min_scale=0.01, max_scale=1.0, deg=1, method='dfa')[source]

Compute a fluctuation analysis on a signal.

Parameters
sig1d array

Time series.

fsfloat

Sampling rate, in Hz.

n_scalesint, optional, default=10

Number of scales to estimate fluctuations over.

min_scalefloat, optional, default=0.01

Shortest scale to compute over, in seconds.

max_scalefloat, optional, default=1.0

Longest scale to compute over, in seconds.

degint, optional, default=1

Polynomial degree for detrending. Only used for DFA.

  • 1 for regular DFA

  • 2 or higher for generalized DFA

method{‘dfa’, ‘rs’}

Method to use to compute fluctuations:

  • ‘dfa’ : detrended fluctuation

  • ‘rs’ : rescaled range

Returns
t_scales1d array

Time-scales over which fluctuation measures were computed.

fluctuations1d array

Average fluctuation at each scale.

resultfloat

Slope of line in log-log when plotting time scales against fluctuations. This is the alpha value for DFA, or the Hurst exponent for rescaled range.

Notes

These analyses compute fractal properties by analyzing fluctuations across windows.

Overall, these approaches involve dividing the time-series into non-overlapping windows at log-spaced scales and computing a fluctuation measure across windows. The relationship of this fluctuation measure across window sizes provides information on the fractal properties of a signal.

Available measures are:

  • DFA: detrended fluctuation analysis
    • computes ordinary least squares fits across signal windows

  • RS: rescaled range
    • computes the range of signal windows, divided by the standard deviation

Examples

Compute DFA of a simulated pink noise signal:

>>> from neurodsp.sim import sim_powerlaw
>>> sig = sim_powerlaw(n_seconds=10, fs=500, exponent=-1)
>>> t_scales, flucts, dfa_exp = compute_fluctuations(sig, fs=500)

Compute the Hurst exponent of a simulated pink noise signal:

>>> from neurodsp.sim import sim_powerlaw
>>> sig = sim_powerlaw(n_seconds=10, fs=500, exponent=-1)
>>> t_scales, flucts, hurst_exp = compute_fluctuations(sig, fs=500)