Blog
Back to articles

Pedaling kinetics: Conversion and filtering on OpenSim

Introduction

This project stems from the need to integrate motion data acquired through inertial sensors into the OpenSim biomechanical simulation environment, with the goal of achieving a reliable reconstruction of the pedaling motion. In the early stages of the work, no consolidated operational protocols or standardized procedures were available for data conversion and processing, making it necessary to develop a dedicated workflow.

The first import attempts revealed significant issues related to the incompatibility between the format of the acquired data and the structural requirements demanded by OpenSim. In particular, the misalignment between the reference systems used by the sensors and the one adopted by the simulation software resulted in an incorrect spatial configuration of the biomechanical model, compromising the correct reproduction of the cyclist's posture on the bicycle.

At the same time, anomalies in the reading and interpretation of the raw data generated discontinuous movements lacking the necessary kinematic coherence, limiting the possibility of performing reliable biomechanical analyses.

In light of these issues, the project focused on defining a processing pipeline capable of converting, correcting, and optimizing the acquired data, ensuring compatibility with OpenSim and the quality of subsequent motion analyses.

Objective

The activity carried out had the general goal of creating a reliable procedure for importing and analyzing kinematic data within OpenSim, applied to the study of the pedaling motion. To this end, the work focused on achieving three specific objectives.

First, a customized scaling procedure for the biomechanical model was developed, aimed at accurately reproducing the anthropometric characteristics of the analyzed subject, overcoming the use of generic models and allowing a more realistic representation of the cyclist's body configuration.

Next, the problem of misalignment between the sensors' reference systems and OpenSim's was addressed, through the definition of a spatial correction and alignment strategy that would allow the correct reconstruction of the riding position within the virtual environment.

Finally, signal processing techniques were implemented to reduce the noise present in the instrumental acquisitions and to minimize kinematic discontinuities. The final goal of this phase was to obtain a smooth and biomechanically coherent animation, free of artifacts, suitable for subsequent quantitative motion analyses.

Project Development

a. MATLAB Script for File Conversion

Development of the .mvn to .mot Algorithm

To overcome the incompatibility of the native files generated by inertial Motion Capture systems and enable the animation of the virtual skeleton, a MATLAB script originally developed for converting Xsens kinematic data into .mot files compatible with OpenSim was used and adapted. This script acts as a genuine technological bridge, automating the translation of raw kinematic data (.mvn or .mvnx format exported from the Xsens software) into the native format required by the OpenSim simulation environment (motion files with a .mot extension).

The primary goal of the algorithm is to mathematically convert and map the angles defined in the Xsens software so that they are consistent with the degrees of freedom and geometric conventions of OpenSim's musculoskeletal models.

Structural and Geometric Analysis of the Formats

The need to develop a dedicated converter lies in the deep structural and physical differences between the two file formats:

Logical Phases of Script Processing

To successfully convert the movement and populate its structure, the algorithm follows a logical sequence divided into three macro-operations:

Through conditional logic (if-elseif strcmp), the signs vector (initially composed only of 1 values) is modified by inserting a -1 value at the critical indices, in order to surgically invert the kinematic polarity based on the selected OpenSim model:

The final mathematical operation translates into an element-by-element multiplication (MATLAB's .* matrix operator) between the sign vector and the global motion matrix, to which the time column, converted into seconds, is subsequently appended:

Angles_Matrix = signs .* (Angles_Matrix)

The final .mot file is then physically written by printing, row by row, the strict text header, making the data ready, clean, and digestible for OpenSim's inverse kinematics solver.

b. Signal Analysis and Filtering

After converting the file from the native .mvn format to .mot following the described procedure, the motion data was filtered using a MATLAB script. Before proceeding with filtering, a study of the signal in the frequency domain was carried out: by applying the Fast Fourier Transform (FFT) to a kinematic component, the harmonic components of the pedaling motion were identified in order to isolate them from the background noise.

As can be seen from the graph, at very low frequencies there is a high-amplitude peak. This peak represents the DC component (the average offset of the signal over time), which, in our specific setup, holds the fundamental biomechanical information about the subject's initial reclined geometric position.

During the data conversion for OpenSim, a further problem was encountered: a visual artifact consisting of an instantaneous 360° rotation of the model. This phenomenon is related to the wrapping of the Euler angles, whose values are mathematically bounded within the [-180°, +180°] range, generating artificial discontinuities when the actual movement exceeds this threshold. To resolve this numerical error, the unwrap function was applied to the kinematic signal before importing it into OpenSim. The algorithm identified the jumps near ±180° and algebraically added multiples of 360° (2π rad) to them. This intervention removed the fictitious angular velocity spikes, ensuring trajectory continuity and a coherent simulation.

Regarding data cleaning, a low-pass filter was preferred over a band-pass filter. Voluntary human body movements are in fact low-frequency phenomena, whose informative content is generally below 6-10 Hz, while measurement noise is concentrated at high frequencies; the low-pass filter therefore allows the disturbance to be eliminated while preserving the useful signal. The choice of a band-pass filter was discarded because introducing a lower cutoff frequency would have eliminated precisely the very low frequencies, zeroing out the initial postural offset and compromising the subsequent inverse dynamics calculations in OpenSim.

Critical Issues

The critical issues encountered were as follows:

Conclusions and Future Developments

Through the work carried out, it was possible to obtain a stable biomechanical animation consistent with the real pedaling motion, a smoother and more realistic model movement within OpenSim, improving both animation quality and the robustness of subsequent analyses.

Looking ahead, the workflow could be further improved by automating the conversion and filtering procedures, making the pipeline faster, standardized, and easily replicable for different acquisitions.

The availability of reliable kinematic data in OpenSim also paves the way for advanced biomechanical analyses, such as Inverse Dynamics, muscle force estimation via Static Optimization, joint load analysis, and the study of posture's influence on cyclist performance. These tools could support the ergonomic optimization of the vehicle and future design activities integrated with multidisciplinary simulations.