antropy.hjorth_params#
- antropy.hjorth_params(x, sf=None, axis=-1)[source]#
Calculate Hjorth mobility and complexity on given axis.
Added in version 0.1.3.
- Parameters:
- xlist or np.array
1D or N-D data.
- sffloat or None
Sampling frequency in Hz. If provided, mobility is returned in Hz instead of samples⁻¹. Default is None (mobility in samples⁻¹).
- axisint
The axis along which to perform the computation. Default is -1 (last).
- Returns:
- mobility, complexityfloat
Mobility and complexity parameters. Mobility is in samples⁻¹ when
sfis None, or in Hz whensfis provided. Complexity is dimensionless in both cases.
Notes
Hjorth Parameters are indicators of statistical properties used in signal processing in the time domain introduced by Bo Hjorth in 1970. The parameters are activity, mobility, and complexity. AntroPy only returns the mobility and complexity parameters, since activity is simply the variance of \(x\), which can be computed easily with
numpy.var().The mobility parameter represents the mean frequency or the proportion of standard deviation of the power spectrum. This is defined as the square root of variance of the first derivative of \(x\) divided by the variance of \(x\).
The complexity gives an estimate of the bandwidth of the signal, which indicates the similarity of the shape of the signal to a pure sine wave (where the value converges to 1). Complexity is defined as the ratio of the mobility of the first derivative of \(x\) to the mobility of \(x\).
Note
Without a sampling frequency, mobility is expressed in units of samples⁻¹. Pass
sfto convert to Hz (multiplies mobility bysf). Complexity is unaffected because it is a ratio of two mobilities.References
Examples
Hjorth parameters of a pure sine (mobility in samples⁻¹)
>>> import numpy as np >>> import antropy as ant >>> sf, f, dur = 100, 1, 4 >>> N = sf * dur # Total number of discrete samples >>> t = np.arange(N) / sf # Time vector >>> x = np.sin(2 * np.pi * f * t) >>> np.round(ant.hjorth_params(x), 4) array([0.0627, 1.005 ])
Same signal with sf provided: mobility is now in Hz
>>> np.round(ant.hjorth_params(x, sf=sf), 4) array([6.2736, 1.005 ])
Random 2D data
>>> np.random.seed(42) >>> x = np.random.normal(size=(4, 3000)) >>> mob, com = ant.hjorth_params(x) >>> print(mob) [1.42145064 1.4339572 1.42186993 1.40587512]
>>> print(com) [1.21877527 1.21092261 1.217278 1.22623163]
Fractional Gaussian noise with H = 0.5
>>> import stochastic.processes.noise as sn >>> rng = np.random.default_rng(seed=42) >>> x = sn.FractionalGaussianNoise(hurst=0.5, rng=rng).sample(10000) >>> np.round(ant.hjorth_params(x), 4) array([1.4073, 1.2283])
Fractional Gaussian noise with H = 0.9
>>> rng = np.random.default_rng(seed=42) >>> x = sn.FractionalGaussianNoise(hurst=0.9, rng=rng).sample(10000) >>> np.round(ant.hjorth_params(x), 4) array([0.8395, 1.9143])
Fractional Gaussian noise with H = 0.1
>>> rng = np.random.default_rng(seed=42) >>> x = sn.FractionalGaussianNoise(hurst=0.1, rng=rng).sample(10000) >>> np.round(ant.hjorth_params(x), 4) array([1.6917, 1.0717])