IMU¶
Functions for processing inertial measurement unit (IMU) data, including orientation kinematics, tilt estimation, and step detection.
Kinematics¶
- biomechzoo.imu.tilt_algorithm.tilt_algorithm_data(data, ch_vert, ch_medlat, ch_antpost, plot_or_not=None)[source]¶
Apply the tilt correction algorithm to the vertical, mediolateral, and anteroposterior channels of zoo data.
- Parameters:
data (dict) – Zoo file data dictionary.
ch_vert (str) – Name of the vertical acceleration channel.
ch_medlat (str) – Name of the mediolateral acceleration channel.
ch_antpost (str) – Name of the anteroposterior acceleration channel.
plot_or_not (bool, optional) – Unused. Reserved for future plotting support.
- Returns:
data (dict) – Zoo file data dictionary with the tilt-corrected channels (
<channel>_tilt_corr) added.- Parameters:
- Return type:
- biomechzoo.imu.tilt_algorithm.tilt_algorithm_line(avert, amedlat, aantpost)[source]¶
Account for gravity and improper tilt alignment of a tri-axial trunk accelerometer.
Step 1: Extract raw measured (mean) accelerations Step 2: Calculate tilt angles Step 3: Calculate horizontal dynamic accelerations vectors Step 4: Calculate estimated provisional vertical vector Step 5: Calculate vertical dynamic vector step 6.1: Calculate the contribution of static components step 6.2 Transpose static component matrices step 7: Remove the static components from the templates of pre and post
- Parameters:
avert (array_like) – Data predominantly in vertical direction. Expressed in g’s.
amedlat (array_like) – Data predominantly in medio-lateral direction. Expressed in g’s.
aantpost (array_like) – Data predominantly in anterior-posterior direction. Expressed in g’s.
- Returns:
df_corrected (pandas.DataFrame) – The tilt corrected and gravity subtracted vertical, medio-lateral, and anterior-posterior acceleration signals (n x 3).
avert2 (ndarray) – The tilt corrected acceleration data in vertical direction.
amedlat2 (ndarray) – The tilt corrected acceleration data in medio-lateral direction.
aantpost2 (ndarray) – The tilt corrected acceleration data in anterior-posterior direction.
- Parameters:
avert (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes])
amedlat (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes])
aantpost (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes])
- Return type:
Notes
If average acceleration is above 5m/s^2, the signal will be corrected.
Step Detection¶
- biomechzoo.imu.step_detection.imu_kielmat(vertical_acceleration, fsamp)[source]¶
Detect foot-strike and foot-off events using KielMAT.
- Parameters:
vertical_acceleration (ndarray) – One-dimensional vertical acceleration signal in m/s/s.
fsamp (float) – Sampling frequency in Hz.
- Returns:
fs (ndarray) – Foot-strike frame indices.
fo (ndarray) – Foot-off frame indices.
- Raises:
ValueError – If the acceleration signal is not one-dimensional, contains non-finite values, or if the sampling frequency is invalid.
- Parameters:
- Return type:
Tuple[ndarray[Any, dtype[int64]], ndarray[Any, dtype[int64]]]
- biomechzoo.imu.step_detection.imu_mcgrath(ch_line, fsamp, min_stance_t, is_filtered=False)[source]¶
Detect gait events using the method of McGrath et al. (2012).
The first minimum after a local maximum midswing peak is taken as initial contact (heel strike); the first valid minimum before a midswing peak is taken as terminal contact (toe off). Reference: https://doi.org/10.1007/s12283-012-0093-8
- Parameters:
ch_line (array_like) – Vertical acceleration signal.
fsamp (float) – Sampling frequency in Hz.
min_stance_t (float) – Minimum stance time, in milliseconds, used to validate detected steps.
is_filtered (bool, optional) – If True,
ch_lineis assumed to already be filtered and no additional low-pass filtering is applied. Default is False.
- Returns:
IC (ndarray) – Indices of detected initial contact (heel strike) events.
TC (ndarray) – Indices of detected terminal contact (toe off) events.
- Parameters:
- Return type:
- biomechzoo.imu.step_detection.crash_catch(min_stance_samples, IC, TC)[source]¶
Ensure initial and terminal contact index arrays are the same length, truncating any extra detections.
- Parameters:
min_stance_samples (int) – Unused. Reserved for future stance-time validation.
IC (list of int) – Indices of detected initial contact events.
TC (list of int) – Indices of detected terminal contact events.
- Returns:
IC (ndarray) – Initial contact indices, truncated to match
TClength.TC (ndarray) – Terminal contact indices, truncated to match
IClength.
- Parameters:
- Return type: