Scientific Computing: Time Series Analysis with Python
  • (This page is not constructed yet, however if you are interested in something send me an e-mail: gswelter at gmail dot com )


We make available some tools for statistical analysis of time series written in Python using the numpy and matplotlib libraries for scientific computing.

Consider $X$ to be a time series of $n$ data points. For Simplicity we assume $n$ to be a power of 2 in order to apply Fast Fourier Transform algorithm.


White Noise: whitenoise(n)

$\xi(t)$ is a i.i.d with uncorrelated Gaussian distribution
$\langle\xi(t) \rangle = 0$, $\langle\xi(t)\xi(s) \rangle = \sigma_\xi^2 \delta(t-s)$


import pylab
n = 2**12
x = whitenoise(n)

Wiener Process: wiener(n)

\begin{align} W(t) = \int_{-\infty}^{t}\xi(s)ds \end{align}

Ornstein-Uhlembeck Process: ou(n,mu,sigma,lamb)

Fractional Brownian Motion: fbm(n,H)

Wavelet (Multifractal) Random Cascade: wrc(n,W="ln",mu,sigma2)

Log-normal Cascade

Log-Poisson Cascade

Truncated Lévy Process: tlp(n,a,c)

Cantor: cantor(n,p1)

Binomial Multifractal: bm(n,a)

Mandelbrot Compound Cascade mcc(n,a)

Classical Analysis

Powerspectrum: powerspectrum(x)

import numpy
def powerspectrum(x):
    s = numpy.fft(x)
    return numpy.real(s*numpy.conjugate(s))

Cospectrum: cospectum(x,y)

Quadrature Spectrum: quadspectrum(x,y)

Autocorrelation Function: autocor(x)

$R(\tau) = \langle x(t)x(t+\tau)\rangle_t / \sigma_x^2$
Using the Wiener-Kintchine theorem we can obtain the autocorrelation via FFT

import numpy
def autocor(x):
    s = numpy.fft.fft(x)
    return numpy.real(numpy.fft.ifft(s*numpy.conjugate(s)))/numpy.var(x)
R = autocor(x)

Crosscorrelation Function: crosscor(x,y)

Integral Scale: integralscale(x)

$T = \int_0^{\infty} R(\tau) d \tau$

Fourier Filter


\begin{align} \hat{x} = \mathcal{F} \{x\} = \int_{\mathbb{R}} x(t)e^{-i\omega t} dt \end{align}


\begin{align} x = \mathcal{F}^{-1}\{\hat{x}\} = \frac{1}{2\pi}\int_{\mathbb{R}} \hat{x}(\omega)e^{i\omega t} d\omega \end{align}

be the pair of Fourier Transform of $x$.

High Pass: fourier_hp(x, fc)

A high-pass filter is defined as

\begin{align} x(t)_{<} = \frac{1}{2\pi} \int_{-\infty}^{\omega_c} \hat{x}(\omega)e^{i\omega t} d\omega \end{align}

where $\omega_c$ is angular-frequency cut.

Low Pass: fourier_lp(x, fc)

A low-pass filter is defined as

\begin{align} x(t)_{>} = \frac{1}{2\pi} \int_{\omega_c}^{\infty} \hat{x}(\omega)e^{i\omega t} d\omega \end{align}


Convolution Product via FFT: convolve(x,y)

Plynomial Detrend: detrend(x,p)

Probability Density Estimation (via Kernel Density Estimation): pdf(x ,kernel = "g")

Cumulative Density Estimation (via Kernel Density Estimation): cdf(x, kernel = "g")v

Structure Function: sf(x,q)

\begin{align} S(\tau,q) = \langle (x(t+\tau)-x(t))^q \rangle_t \end{align}

Cumulant Expansion: cumulant(x,nc = 4)

Wavelet Transform

Continuous Wavelet transform

\begin{align} T_\psi[x](a,b) = \int_{-\infty}^{\infty} x(t)\psi(\frac{t-b}{a}) dt \end{align}

Discrete Wavelet Transform

\begin{align} \psi_{j,k}(t) = 2^{-j/2}\psi(2^i t -k) \end{align}
\begin{align} d_{j,k} = \int_{\mathbb{R}} x(t)\psi_{j,k}(t)dt \end{align}

Multiresolution Analysis

Multifractal Analysis

Multifractal Detrended Fluctuation Analysis

Wavelet Leader


  • Random Fourier Phases surr_rfp(x)
  • Iterative Amplitute Adjusted Fourier-Transform surr_iaaft(x)
  • Multifractal surr_mf(x)

Information Measures

Information Entropy (Shannon's Entropy): entropy( x, nbins)

\begin{align} H= -\sum_ {i}p_i\log_2(p_i) \end{align}

Mutual Information Content: mic(x,y, nbins)

Unless otherwise stated, the content of this page is licensed under GNU Free Documentation License.