1 Introduction

Due to the change of working mode and the improvement of living standard, people’ living habit and eating habit have experienced great changes. Staying indoors for a long time, and heavily depending on vehicles, a lot of people are lack of exercise. Moreover, because of the excessive intake of high-sugar and high-fat foods, incidence of high blood pressure, heart disease and hyperlipidemia increases year by year. From 1959 to 2003, the morbidity of hypertension increased from 5.9 to 25%. Prevention and control of these diseases have become a topic of concern Tian et al. [1]. In addition to reasonable diets, positive and rational exercise can also enhance the immune ability of the human body and improve the health. To this end, it is of great value to detect the daily movement of human body and reasonably take exercise. The daily gait of the human body includes: walking, running, climbing the stairs, going downstairs, which consume different amounts of energy. It is important to identify the daily gait to estimate different gait patterns of human body Shukla et al. [2].

2 State of the art

2.1 Development trend of gait recognition

At present, there are three major human behavior recognition methods: recognition based on wearable devices, recognition based on vision, and recognition based on environment Ngo et al. [3]. On the one hand, recognition based on wearable devices has the advantages of strong robustness and high accuracy, and can detect multiple events simultaneously. The recorded video information can be read on the remote control terminal. However, its application is confined to the indoor environment and not adapt to a wider range of places. In the meantime, this method also involves privacy protection Lv et al. [4]. The environment-based approach collects object information through multiple sensors installed around the body Magno et al. [5]. The common sensor is a pressure sensor, like a pressure sensor installed on the floor, which can detect the vibration of the floor during motion. This method collects the data of human behavior by installing multiplesensors in the site where people often take exerciese Yang et al. [6]. Human behavior recognition based on wearable devices implants sensors in clothes or portable devices to detect the posture of human body and behaviors of the wearers. Milosevic et al. [7].

2.2 Development status of MEMS

With the development and maturity of MEMS technology, MEMS accelerometer with high sensitivity, small size and low price has been installed in electronic consumer products, such as mobile phone, smart watch and notebook. Shikida et al. [8].

For example, smart phones with built-in accelerometers are much in demand on the market. The application of the acceleration sensor brings people the experience that is completely different from the past. The novel human–computer interaction mode not only brings great success to the product, but also injects new vitality to the whole electroniccomplete machine market. Human gait recognition based on acceleration sensor belongs to the field of pattern recognition. It first obtains acceleration data by acceleration sensor and then transmit the data to data device by Bluetooth wireless transmission technology to obtain acceleration data. Afterwards, the data are preprocessed to extract and select features. The gait is identified and classified through classification algorithm Chen et al. [9]. The human gait recognition based on the acceleration sensor has a very wide application prospect in various fields, such as intelligent human–machine interaction, intelligent monitoring, biomedical research, sports competition and sport energy consumption evaluation. For example, improve the functionality of existing pedometers: From a variety of gait, we can recognize the gait movements such as running and climbing stairs, establish the energy consumption equation of different sports modes, and accurately calculate the energy consumption of various motion states Wang et al. [10]. Therefore, this paper is of great significance to the research of gait recognition based on MEMS sensor.

3 Methodology

3.1 Feature selection

Feature selection means selecting a d-dimension subset from the D-dimension feature F. Under a criterion function J, the selected subset d is optimal in all dimensions of F. Search strategy and criterion function are two important aspects of feature selection. Feature selection first searches a feature subset d from all features according to some search strategy and then evaluates the selected feature subset d. The reliability of the evaluated result is compared with that of stopping criterion J. If the evaluated result has higher reliability than the stopping criteria, the search is stopped. Otherwise, the search is continued to generate the next feature subset, which is continuously evaluated and compared. Finally, the relevant search strategy is obtained. The general process of feature selection is shown in Fig. 1.

Fig. 1
figure 1

The general process of feature selection

The search process refers to the process of searching the feature subset d. The common search algorithms include random search, heuristic search and complete search. Complete search is further divided into: optimal priority search, breadth priority search, branch bound search and directional search. Evaluation function evaluates the superiority of a feature subset. Evaluation functions are divided into two categories: filter and wrapper. Wrapper is essentially a classifier which classifies the sample set through the selected feature subset, and the reliability of classification is an evaluation function. Common evaluation functions include correlation, distance, information gain, consistency and classifier error rate. Information gain, distance, consistency and correlation belong to Filter, and classifier error rate belongs to Wrapper. Classifier error rate refers to that Wrapper classifies the sample set through specific classier based on the selected feature subsets, and the reliability of classification is an evaluation function. Stop criterion is a threshold associated with the evaluation function. When the value of the evaluation function is lower than that of the stop criterion, the feature subset needs to be searched again. When the value of the evaluation function is higher than the stop criterion, the search is stopped and the optimal feature subset has been obtained. Validation of the selected feature subset is also a process of re-classification.

