extractors.iGAIT¶
Module: extractors.iGAIT
¶
This program implements some of the feature extraction equations from:
“iGAIT: An interactive accelerometer based gait analysis system” Mingjing Yang, Huiru Zheng, Haiying Wang, Sally McClean, Dave Newell. 2012. Computer methods and programs in biomedicine 108:715-723. DOI:10.1016/j.cmpb.2012.04.004 http://www.ncbi.nlm.nih.gov/pubmed/22575802
- iGAIT inputs ::
- sample rate
- distance (not included here)
- threshold (anterior-posterior acceleration, to detect heel contact)
iGait was written as a Matlab file and compiled as a Windows application.
- Features ::
cadence (step/min)
distance-related (not included here): velocity, mean step length
RMS (each direction)
integral of the power spectral density (PSD, each direction)
main frequency: frequency with the maximum value of PSD
frequency of cumulated IPSD at 50/75/90/99% energy (each direction)
- autocorrelation coefficients-derived:
- symmetry (vertical and anterior-posterior directions)
- regularity of stride/step (each direction)
- Authors:
- Arno Klein, 2015 (arno@sagebase.org) http://binarybottle.com
Copyright 2015, Sage Bionetworks (http://sagebase.org), Apache v2.0 License
Functions¶
-
mhealthx.extractors.iGAIT.
autocorrelation
(data, unbiased=True, normalized=True)¶ Compute the autocorrelation coefficients for time series data.
From Yang, et al., 2012:
“The autocorrelation coefficient refers to the correlation of a time series with its own past or future values. iGAIT uses unbiased autocorrelation coefficients of acceleration data to scale the regularity and symmetry of gait [30]. The unbiased estimate of autocorrelation coefficients of acceleration data can be calculated by Eq. (5)
fc(t) = 1/(N-|t|) * SUM[i=1:N-|t|](xi * x_i+t)
where xi (i=1,2,...,N) is the acceleration data, fc(t) are autocorrelation coefficients, t is the time lag (t=-N,-N+1,...,0,1,2,...,N).
When the time lag t is equal to the periodicity of the acceleration xi, a peak will be found in the fc(t) series. The autocorrelation coefficients are divided by fc(0) in Eq. (6), so that the autocorrelation coefficient is equal to 1 when t=0
NFC(t) = fc(t) / fc(0)
Here NFC(t) is the normalised autocorrelation coefficient, and fc(t) are autocorrelation coefficients.”
- data : numpy array
- time series data
- unbiased : Boolean
- compute unbiased autocorrelation?
- normalized : Boolean
- compute normalized autocorrelation?
- coefficients : numpy array
- [normalized, unbiased] autocorrelation coefficients
>>> import numpy as np >>> from mhealthx.extractors.iGAIT import autocorrelation >>> data = np.random.random(100) >>> unbiased = True >>> normalized = True >>> coefficients = autocorrelation(data, unbiased, normalized)
From “Efficient computation of autocorrelations; demonstration in MatLab and Python” (Dec. 29, 2013) by Jesper Toft Kristensen: http://jespertoftkristensen.com/JTK/Blog/Entries/2013/12/29_Efficient_ computation_of_autocorrelations%3B_demonstration_in_MatLab_and_Python.html
-
mhealthx.extractors.iGAIT.
gait
(x, y, z, t, sample_rate, duration, threshold=0.2, order=4, cutoff=5)¶ Estimate various gait measures from time series (accelerometer) data.
From Yang, et al., 2012:
Re: heel strikes: “The heel contacts are detected by peaks preceding the sign change of AP acceleration [3]. In order to automatically detect a heel contact event, firstly, the AP acceleration is low pass filtered by the 4th order zero lag Butterworth filter whose cut frequency is set to 5 Hz. After that, transitional positions where AP acceleration changes from positive to negative can be identified. Finally the peaks of AP acceleration preceding the transitional positions, and greater than the product of a threshold and the maximum value of the AP acceleration are denoted as heel contact events... This threshold is defined as the ratio to the maximum value of the AP acceleration, for example 0.5 indicates the threshold is set at 50% of the maximum AP acceleration. Its default value is set to 0.4 as determined experimentally in this paper, where this value allowed correct detection of all gait events in control subjects. However, when a more irregular pattern is analysed, the threshold should be less than 0.4. The user can test different threshold values and find the best one according to the gait event detection results.”
- x : list
- x-axis accelerometer data
- y : list
- y-axis accelerometer data
- z : list
- z-axis accelerometer data
- t : list
- time points for accelerometer data
- sample_rate : float
- sample rate of accelerometer reading (Hz)
- duration : float
- duration of accelerometer reading (s)
- threshold : float
- ratio to the maximum value of the anterior-posterior acceleration
- order : integer
- order of the Butterworth filter
- cutoff : integer
- cutoff frequency of the Butterworth filter (Hz)
- heel_strikes : numpy array
- heel strike timings
- number_of_steps : integer
- estimated number of steps based on heel strikes
- cadence : float
- number of steps divided by duration
- step_durations : numpy array
- step durations
- avg_step_duration : float
- average step duration
- sd_step_durations : float
- standard deviation of step durations
- strides : list of two lists of floats
- stride timings for each side
- avg_number_of_strides : float
- estimated number of strides based on alternating heel strikes
- stride_durations : list of two lists of floats
- estimated stride durations
- avg_stride_duration : float
- average stride duration
- sd_step_durations : float
- standard deviation of stride durations
- step_regularity_x : float
- measure of step regularity in x-axis
- step_regularity_y : float
- measure of step regularity in y-axis
- step_regularity_z : float
- measure of step regularity in z-axis
- stride_regularity_x : float
- measure of stride regularity in x-axis
- stride_regularity_y : float
- measure of stride regularity in y-axis
- stride_regularity_z : float
- measure of stride regularity in z-axis
- symmetry_x : float
- measure of gait symmetry in x-axis
- symmetry_y : float
- measure of gait symmetry in y-axis
- symmetry_z : float
- measure of gait symmetry in z-axis
>>> from mhealthx.xio import read_accel_json, compute_sample_rate >>> input_file = '/Users/arno/DriveWork/mhealthx/mpower_sample_data/accel_walking_outbound.json.items-6dc4a144-55c3-4e6d-982c-19c7a701ca243282023468470322798.tmp' >>> x, y, z, t, sample_rate, duration = read_accel_json(input_file) >>> from mhealthx.extractors.iGAIT import gait >>> threshold = 0.2 >>> order = 4 >>> cutoff = 5 >>> data = y >>> a = gait(x, y, z, t, sample_rate, duration, threshold, order, cutoff)
-
mhealthx.extractors.iGAIT.
gait_regularity_symmetry
(x, y, z, step_period, stride_period)¶ Compute step and stride regularity and symmetry from accelerometer data.
From Yang, et al., 2012:
“The peak value a1 = NFC(t1), which is found at the t1 lag time to be a step period, indicates the step regularity in a direction. The peak value a2 = NFC(t2), which was found at the t2 lag time to be a stride period, indicates the stride regularity in a direction. The variance of the stride regularity and step regularity D = |a2 - a1, can be used as an indicator to measure gait asymmetry. A smaller value of D indicates a more symmetric gait. A larger value of D indicates a more asymmetric gait. In total, iGAIT extracts seven regularity and symmetry features from the acceleration data, namely
- Step regularity: vertical (VT), anterior-posterior (AP) directions - Stride regularity: VT, AP, medial-lateral (ML) directions - Symmetry: VT, AP directions
- x : list
- x-axis accelerometer data
- y : list
- y-axis accelerometer data
- z : list
- z-axis accelerometer data
- step_period : integer
- step period
- stride_period : integer
- stride period
- step_regularity_x : float
- step regularity measure in medial-lateral direction
- step_regularity_y : float
- step regularity measure in anterior-posterior direction
- step_regularity_z : float
- step regularity measure in vertical direction
- stride_regularity_x : float
- stride regularity measure in medial-lateral direction
- stride_regularity_y : float
- stride regularity measure in anterior-posterior direction
- stride_regularity_z : float
- stride regularity measure in vertical direction
- symmetry_x : float
- symmetry measure in medial-lateral direction
- symmetry_y : float
- symmetry measure in anterior-posterior direction
- symmetry_z : float
- symmetry measure in vertical direction
>>> from mhealthx.xio import read_accel_json >>> from mhealthx.extractors.iGAIT import gait_regularity_symmetry >>> input_file = '/Users/arno/DriveWork/mhealthx/mpower_sample_data/accel_walking_outbound.json.items-6dc4a144-55c3-4e6d-982c-19c7a701ca243282023468470322798.tmp' >>> x, y, z, t, sample_rate, duration = read_accel_json(input_file) >>> step_period = 2 >>> stride_period = 1 >>> a = gait_regularity_symmetry(x, y, z, step_period, stride_period)
-
mhealthx.extractors.iGAIT.
rms
(data)¶ The root mean square of acceleration indicates the intensity of motion. The RMS values of the three acceleration directions (VT, AP and ML) are calculated as: RMS_d = sqrt( (sum[i=0:N-1](xdi - [xd])^2 / N) ) where xdi (i = 1,2,...,N; d = VT,AP,ML) is the acceleration in either the VT, AP or ML axis, N is the length of the acceleration signal, [xd] is the mean value of acceleration in any axis.