Abstract
Background:
Acceleration and angular velocity sensors are commonly used in the measurement of gait parameters. A representative application calculates the limb segment dip angle. The rotation angle is typically deduced by a conventional Kalman filter, which includes the use of two empirically derived parameters. We improved this conventional method by introducing colony algorithm to find the optimal parameter combination instead of empirically assignment.
Method:
To achieve optimal results, a servo motor with an inertial measurement unit was used to simulate human limb segment motion according to programmed rotation angles that was employed as the ground truth. To minimize the bias between the ground truth and the calculated result, the ant colony algorithm was employed to obtain the optimal Kalman filter parameter combination in two-dimensional space.
Results:
By the motor experiment, the sum of the angle squared error was only 1.9305 rad2, much better than the 6.7723 rad2 error by the conventional method. The optimal parameter combination obtained was then used in a human experiment involving a basketball player. The frames from video of a whole gait cycle period were all showed with a corresponding deduced thigh dip angle curve diagram.
Conclusion:
The colony algorithm for parameters optimization results in less angle errors deduced by Kalman filter using the data from inertial measurement unit. The subject experiment verified the feasibility and performance of this method.
Introduction
Since the 1970s, gait analysis has attracted considerable attention from researchers and clinicians. In human gait analysis, the measurement of lower extremity joint angles is very important and is useful in applications such as rehabilitation exercise, sports training, and entertainment. An inertial measurement unit (IMU) is the most commonly employed tool for estimating and analyzing kinematic movement. An IMU comprises accelerometers, gyroscopes, and magnetometers for measuring the acceleration, angular velocity, and the magnetic field vector in their local coordinate system, respectively. The orientation of the sensors can be estimated using appropriate algorithms, which can facilitate gait analysis based on an IMU mounted on a human body. An early method fused three accelerometers and a single gyroscope to monitor human posture and walking velocity.1,2 To estimate the human posture in the sagittal plane, one of the three accelerometers was mounted on the subject’s trunk, thigh, and shank, respectively, thereby measuring the angle of the gravitational direction of each anatomical component. To estimate walking velocity, a gyroscope was attached to the thigh, and changes in the angle of the sagittal plane caused by walking were obtained by integrating the sensor signals. The walking velocity was then calculated according to changes in the thigh angle, the period of a single step cycle, and the subject’s leg length. Pappas et al. 3 proposed a reliable gait phase detection system to measure the angular velocity of the foot, and the forces exerted by the foot were assessed through a gyroscope and three force-sensitive resistors. Roetenberg et al. 4 used gyroscope, accelerometer, and magnetometer signals to estimate the orientations of various segments of a human body. Santhiranayagam et al. 5 mounted inertial sensors on a human foot to estimate gait parameters for evaluating their suitability in clinical applications. To obtain more information, such as for joint angles, additional sensors can be mounted on leg segments. Other researchers have employed a body-mounted gyroscope to calculate body segment orientations from the angular velocity data. 6 Another researcher employed three IMU sensors to track and locate human velocity. 7
In the 1980s, video camera systems were developed to track human movements, and, since then, this method has been an important method for gait analysis.8,9 Gait movement can be analyzed using an optical tracking system, for example, the Vicon motion analysis system.10,11 Andrews employed optoelectronic technology to measure the position of markers mounted to body segments.12–14 However, this technology is expensive and is generally limited to indoor use, such as in laboratories or clinical environments. Moreover, all cameras employed in the approach require precise assembly. 15 However, the development of micro-electromechanical system (MEMS) technology has fostered a series of lightweight, low-power inertial sensors. 16 IMUs are based on this technology. Compared to video camera technology, MEMS technology is a better choice under particular conditions owing to its miniaturization, and the developed sensors are lightweight, portable, less expensive, safe, and much more easily mounted to the human body. 17 Wearable sensing systems have advantages over other systems, such as the capacity for conducting experiments outdoors to monitor daily movements. 18 One of the inconveniences is that the employment of a large number of sensors at one time may become overly burdensome for subjects. 19 Moreover, the sensors are subject to output errors mainly caused by noise, axis misalignment, and cross-axis sensitivity, particularly when the sensors are improperly handled.20,21 The main output error of gyroscopes is associated with angle wander, which results from angle random walk and the progressive dynamic variation of the bias. An accelerometer produces noise in its output. Ferromagnetic materials, such as iron and other magnetic materials, near a magnetometer sensor will affect the direction and density of the local earth magnetic field and thus negatively affect the orientation estimates. 22
Most existing studies have employed the Kalman filter to estimate the angle due to its better response.23–26 However, the accuracy of a Kalman filter algorithm is highly dependent on the appropriate tuning of its parameters, and a balance suitable for both low- and high-intensity movements is difficult to achieve. In some studies, the parameters are empirically determined and achieve a tuning that may not be applicable to general conditions. Olivares and Górriz have proposed other filters such as least-mean squares (LMS) and recursive-least squares (RLS) filters. Miezal et al. 10 proposed an algorithm based on quaternions to calculate body segment orientation, which was converted from the orientation estimations of the sensor units through a rotation matrix obtained from a calibration trail. The general regression neural network (GRNN) algorithm has also been applied to estimate ankle, knee, and hip joint angles with good accuracy. However, to acquire this functionality, this method must first be trained for individual settings prior to measuring the parameters. Therefore, among all the approaches considered, we selected the Kalman filter to eliminate the drift. A common method employed to calculate the angle is to double integrate the detected angular acceleration, although this method results in significant drift.27,28 To minimize this drift, a number of approaches have been proposed in the past decades. For example, Morris 29 equated the signals obtained at the beginning and end of each walking cycle. Tong and Granat 30 applied a low-cut, high-pass filter on the shank and thigh inclination angle signals. However, these methods cannot estimate the data correctly when the object is static or exhibits a low moving frequency. Thus, neither method can be used to process real-time signals. Another method for estimating joint angles from measured accelerations is to estimate shank segment orientation in the sagittal plane during walking and subsequently calculate the thigh inclination angle by adding the two values of the shank and knee angles. The results are acceptable only if the segment acceleration is small compared to that of gravity. 31
We utilized a six-axis IMU to obtain the original acceleration and angular velocity signals of the low limb segment. The Kalman filter was used to fuse the original data and calculate the segment angle. An experiment employing a standard subject was designed to verify the proposed algorithm. Simulated noise disturbance was added to the signal. Swarm intelligence algorithms have been widely used for parameter searching. 32 In this study, the ant colony algorithm was applied to obtain optimal values for two of the Kalman filter parameters according to ground truth criteria. The experimental results obtained for detecting the dip angle of an adult male thigh demonstrated a very high accuracy. This angle calculation algorithm is very fast and therefore suitable for real-time processing. The proposed method has good prospects in rehabilitation applications.
The key of this work is how to find the optimal parameters in the mathematical Kalman filter model. Most of the literatures have omitted the method of how to calculate the number of these parameters, while we have creatively utilized the ant colony algorithm to obtain the optimal parameters. A step motor was used as a standard subject to verify the angle deduction algorithm. A university basketball player was selected as the subject to show the result of thigh dip angle deduction method.
Hardware description
For this study of the human lower limb posture and motion during walking, we employed IMUs to measure the acceleration and angular velocity of thighs, shanks, and feet during walking. An MPU6050 six-axis IMU with a three-axis accelerometer and a three-axis gyroscope was employed in this study. The IIC protocol was employed for communications owing to its convenience in the data-acquisition experiment. Given that the data-processing system must accommodate multi-channel data acquisition, processing capacity, and real-time requirements, in addition to a secure digital (SD) card and a serial peripheral interface (SPI) communication protocol, we employed an ARM Cortex-M3 architecture STM32F103 microcontroller unit (MCU) as the main controller of the overall data-acquisition system to store data collected from IMUs. For the convenience of data acquisition, an appropriate data-storage method is important. The system stores the data provided by the IMU using an SD card storage method rather than a computer. The data are stored in the form of an Excel spreadsheet, in which each column represents a single axis of data. This type of stored file is easily read on a computer for subsequent offline data analysis.
Each data-acquisition experiment generated an Excel spreadsheet. The name of the spreadsheet comprises the date and the current number of the experiment on that day. Use of a real-time clock updates the date automatically, and the experiment number is automatically reset to zero when the date changes. The name of the current experiment is displayed on a flat-panel display for recording. The system employs a lithium polymer battery, which would be damaged if the voltage were lower than 2.85 V, and this necessitates the inclusion of a low-voltage alarm, such that the alarm is engaged when the battery voltage is less than 2.9 V as a reminder to replace the battery. The data-acquisition system detects the effectiveness of data acquisition each time after signal sampling. The system also checks the reliability of the hardware connection from the recorded file. If any IMUs are not connected, the system will sound an alarm and display an indication of the specific disconnected IMU(s). Experiments show that the performance of the data-acquisition system is reliable and stable. A schematic of the system is given in Figure 1.