3.2 Posture recognition algorithm

Walking, running, going up stairs and going downstairs are complex and random movement of human displacement. During walking and running, the gravity center of body moves forward along a complex spiral curve. In the process of movement, the center of gravity will move up, down and sideways and then accelerate and decelerate alternately. In order to maintain the balance of the body, the pelvis correspondingly rotates, tilts and moves laterally. Walking and other gait are periodic behaviors of the human body. According to the leg behavior, a gait cycle can be divided into two stages: a support stage and a swing stage. About 15% in the walking cycle is in the period of bilateral support.

If there is no bilateral support in the gait cycle, and both feet leave the ground, the human body may be in a running state. On the contrary, if there is a bilateral support period, the human body may be in the state of walking, going up the stairs or going down the stairs. When walking up the stairs and running in the support stage, the heels do not land obviously. The sequence of support stage when going downstairs is toes landing, soles landing, middle support stage, heels off the floor, and toes off the floor. The swing stages of walking, running, going upstairs and going downstairs swing phases are similar, only with the difference in amplitude. The actions of the upper limb vary greatly during the walking and running cycles. The possible actions include: swinging, static, and other random movements. Therefore, if the sensor is worn on the upper limb, even if it is also in the walking state, the collected sensor data can not reflect the walking state effectively because of the various behaviors of the upper limb.

Throughout the gait, all muscles and bones of the body work together. In this paper, the FFT coefficients of waist acceleration data is extracted as the features of walking, running, going upstairs and going downstairs, and the SVM classifier is used to classify and identify the features. Except that the recognition rate of running is close to 100%, and the recognition rates of walking, going up stairs and going downstairs are lower than 90%. In practice, the recognition rate is not acceptable. Therefore, the height variation of the human body will be measured through a barometer as a feature of walking, running, going upstairs and downstairs.

The barometer has been added to the embedded device, and the relative precision of BMP280 and BMP280 is ± 1 m. By consult data, we can find that the floor height of residential buildings, office buildings, shops and other civil buildings is generally greater than 2.8 m. The time to go upstairs and downstairs at constant speed is generally more than 12 s. The height change value is obtained by calculating the change value of barometer within 12 s. When \(\left| {\Delta h} \right| > 2m\), the human body may be on or off the stairs. However, because of the change of air pressure by taking elevators and air flow variation, the features of accelerometers should be combined as the gait features. The flow chart of gait recognition algorithm is shown in Fig. 2. The main work is as follows:

Fig. 2
figure 2

Gait recognition flow chart

First, data filtering. In this paper, it is necessary to transplant the low pass filter to the embedded device through C code. The filter model is shown in formula (1). The values of \(\vec{a}\) and \(\vec{b}\) have been determined in the last chapter, and their values are shown in formula (2) and formula (3). The filter is second order.

$$y[n] = \sum {_{k = 1}^{N} a_{k} } *y[n - k] - \sum {_{k = 0}^{N} b_{k} } *x[n - k]$$
(1)
$$\vec{a} = \{ 1.0000,0.4602\}$$
(2)
$$\vec{b} = \{ 0.7301,0.7301\}$$
(3)

The filter model is transplanted through C code, that is, C code is used to realize (1). To implement the above filters, two queues, RawDataQueue and FilterDataQueue, need to be defined. RawDataQueue stores raw data, and FilterDataQueue stores the filtered data. The queue length is 2. The filter implementation flow is shown in Fig. 3.

Fig. 3
figure 3

Filter implementation flow chart

Second, data partitioning. To facilitate the subsequent FFT computing, the queues with the length of 256 data, namely, AccxQueue, AccyQueue, AcczQueue and BaroQueue store the acceleration triaxial data and barometer data. The latest data are added to the queue at the tail of the queue, and the data at the head of the queue dequeue, thus the sliding partitioning of data is completed. Afterwards, the FFT value is calculated. C code is used in the embedded device to obtain the FFT function. FFT is a gast algorithm for discrete Fourier transform, which is defined as.

$$X_{k} = \sum {_{n = 0}^{N - 1} } x_{n} *W_{N}^{nk} k = 1,1, \ldots \ldots ,N - 1$$
(4)

