Pedestrian dead reckoning for MARG navigation using a smartphone

The demand for navigating pedestrian by using a hand-held mobile device increased remarkably over the past few years, especially in GPS-denied scenario. We propose a new pedestrian dead reckoning (PDR)-based navigation algorithm by using magnetic, angular rate, and gravity (MARG) sensors which are equipped in existing commercial smartphone. Our proposed navigation algorithm consists of step detection, stride length estimation, and heading estimation. To eliminate the gauge step errors of the random bouncing motions, we designed a reliable algorithm for step detection. We developed a BP neural network-based stride length estimation algorithm to apply to different users. In response to the challenge of magnetic disturbance, a quaternion-based extended Kalman filter (EKF) is introduced to determine the user's heading direction for each step. The performance of our proposed pedestrian navigation algorithm is verified by using a smartphone in providing accurate, reliable, and continuous location tracking services.


Introduction
A large number of navigation systems, such as GPS, can only be applied to the outdoor and open sky scenarios since the microwaves are easily blocked by the buildings and ground. To solve this problem, the multi-MEMS inertial sensor-based navigation systems are more favored in recent 5 years [1,2]. Inertial sensors are independent of the external information, involve no radiation energy to the environment, and require no external reference frame. On this basis, it can be recognized as an autonomous navigation system providing location, heading, and attitude angle [3,4]. The navigation information obtained from the inertial system is featured with continuity, high data-updating rate, good short-term accuracy, and stability. The magnetic, angular rate, and gravity (MARG) sensors involved in MEMS technology have been widely used in smartphones for pedestrian inertial navigation and are expected to become one of the key components of a variety of localization and tracking systems [5,6].
As far as we know, the pedestrian inertial navigation systems are normally based on pedestrian dead reckoning (PDR) algorithm which is independent of the integration of acceleration values. Based on the physiological characteristics of pedestrian movement, we can use the cyclical characteristics and statistics of acceleration waveform and features which are associated with the walking speed to estimate the stride length. Moreover, the heading is obtained from the integration of gyroscope or from the combination of magnetometer and accelerometer. Due to the randomness of pedestrian hand-held way, the attitude angle of a smartphone cannot be constant. Hence, the accuracy of heading can be guaranteed only after the real-time attitude angle has been calculated. Therefore, the way to obtain an accurate attitude angle solution in different environmental conditions without the external absolute reference signals forms one of the significant challenges to be concerned [7,8].
There are two categories of algorithms for attitude angle updating by using the angular rate of gyroscope: the Euler angle algorithm and the quaternion algorithm. The Euler angle algorithm relies on the Euler angle differential equations to calculate the yaw, pitch, and roll angles. Since the pitch angle in Euler angles can result to degenerations, the yaw and roll angles cannot be determined uniquely when the pitch angle is close to 90°. The quaternion algorithm avoids the singularity problem involved in Euler angles by solving four linear differential equations. On this basis, the quaternion algorithm is featured with simple computation cost and is easy to be operated for a wide application. In quaternion algorithm, since the gyroscope is suffered by the accumulated measurement errors, it is not effective to measure the angles over a long period of time. To obtain a stable and reliable attitude angle, the gyroscope should be integrated with accelerometer and magnetometer. To this end, the complementary filter, Kalman filter, and gradient descent algorithm are widely used to conduct data fusion. The work in [9] proposed the quaternionbased gradient descent algorithm to merge the measured absolute angle and angular velocity and then obtain three degrees of freedom (DOF) for attitude measurement. The algorithm in [9] is simple and is easy to be implemented, but the related accuracy performance is not good. The quaternion-based extended Kalman filter (EKF) algorithm in [10] is recognized to be more accurate, but more system state vectors and higher computation cost are required, which is not appropriate for the real-time processing on a smartphone platform. There is significant accuracy deterioration by using the aforementioned conventional algorithms when a large linear acceleration occurs or the magnetometer is seriously interfered by the surrounding noise, such as the blocking by iron products. To solve this problem, this paper shows a new pedestrian dead reckoning-based MARG navigation algorithm, which is highly accurate and is easy to be implemented on smartphones.
This paper is organized as follows. Section 2 gives the system framework. Section 3 presents the algorithms for step detection and stride length estimation. The heading estimation algorithm is discussed in Section 4. Section 5 shows some testing results and the related discussion. Finally, we conclude this paper in Section 6.

System framework
Our system is based on the PDR algorithm which is recognized as a relative positioning algorithm, as shown in Figure 1 [11][12][13][14][15]. In Figure 1, notations E and N denote the east and north directions, respectively.
where θ i and d i (i = 1,.., k) stand for the heading angle and the stride length of step i. Hence, the user's position coordinates can be calculated by (1) as soon as the parameters d i and θ i are estimated.
The system architecture is shown in Figure 2. In concrete terms, we first conduct low-pass filtering to smooth the modulus of the three-axis accelerometer data. Second, the filtered accelerometer data is used to detect the user's steps for location updating. Third, the empirical model is applied to estimate the pedestrian stride length as the displacement between every two adjacent positions. Fourth, using the quaternion-based extended Kalman filter, we merge the data collected from MARG sensors to calculate the quaternion rotation matrix. Fifth, after the Butterworth low-pass filtering, we  obtain a stable heading angle for each step. Finally, the PDR algorithm is performed to calculate the user's locations in a real-time manner.

