2.3.1. ECG Data Processing and Heart Rate Calculation
In the standard ECG waveform, the baseline refers to the zero potential baseline, which is usually determined by the TP segment in the ECG waveform. The ST segment represents the process between the termination of ventricular depolarization and the beginning of repolarization. The normal ST segment is slightly concave and is the line segment from the end of the QRS complex to the beginning of the T wave in the image. Under normal circumstances, the ST segment should be aligned with the baseline [
17]. However, in the process of collecting data from the ECG signal sensor, due to the change in electrode resistance, the drift of the amplifier’s DC bias, and the slow motion of human muscles or breathing, the zero potential baseline is shifted, which affects the ECG waveform [
18].
The frequency range of baseline drift is about 0.05 Hz to 5 Hz, and the main frequency component is about 0.1 Hz, which is low-frequency interference. The frequency range of the ST segment in ECG is about 0.6–0.7 Hz [
19], which is close to the frequency range of baseline drift. Therefore, if a high-pass filter is used to eliminate baseline drift, severe distortion occurs in the ST segment. To solve this problem, we design a median filter to process the ECG data.
We used digital discrete signals to represent ECG signals:
Suppose that the length of the filter window is
, and
N is a positive integer. At a certain moment, the signal samples in the window are as follows:
where
is the sample signal value at the center of the window. The center value of the
signal values in the window arranged from large to small is the output value of the median filter. The width of the window used in this method is
. which is
The magnitude of the ECG signal is only several millivolts, and the main frequency range is between 0.05 Hz and 100 Hz [
20]. After removing the baseline drift, the signal needs to be passed through a low-pass filter to eliminate the interference with a frequency above 100 Hz. The transfer function of the Buteterworth low-pass filter we designed is as follows:
Heart rate measurement is performed by analyzing the peak voltage in the QRS complex [
21]. The algorithm finds the index values corresponding to the peak voltages of several consecutive QRS complexes of the ECG signal and then obtains the current heart rate according to the sampling frequency or sampling interval.
2.3.2. Body Surface Temperature Measurement
As depicted in
Figure 5, the output value of the TAO pin of LMT70 has a negative correlation with temperature:
The relationship between
and ambient temperature can be expressed by the following formula:
However, if the task requires an accurate measurement of temperature in the range of 30–40 °C, the linear relationship between voltage and temperature cannot meet the requirements for accuracy. Therefore, it is necessary to fit the voltage value output using the TAO pin with a quadratic polynomial or cubic polynomial in the range of 30–40 °C. When fitting, we use a stable value of the body surface thermometer as the true value of body temperature, measure the stable voltage value output using the sensor composed of LMT70 in the same environment, and then perform polynomial fitting on the voltage and the temperature.
The results of polynomial fitting based on the value of the body surface thermometer and the voltage output by the LMT70 chip in the range of 30–40 °C are as follows:
Quadratic polynomial fitting result:
Cubic polynomial fitting result:
2.3.3. Pose Estimation and Motion Data Measurement
The algorithm combined with a driver program estimates the pose and collects the motion data for MPU6050. MPU6050 can read the three-axis acceleration and three-axis angular velocity information at high speed [
22], but the pose information reflecting the human body movement cannot be directly collected and needs to be obtained through the corresponding algorithm. The algorithm selects a quaternion as the pose information to be obtained, and the quaternion can avoid the singularity when three variables are used to represent the pose information.
Quaternions are generally written as follows:
where
and
are the three imaginary parts of the quaternion.
The quaternion calculation in the microprocessor can be approximated by the Runge–Kutta method with the angular velocity data read by the sensor. In our design, taking into account the real-time need to obtain motion data, the digital motion processor inside the drive module (DMP) solves the quaternion, which reduces the burden of the external processor and avoids cumbersome steps such as filtering and data fusion. At the same time, high-speed and accurate data can be obtained by reading the DMP registers, which can satisfy applications running at lower frequencies. DMP can provide accurate and stable data to update the frequency of the motion data and the frequency of the reading data using an external processor.
The quaternion and acceleration data are sent to the MCU through I2C, and the algorithm for step counting and distance calculation is executed on the MCU. First, the MCU updates the Euler angle in real time according to the quaternion. The Euler angle can more intuitively reflect the real-time motion posture, and the Euler angle is used in step counting and distance calculation.
The formula for calculating Euler angles with quaternion is as follows:
Rad means that the result of the calculation is converted from radians to angles.
For practical applications, the algorithm uses the comparison between the Euler angle change rate and the corresponding threshold to adjust the system’s judgment of the motion state, and /s is selected as the threshold.
The overall motion data measurement algorithm has two parts: step counting and distance calculation. The step counting algorithm uses 40 ms as a delay to read the acceleration collected by the accelerometer to calculate the number of steps. The algorithm initially eliminates the noise in the acceleration data through the mean filter [
23]. Considering that the acceleration waveform has obvious peaks when people are walking, the algorithm combines the threshold to filter the interference and to save effective fluctuations. The threshold is set to
g. Next, the algorithm checks the acceleration data of the three axes in accordance with the law of motion. The threshold of the peak difference is set to
g. Finally, the algorithm combines the current motion state and the detection results of the three axes to count the steps.
In the distance calculation algorithm, we chose to use two-dimensional numerical integration to calculate the distance [
24]. First, the Euler angle can express the rotation matrix connecting the world coordinate system and the current coordinate system:
The vector in the current coordinate system can be transformed to the world coordinate system through such a matrix:
where
represents the acceleration vector obtained by measurement and
represents the acceleration transformed to world coordinates.
Finally, the algorithm can obtain the distance in the three-dimensional space through two-dimensional numerical integration. In the calculation process, we used the motion state and other information to process the acceleration and velocity to eliminate the interference from gravity acceleration and noise. In practical applications, walking can be considered movement on a two-dimensional plane, and this approximation is more suitable for the requirements of distance calculation tasks. Under this approximation, the matrix can be degenerated to second order, reducing the burden of calculation including filtering, and finally, the result can be corrected in combination with the step counting information. In the walking round-trip test, this algorithm achieved more accurate results.