where, \(W_{N}^{nk} = e^{ - j2\pi nk/N}\). FFT performs butterfly calculations through the periodicity, reducibility and symmetry of \(W_{N}^{nk}\) to reduce the amount of computation. In this paper, the radix-2FFT algorithm is used to realize the FFT transform of the data. The length of the data FFT_N = 256 is 2 to the 8th power. The FFT is composed of two parts: binary reverse order rearrangement and iterative butterfly operation. The operation consists of three cycles, and the innermost loop computes each group of butterfly units at each level.

3.3 Step counting algorithm

According to the above analysis, the key to identifying the step number is the design of the filter. When the clutter is completely filtered out, the filter is designed by the peak-valley difference value of the acceleration wave. The filter is a three-order filter, and the values of \(\vec{a}\) and \(\vec{b}\) are:

$$\vec{a} = \{ 1.0000,0.9865,0.4468\}$$
(5)
$$\vec{b} = \{ 0.1026,0.2051,0.1026\}$$
(6)

After the filter is designed, the number of steps is identified through decision tree. In the last chapter, the threshold of peak-valley differences for walking, running, going up stairs, and going down stairs is lg.

The step counting algorithm is implemented on the embedded device. According to the real-time behavior, the peak-valley difference of each walking cycle is not the same. The peak-valley difference of running is greater than that of walking, going upstairs and going downstairs. The signal amplitude of walking is similar to that of going upstairs and downstairs, but its acceleration signal is more stable. Therefore, in order to reduce the probability of identifying other actions as steps, these judgment conditions will be added in the implementation of the algorithm.

3.4 Fall algorithm

In the research on detection of falling based on the single accelerometer, the impact force, velocity and posture after falling are taken as the judgment features of falling to obtain the maximum sensitivity (SE) and specificity (SP). Falling can also be judged based on a single gyroscope. The rotation angle of the main torso is calculated through the gyroscope to determine whether the human body falls. Some research judge falling by combining accelerometers and gyroscopes. Features extracted from acceleration data are similar to those extracted based on single acceleration. The gyroscope is used to calculate the rotation angle of the body as one of the falling features. However, the algorithm has high false positive rate in practice. The main reason for worse performance in practice compared with that in previous experiments is that the device was fixed at the waist. However, in some real life scenarios (such as sleeping, bathing and charging), the device needs to be removed, and during this process, the device will be flipped and shook in hands (Fig. 4).

Fig. 4
figure 4

Calculation step flow chart

4 Result analysis and discussion

4.1 Posture recognition experiment

In this paper, we identify the features by using the function provided by the lib SVM toolbox on the Matlab. Since the SVM is a two-class classifier, multi-class classification is implemented in a pair of other ways. There are four behaviors to identify, namely, walking, running, going up stairs, and going downstairs. Therefore, we need to construct four two-class classifiers. When the ith classifier is trained, the ith class is used as the positive class, and the others are negative classes for training. In the last section, the gait feature has been identified, and the 500 features to be identified and 500 features of all other behaviors are taken as the training set and the test set. A half of the features are selected as training set and the other half as test set. The algorithm flowchart is shown in Fig. 5.

Fig. 5
figure 5

Algorithm flow chart

When the penalty parameter C and kernel function parameter g in the preliminary classification of the data are taken as the conventional selected value, we cannot get the highest classification accuracy of the model. Therefore, it is necessary to optimize the parameters to improve the classification accuracy. The simplest method for parameter optimization is to get the discrete values of C and g within a certain range, or set appropriate step size for lattice point test. The combination with the highest accuracy is the optimal parameter. The design adopts cross validation method to optimize parameter to effectively prevent from the occurrence of undertraining and over-training states, so that better classification effect can be obtained.

The basic idea of cross validation parameter optimization is to group raw data from certain angles. Some data is the training set of the model, and the rest is the test set of the model. The classification system requires prior training through data in the training set. The trained classification model is tested through data in the test set. The performance of classification system can be evaluated by the accuracy of model classification. The specific implementation method (K-fold Cross validation) is to divide the raw data into K groups. The data in each group are as the test set and the remaining K-1 groups as the training set. After K times of verification, the average accuracy of all models is used as the performance evalucation index of the classification system. K is 5 here. The classifier is trained through the svmtrain function provided by libsvm, and tested through the svmtrain function provided by Libsvm. C, g and the whole training set are obtained through the above steps to get the SVM model for test.

