Functions

MFDFA

MFDFA.MFDFA.MFDFA(timeseries: numpy.ndarray, lag: numpy.ndarray, order: int = 1, q: numpy.ndarray = 2, stat: bool = False, modified: bool = False, extensions: dict = {'EMD': False, 'eDFA': False, 'window': False}) → Tuple[numpy.array, numpy.ndarray]

Multifractal Detrended Fluctuation Analysis of timeseries. MFDFA generates a fluctuation function F²(q,s), with s the segment size and q the q-powers, Take a timeseries Xₜ, find the integral Yₜ = cumsum(Xₜ), and segment the timeseries into Nₛ segments of size s.

\[F^2(v,s) = \dfrac{1}{s} \sum_{i=1}^s [Y_{(v-1)s + i} - y_{v,i}]^2, ~\mathrm{for}~v=1,2, \dots, N_s,\]

with \(y_{v,i}\) the polynomial fittings of order m. Having obtained the variances of each (detrended) segment, average over s and increase s, to obtain the fluctuation function \(F_q^2(s)\) depending on the segment length.

\[F_q^2(s) = \Bigg\{\dfrac{1}{N_s} \sum_{v=1}^{N_s} [F^2(v,s)]^{q/2}\Bigg\}^{1/q}\]

The fluctuation function \(F_q^2(s)\) can now be plotted in a log-log scale, the slope of the fluctuation function \(F_q^2(s)\) vs the s-segment size is the self-similarity scaling \(h(q)\)

\[F_q^2(s) \sim s^{h(q)}.\]

If \(H ≈ 0\) in a monofractal series, use a second integration step by setting modified = True.

Parameters:
  • timeseries (np.ndarray) – A 1-dimensional timeseries (N, 1). The timeseries of length N.
  • lag (np.ndarray of ints) – An array with the window sizes to calculate (ints). Notice min(lag) > order + 1 given a polynomial fit of order m needs at least m points. The results are meaningless for ‘order = m’ and for lag > size of data / 4 since there is low statistics with < 4 windows to divide the timeseries.
  • order (int (default 1)) – The order of the polynomials to approximate. order = 1 is the DFA1, which is a least-square fit of the data with a first order polynomial (a line), order = 2 is a second-order polynomial, etc.. order = 0 skips the detrending process and hence gives the non-detrended fluctuation functions, i.e., simply Fluctuation Analysis.
  • q (np.ndarray (default 2)) – Fractal exponent to calculate. Array in [-10,10]. The values = 0 will be removed, since the code does not converge there. q = 2 is the standard Detrended Fluctuation Analysis as is set a default.
  • stat (bool (default False)) – Calculates the standard deviation associated with each segment’s averaging.
  • modified (bool (default False)) – For data with the Hurst index ≈ 0, i.e., strongly anticorrelated, a standard MFDFA will result in inacurate results, thus a further integration of the timeseries yields a modified scaling coefficient.
  • extensions (dict) –
    • EMD: list (default False)
      If not None, requires a list of indices of the user-chosen IMFs obtained from an (externally performed) EMD analysis. The indexing starts from 0. Will enforce order = 0 since there is no need for a polynomial detrending.
    • eDFA: bool (default False)
      A method to evaluate the strength of multifractality. Calls function eDFA().
    • window: bool (default False)
      A moving window for smaller timeseries. Set window as int > 0 with the number of steps the window shoud move over the data. window = 1 will move window by 1 step. Since the timeseries is segmented at each lag lenght, any window choise > lag is only segmented once.
Returns:

  • lag (np.ndarray of ints) – Array of lags, realigned, preserving only different lags and with entries > order + 1
  • f (np.ndarray) – A array of shape (size(lag),size(q)) of variances over the indicated lag windows and the indicated q-fractal powers.

References