Step detection and stride length estimation
Based on the physiological characteristics of the pedestrian, the waveform for the three-axis accelerometer modulus values can be obtained for the formation of cyclical changes. Therefore, the cyclical and characteristic values can be used to detect the steps. We calculate the three-axis accelerometer modulus values in (2).
where a x , a y , and a z are the output data of triaxial accelerometer in the X, Y, and Z directions respectively. Then, we can obtain a single peak curve of accelerometer modulus by using a digital low-pass filter, detect the peak point accurately, and consequently calculate the step number. Some small jitters could be produced during walking when the pedestrian is holding the phone. On this basis, the peaks appear in the output waveform of accelerometer modulus values, as shown in Figure 3. We set a threshold to eliminate the gauge errors of steps which resulted from the shaking of smartphone, such that where ΔT stands for the time interval between every two adjacent peaks, g is the local acceleration of gravity. T Th and A Th stand for the time threshold and the peak threshold, respectively.
We use the empirical model [16,17] to estimate the stride length in (4).
where A max and A min stand for the maximum and minimum of modulus values of accelerometer which are obtained from the step detection. C is the proportionality coefficient. Since the step lengths are determined by height, attitude, and frequency, the value of C which is significantly influenced by the pedestrian height and stride frequency cannot be constant. Considering the nonlinear relations of the proportion coefficient C, pedestrian height, and stride length, we use a back propagation (BP) neural network to obtain this nonlinear mapping for the sake of predicting the value C accurately and real timely. The structure of our addressed BP neural network is shown in Figure 4.

Gyroscope attitude estimation
The angular velocities x, y, and z in the coordinates of smartphone are measured by a three-axis gyroscope. The attitude of the smartphone is obtained from the integration of the quaternion-based rigid body kinematic  equations. The quaternion-based rigid body kinematic equations are where the quaternion Q = q 0 + q 1 i + q 2 j + q 3 k, q i (i = 0, 1, 2, and 3) is a real number. t 0 is the initial time of the user's movement. Q 0 is the initial quaternion. W = 0 + w 1 i + w 2 j + w 3 k is the quaternion of the attitude angular velocity in the coordinates of smartphone. ⊗ denotes the multiplication of quaternion. We can represent (5) in matrix form as where ω i (i = 1, 2, and 3) is the angular velocity. We assume that the angular velocity is a constant value in the same sampling interval. By calculating the differential equations in (6), the formula of quaternion discrete time can be obtained by where Δθ ¼ T s ffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi ω 1 2 þ ω 2 2 þ ω 3 2 p . Based on the relationship between attitude rotation matrix and quaternion, the rotation matrix can be calculated as In (8), the parameter q i (i = 0,…, 3) can be used to update the attitude rotation matrix. Finally, we calculate the roll, pitch, and yaw as

Extended Kalman filter design
In practical use, the attitude angles collected from the gyroscope may start from incorrect initial conditions. Figure 5 Variations of heading angles from 0°to 360°. When the heading is in the vicinity of 360°or 0°, the heading angles will vary from 0°to 360°.  When the accelerometer is not stationary or the magnetometer is exposed to interferences, the accumulated errors by the gyroscope measurement noise and the absolute attitude angles from magnetometer/accelerometer could provide an incorrect estimation on the heading angle. Therefore, the integration of gyroscope, accelerometer, and magnetometer for the calculation of attitude angles can effectively improve the heading precision. The extended Kalman filter is used in the paper to merge all the sensors' information to obtain an accurate estimation on attitude angles. The EKF model is shown in (10).
Using the discrete time model to update attitude angles, the state vector can be described by the rotation Figure 8 Step detection. We can obtain a single peak curve of accelerometer modulus by using a digital low-pass filter, detect the peak point accurately, and consequently calculate the step number.
quaternion. The state transition vector equation is shown in (11).
is the state transition matrix. w k is the vector of processing noise. The measurement model is constructed by stacking the normalized accelerometer and the magnetometer measurement vectors as a kþ1 m kþ1 where T b n ðQ kþ1 Þ is the quaternion-based attitude rotation matrix. g is the vector of normalized gravity. h is the vector of normalized magnetic field intensity. The vectors of measurement noise in accelerometer and magnetometer are notated as a v k + 1 and m v k + 1 which can be recognized as the uncorrelated zero-mean white noise processes with the corresponding covariance matrix R.
From the observation equation, we can find that the relationship between state vector and measurement vector is nonlinear. Therefore, we linearize the first part on the right side of (12) to calculate the observation matrix H as 2b y q 2 þ 2b z q 3 2b y q 1 −2b z q 0 2b y q 0 þ 2b z q 1 4b y q 0 þ 2b z q 1 2b z q 0 4b y q 2 þ 2b z q 3 2b z q 2 −2b y q 1 þ 4b z q 0 −2b y q 0 2b y q 3 2b y q 2 þ 4b z q 3 In the static scenario without magnetic interference, the measurement noise in accelerometer and magnetometer is not changed. When the linear acceleration or the magnetic interference exists, the errors of attitude in accelerometer and magnetometer could be significantly large. To solve this problem, we use an adaptive approach to construct the observation variance σ 2 a and σ 2 m for the sake of modifying the weight of measurement values in a real-time manner. This process is illustrated in (17) and (18).
where ||a k || and ||m k || are the modulus values of accelerometer and magnetometer. k i1 and k i2 are the weighting factors. var(i k − N/2 : i k + N/2 ) (i = a, m) is the variance of modulus values in the sliding window with the size of N.
When the smartphone has a large linear acceleration or is suffered by the external magnetic interference, both modulus value and variance of accelerometer and magnetometer are increased. In this case, to reduce the influence of the linear acceleration and the external magnetic interference, we distribute large values to the observation variance, σ 2 a and σ 2 m , to guarantee that the filtering process is determined by the output of gyroscope.