Hardware structure scheme.
Materials and methods
Angle deduction algorithm based on the Kalman filter
The quaternion coordinate system was used to represent an object’s attitude and changes in the three-dimensional (3D) angle. Unlike the Euler equations, gimbal lock does not occur when employing quaternions, which is convenient for solving the attitude. In this study, each limb segment was equipped with a single IMU with the goal of measuring the dip angle. After calculating the dip angles by updating the quaternion, in conjunction with the angular velocity data, the integration error was corrected by the Kalman filter using the angles calculated from the acceleration outputs.
Quaternion calculation
3D rotation using quaternions
where
The Runge–Kutta method was used to solve the following quaternion differential equation for updating the quaternion at each time t
where
Sensor-to-segment mounting
As expressed before, the calibration posture was needed in this experiment. The experimenter was asked to stand upright for 5 s before walking. During that time, we needed to make sure the lower limb segment was straight and parallel to the direction of gravity. The relative position of the lower limb segment in the local sensor coordinate system, denoted by the vector
The angle
Finally, the dip angle of the lower limb segment obtained from the angular velocity data, denoted
Segment dip angle from acceleration data
The value of
where
Application of Kalman filter
The Kalman filter uses a system’s dynamics model, known control inputs to that system, and multiple sequential measurements to form an estimate of the system’s varying quantities that is better than the estimate obtained using only one measurement alone. It is a common sensor-fusion and data-fusion algorithm. The Kalman filter deals effectively with the uncertainty due to noisy sensor data, and to some extent with random external factors as well.
The value of