The experimenter wears the equipment on the waist to test the four gaits of walking, running, going upstairs, and going downstairs. Each gait lasts for 300 s. There are 6 participants aged between 21 and 60. The height is between 150 and 181 cm, the weight is between 45 and 75 kg, and the proportion of men and women is 1:1. The gait recognition result in the final test is as shown in Table 1, the accuracy of the recognition has been improved to some extent (Table 2).

Table 1 Gait algorithm final test results
Table 2 Sensitivity and specificity of the fall method

4.2 Step counting algorithm experiment

The equipment wearing mode and experiment objects are similar to the previous section. As shown in the figure, the step counting error of running and walking is less than 0.5%, while the step counting error of going upstairs and downstairs is relatively large, but smaller than 2%, which have been improved compared with similar step counting products. However, the step counting accuracy of going upstairs and downstairs is lower than that of running and walking.

4.3 Fall algorithm experiment

According to the experiment result, when impact force, velocity and posture after falling are taken as the judgment features of falling, if the device is flipped in hands, the above fall judgment algorithm will determine whether this behavior is falling. We obtain the data waves of accelerometers and gyroscopes when the device is flipped in hands, and the experimenter actually falls down.

By observing the sensor curve in the flipping scene and the actual falling curve, we can know that the acceleration data of the former does not have weightless feature. Therefore, this paper uses acceleration and gyroscope data to calculate the weight loss feature accm_weight_loss_, impact force accm_impact, velocity accm_velocity, posture after falling accx_postrue and angle of the main body gyrm_angle as the falling features. Figures 4 and 5 marks the weight loss features except for the falling process. When the weight loss state is shown on the sensor data, the RMS value of the acceleration is less than the gravitational acceleration for a period of time. The weight loss of the body can be calculated by integrating the difference between the RMS of the three axis acceleration and the gravitational acceleration. The threshold of fall feature has been obtained in the previous chapter. The thresholds of the impact force, velocity, posture after falling and flipping angle are 3.1, 5.2 m/s, 30° and 80°, respectively. In this paper, the weight loss feature is added as one of the falling features. Through the experiment, the threshold value of the weight loss feature is 10, and the decision tree is used to judge the falling (Figs. 6, 7).

Fig. 6
figure 6

Step algorithm final test performance

Fig. 7
figure 7

The data waveform of the actual backward drop

According to different directions, falling is divided into four types: front falling, backward falling, left falling and right falling. All experiments were carried out on the cushions to prevent the experimenter from being hurt.

The impact strength of falling on the cushion is less than that on the true ground, but the changes of dip angle and attitude angle are the same as those of falling on the ground. Therefore, this experiment can accurately test the accuracy of the falling alarm system. In addition, the testers wear the falling alarm system to complete the following daily activities: standing up; walking; sitting down and getting up from a chair; going upstairs and downstairs, and lying down slowly on cushion. Each tester completes each behavior for 20 times. A total of 6 testers are recognized through the proposed algorithm, and the sensitivity and false positive result are calculated and compared with the previous features. The extracted features are compared with the traditional feature, finding that adding weight loss features do not reduce the sensitivity of the fall detection, but it can increase its specificity. Therefore, the algorithm used in this paper is effective.

This paper mainly realizes the human behavior recognition algorithm of MEMS sensor and uses the barometer difference as one of the gait features to improve the gait recognition accuracy. For falling algorithm, this paper proposes adding weight loss features which reflect the weight loss state of human body in flipping in the air as the fall judgment features. Experimental results show that weight loss features can effectively increase the specificity of the algorithm, but will not reduce its sensitivity.

5 Conclusion

This paper is of great significance to the research on gait recognition based on MEMS sensor. In order to more accurately classify gait and improve the gait recognition rate, the algorithm of human gait recognition based on MEMS sensor is studied in this paper. Firstly, the recognition rate of behaviors of typical human body parts is studied, including walking, running, going upstairs and downstairs, falling and stillness. Data acquisition experiment was carried out to collect inertial sensing data of key parts of human body under various behaviors. Moreover, we design the behavior recognition algorithms in PC, including attitude recognition algorithm, step counting algorithm and falling algorithm. Finally, experiments are designed to verify the algorithm and draw the conclusion. That is, the algorithm proposed in this paper can effectively monitor and recognize various gait patterns of human body. When the weight loss features are added, the sensitivity remains and the specificity increases. In a word, the algorithm designed in this paper is effective. However, the acquisition of interference data is not comprehensive in this paper, and the estimation of the algorithm performance is relatively ideal. For example, the data of some motions, such as rolling, swinging, and playing basketball, are not collected. Therefore, more types of motions need to be added to the existing human behavior database in subsequent research.