3 Heading correction
During the walking, the smartphone is suffered by not only the upward and forward movement, but also the swings. From the curve of heading angles obtained by EKF, we can find that the smartphone swings severely. To reduce the impact of swing on heading estimation, we use the second-order Butterworth digital low-pass filter to conduct heading correction.
The quaternion representation is discontinuous in the rotation angles of 360°. For example, the angle of 361°T should be represented as the angle of 1°. The low-pass filtering could result in an unexpected behavior when the heading is in the vicinity of 360°or 0°, as shown in Figure 5. In contrast, the estimation by rotation matrix is not suffered by the discontinuities. After the low-pass filtered rotation matrix is obtained, the heading angle can be calculated by (8). The solid curve in Figure 6 is the result of corrected heading angles.

Testing results
In our testing, the MARG sensors equipped in Huawei smartphone is selected as the inertial measurement unit consisting of a three-axis accelerometer (ST LIS3DH), a three-axis magnetometer (akm8963), and a three-axis gyroscope (ST L3G4200D). The smartphone is based on the Android operating system to provide application programming interface (API). We collect the raw data from sensors using the API with the sampling rate of 50 Hz. Considering the sensor behavior and structure, we do the necessary calibration as one of the important pre-processing modules to integrate the three different sensors. The signal conditioning is required to get rid of the residual bias and scale-factor errors in a fine alignment procedure. As shown in Figure 7, the smartphone is hand-held during walking.

Step detection and stride length estimation
A dataset is collected to examine the performance of our proposed step detection approach. The results of step detection and a magnified part of the detection are shown in Figure 8. From Figure 8, we can find that the probability of step detection is close to 100%. We use five groups of data collected by five different persons with different heights to examine performance  of stride length estimation. The walking length in total is about 105 m. Table 1 shows the results of stride length (SL) estimation.

Heading estimation
We choose the corridors in a building in CQUPT as the testing bed to examine the ability of our proposed approach resisting to the anti-magnetic interference. The testing bed has different intersections and is suffered by variable magnetic interference. As shown in Figure 9, the irregular changes of magnetometer modulus values indicate that strong magnetic interference exists in the environment. Figure 10 compares two different attitude fusion methods: the conventional gradient descent algorithm (GDA) and our proposed EKF. The 'Reference' indicates the direction of testing path. From Figure 10, we observe that the proposed EKF can provide more accurate and stable estimation of pedestrian heading compared to the GDA, especially in the environment where the magnetic disturbance exists.

Trace tracking
Since the error for each step cannot be easily labeled, we use an actual walking trace in a loop (i.e., the starting position and ending position coincide) instead for our testing. The distance between the starting position and the ending position on the tracked trace (or called tracking error) is selected to evaluate the positioning accuracy. In this case, the smaller distance between the starting position and the ending position indicates the higher positioning accuracy to be obtained. In Figure 11, Reference and 'Trajectory' stand for the real trace and the tracked trace, respectively.
The tracking results by our proposed pedestrian navigation algorithm are shown in Table 2. Ten groups of data collected by ten different people are used to evaluate the positioning accuracy. For the trace with 400 m in length, the tracking errors are only within 8 m.

Conclusions
This paper presents a new pedestrian navigation algorithm based on the MARG sensors equipped in Huawei smartphone. The testing results on the smartphone platform show that the accurate, reliable, and continuous localization and tracking can be provided. Our proposed algorithm can be applicable to many other types of smartphones and also provide an important guidance to the design of the integrated Wi-Fi and MEMS navigation systems [18][19][20]. Furthermore, the optimization of heading estimation algorithm forms another interesting work in future.