Block diagram of angle calculation method using Kalman filter.
The state equation is represented by the error of the joint angle measured by a gyroscope,
where
where
and predictions
where
Ant colony algorithm to obtain optimal parameters
In the natural world, ants of some species wander randomly, and upon finding food return to their colony while laying down pheromone trails. If other ants find such a path, they are likely not to keep traveling at random, but instead follow the trail, returning and reinforcing it if they eventually find food. Pheromone evaporation also has the advantage of avoiding the convergence to a locally optimal solution. If there were no evaporation at all, the paths chosen by the first ants would tend to be excessively attractive to the following ones. The overall result is that when one ant finds a good/short path from the colony to a food source, other ants are more likely to follow that path, and positive feedback eventually leads to all the ants following a single path. The idea of the ant colony algorithm is to mimic this behavior with “simulated ants” walking around the graph representing the problem to solve.
The two uncertain parameters of the Kalman filter, for which different values lead to different results, are the angular velocity weight
First, the solution of the optimization problem is determined as
In this model, each figurative ant constructs a solution by choosing a point at each row according to the pheromone value

Schematic of parameter space meshing.
The probability
where for point
After the
where
When the number of search cycles reaches an upper bound
where
After the ranges of each parameter have been updated, the parameter matrix is reconstructed according to equation (19), and the initial pheromone values of each point are reset according to equation (21). The search process is then repeated until the bias between

Flowchart of ant colony algorithm.
The optimal parameter
The computational complexity of the proposed algorithm can be analyzed according to the above algorithm steps. The steps involving the highest computational complexity are given as follows: (1) the structure of the solution involving the calculation of the objective function value, (2) the process of updating pheromones, and (3) the space subdivision. The first step represents the highest computational complexity and can therefore represent the computational complexity of the overall algorithm, which is given as follows
where
Results
Data acquisition
The data-acquisition hardware was employed to collect signals from a standard subject and a human subject. The standard subject was a servo motor, and the human subject was a healthy 20-year-old male. Data collected from the standard subject were treated as the original signal. Data collected from the human subject were treated as the result of combining the signal and noise. The Kalman filter was used to fuse the acceleration and angular velocity data to determine the angle. Integration of the angular velocity represented the change in the angle. Prior to data acquisition, all IMUs were calibrated to minimize the offset. However, even a precise calibration yields a degree of non-zero bias, which inevitably imparts a degree of drift to the angles integrated from the gyroscope data. In this study, the acceleration was used to rectify the steady-state error. The detection noise of the accelerometers was mainly derived from vibration, leading to a velocity detection bias. The accelerometer noise was defined as the resultant acceleration obtained from human subject measurements subtracted by the acceleration due to gravity. The signals from the standard subject were treated as the ground truth. Then, the noise obtained from the human subject was added to the ground truth data to simulate a realistic standard signal. A quaternion coordinate system, widely used in the inertial navigation field, was employed to deduce the rotation angles based on the angular velocity data. As ideal control parameters, the coordinate system represents a rigid body’s Euler axis and rotation angle during the attitude transformation. We subsequently obtained the rotation angles based on the acceleration data by calculating the angles between the segment vector in the local sensor coordinate system and the gravity vector. After obtaining these two types of rotation angles, the two angles were fused by means of the Kalman filter. Ant colony algorithm optimization was employed to obtain an optimal combination of two of the parameters required by the Kalman filter to achieve an optimal result relative to the ground truth. Experiments were conducted for both the standard subject and the human subject, and the results demonstrated the feasibility of the proposed algorithm.
Two different experiments were designed. In the first, data were acquired from the standard subject to obtain a series of reference rotation angles for implementing the ant colony algorithm. Data were then acquired from the human subject to verify the feasibility of the algorithm. In both of these two experiments, the acquired IMU data were stored in the SD card, which was convenient for offline processing.
In the standard subject experiment, a motorized rotation stage was placed on an optical platform, keeping the rotation plane vertical to the horizontal plane. A single IMU sensor was mounted on the rotation plane. At the beginning of data acquisition, the servo motor is held stationary for 2 s and then rotated clockwise 2° over a period of 0.17 s, held stationary for 0.73 s and then rotated clockwise 90° at a constant angular velocity over a period of 2.7 s, held stationary for 0.6 s and then rotated clockwise 2° over a period of 0.17 s, held stationary for 0.73 s and then rotated anti-clockwise 94° at a constant angular velocity over a period of 3.56 s, and held stationary for 3 s before the end of data acquisition. Over the course of the experiment, the acceleration and angular velocity data obtained from the IMU were collected, and the rotation angles were recorded as the ground truth of the experiment. The experimental record of the rotation angles is given in Figure 5.