[Peng1994]C.-K. Peng, S. V. Buldyrev, S. Havlin, M. Simons, H. E. Stanley, and A. L. Goldberger. “Mosaic organization of DNA nucleotides.” Phys. Rev. E, 49(2), 1685–1689, 1994.
[Kantelhardt2002]J. W. Kantelhardt, S. A. Zschiegner, E. Koscielny-Bunde, S. Havlin, A. Bunde, H. E. Stanley. “Multifractal detrended fluctuation analysis of nonstationary time series.” Physica A, 316(1-4), 87–114, 2002.
MFDFA.MFDFA.eDFA(F: numpy.ndarray) → numpy.ndarray

In the reference indicated below a measure of nonstationarity was added by including a subsequent calculation of the extrema of the DFA. Denoted \(dF_q^2(s)\) the difference of the extrema at each segment, i.e.,

\[dF_q^2(s) = \max[F_q^2(s)] - \min[F_q^2(s)]\]
Parameters:F (np.ndarray) – Fluctuation function given by the MFDFA().
Returns:res – Difference of max and min.
Return type:np.ndarray

Notes

New in version 0.3.

References

[Pavlov2020]A. N. Pavlov, A. S. Abdurashitov, A. A. Koronovskii Jr., O. N. Pavlova, O. V. Semyachkina-Glushkovskaya, and J. Kurths. “Detrended fluctuation analysis of cerebrovascular responses to abrupt changes in peripheral arterial pressure in rats.” CNSNS 85, 105232, 2020

Empirical Mode Decomposition for detrending timeseries

MFDFA.emddetrender.detrendedtimeseries(timeseries: numpy.ndarray, modes: list) → numpy.ndarray

The function calculates the Intrinsic Mode Functions (IMFs) of a given timeseries, subtracts the user-chosen IMFs for detrending, and returns the detrended timeseries. Based on based on Dawid Laszuk’s PyEMD found at https://github.com/laszukdawid/PyEMD

Parameters:
  • timeseries (np.ndarray) – A 1-dimensional timeseries of length N.
  • modes (list) – List of integers indicating the indices of the IMFs to be subtracted/detrended from the timeseries.
Returns:

detrendedTimeseries – Detrended 1-dimensional timeseries.

Return type:

np.ndarray

Warning

To use the extension Empirical Mode Decomposition for detrending, the pyEMD library is needed.

pip install EMD-signal

Notes

New in version 0.3.

References

[Huang1998]N. E. Huang, Z. Shen, S. R. Long, M. C. Wu, H. H. Shih, Q. Zheng, N.-C. Yen, C. C. Tung, and H. H. Liu, “The empirical mode decomposition and the Hilbert spectrum for non-linear and non stationary time series analysis”, Proc. Royal Soc. London A, Vol. 454, pp. 903-995, 1998.
[Rilling2003]G. Rilling, P. Flandrin, and P. Goncalves, “On Empirical Mode Decomposition and its algorithms”, IEEE-EURASIP Workshop on Nonlinear Signal and Image Processing NSIP-03, Grado (I), June 2003.
MFDFA.emddetrender.IMFs(timeseries: numpy.ndarray) → numpy.ndarray

Extract the Intrinsic Mode Functions (IMFs) of a given timeseries.

Parameters:timeseries (np.ndarray) – A 1-dimensional timeseries of length N.

Notes

New in version 0.3.

Returns:IMFs – The Intrinsic Mode Functions (IMFs) of the Empirical Mode Decomposition. These are of shape (…, timeseries.size), with the first dimension varying depending on the data. Last entry is the residuals.
Return type:np.ndarray

Fractional Gaussian noise

MFDFA.fgn.fgn(N: int, H: float) → numpy.ndarray

Generates fractional Gaussian noise with a Hurst index H in (0,1). If H = 1/2 this is simply Gaussian noise. The current method employed is the Davies–Harte method, which fails for H ≈ 0. A Cholesky decomposition method and the Hosking’s method will be implemented in later versions.

Parameters:
  • N (int) – Size of fractional Gaussian noise to generate.
  • H (float) – Hurst exponent H in (0,1).
Returns:

f – A array of size N of fractional Gaussian noise with a Hurst index H.

Return type:

np.ndarray