Record of programmed motor rotation angles.
During the human subject experiment, the IMU was mounted on the subject’s thigh segment, and the data-acquisition electrical circuit board was bound at the subject’s rear waist. The subject was first instructed to maintain an upright posture for 5 s, keeping the lower limb segment vertical for the sensor to acquire the direction of gravity for calibration purposes. The subject was then instructed to walk on level ground at a medium speed while IMU data were sampled. The resultant acceleration subtracted by the acceleration due to gravity was treated as the acceleration noise. After collecting the acceleration and angular velocity data of the IMU, the accelerometer noise was added to the standard subject signal to simulate a realistic standard signal.
Verifying algorithm performance
After the reference rotation angles were obtained from the standard subject experiment, the ant colony algorithm was applied to improve the performance of the sensor fusion by searching the optimal parameters in the Kalman filter. To verify the performance of the ant colony algorithm in terms of the searching efficiency or the optimality of the search results, we compared its performance with that of two different algorithms.
Comparison with traversal method
In the Kalman filter there are two uncertain parameters, the angular velocity weight
Comparison with use of empirical parameter values
In most Kalman filter applications, the parameters are assigned empirical values. In the present circumstance, most researchers assign the parameters as
where
Human experiment based on proposed algorithm
The optimal values of

Continuous video frame series representing a single gait cycle period.

Deduced left thigh dip angle over a single gait cycle period.
Discussions and conclusion
In this paper, we presented a lower limb segment angle measuring system employing a six-axis IMU with a 3D accelerator and 3D angular velocity outputs. To eliminate gyroscope drift, the Kalman filter was utilized to fuse the respective segment dip angles deduced from acceleration and angular velocity measurements. The Kalman filter employs two uncertain parameters that are typically assigned empirical values. In the proposed method, measurement results obtained from standard subject and human subject experiments were employed by the ant colony algorithm to find the optimal parameter value combination that led to a minimum bias from the ground truth. The human experiment involved a basketball player as the test subject, where the dip angle of the subject’s thigh during the experiment was calculated offline. The segment angles were then deduced from the gravitational direction. The experimental results demonstrated that the wearable sensors employed can provide quantitative measurements of human gait motion, such as joint angles. The accuracy of an optical tracking system is greatly dependent on the position of the installed optical markers, and it is very difficult to eliminate bias. 33 However, in the servo motor reference system, the programmed rotation angles are highly accurate.
The proposed lower limb segment angle measuring system still requires improvement, and this represents ongoing future work. Because the method employs no magnetic field sensing, the yaw angles cannot be obtained, which causes difficulties when calculating the joint angle. To solve this problem, the angle reversion system is being improved. A nine-axis IMU sensor with magnetic detection will be employed to upgrade the system, and orientation reversion algorithms other than the Kalman filter will be implemented to test their respective advantages. Ultimately, a real-time lower limb angle measurement system will be developed for rehabilitation engineering product applications.
Footnotes
Acknowledgements
We would like to personally thank the Xiamen University basketball team for their sincere cooperation.
Declaration of conflicting interests
The author(s) declared no potential conflicts of interest with respect to the research, authorship, and/or publication of this article.
Funding
This work was supported by the National Natural Science Foundation of China (61571381) and Soft Science Project of Fujian Province (2016R0083). Financial support from National Natural Science Foundation of China, Chinese Fundamental Research Funds for Central Universities, and Soft Science Project of Fujian Province is gratefully acknowledged.
