1 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 quaternion-based 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.

2 System framework

Our system is based on the PDR algorithm which is recognized as a relative positioning algorithm, as shown in Figure 1[1115]. In Figure 1, notations E and N denote the east and north directions, respectively.

x k = x 0 + i = 1 k d i cos θ i y k = y 0 + i = 1 k d i sin θ i
(1)

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.

Figure 1
figure 1

Basic model for PDR algorithm. Starting from the user's initial position (x0, y0), we can calculate the next position, notated as (x1, y1), by utilizing the heading angle θ1 and the displacement d1. Based on the iterative process of position calculation, the coordinates of the user's k th position are calculated by (1).

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.

Figure 2
figure 2

System architecture. We propose a new PDR-based navigation algorithm using MARG sensors which are equipped in commercial smartphone.

3 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).

Acc _ norm = a x 2 + a y 2 + a z 2
(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

ΔT > T Th Acc _ norm g > A Th
(3)

where ΔT stands for the time interval between every two adjacent peaks, g is the local acceleration of gravity. TTh and ATh stand for the time threshold and the peak threshold, respectively.

Figure 3
figure 3

Modulus values of accelerometer. Some small jitters could be produced during the walking when the pedestrian is holding the phone. The false peaks appear in the output waveform of accelerometer modulus values.

We use the empirical model [16, 17] to estimate the stride length in (4).

step _ length = C × A max A min 4
(4)

where Amax and Amin 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.

Figure 4
figure 4

Structure of BP neural network. There are two input layers of neurons and one output layer of neurons. The number of neurons in the hidden layer is determined in the process of neural network training.

4 Heading estimation

4.1 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

Q = 1 2 Q W , Q t 0 = Q 0
(5)

where the quaternion Q = q0 + q1i + q2j + q3k, q i (i = 0, 1, 2, and 3) is a real number. t0 is the initial time of the user's movement. Q0 is the initial quaternion. W = 0 + w1i + w2j + w3k 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

Q = q 0 q 1 q 2 q 3 = 1 2 0 ω 1 ω 2 ω 3 ω 1 0 ω 3 ω 2 ω 2 ω 3 0 ω 1 ω 3 ω 2 ω 1 0 q 0 q 1 q 2 q 3 = 1 2 Ω ω Q
(6)

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

Q k + 1 = exp 1 2 Ω ω T s Q k = I cos Δθ 2 + Ω ω T s sin Δθ 2 Δθ Q k
(7)

where Δθ = T s ω 1 2 + ω 2 2 + ω 3 2 . Based on the relationship between attitude rotation matrix and quaternion, the rotation matrix can be calculated as

T n b = q 0 2 + q 1 2 q 2 2 q 3 2 2 q 1 q 2 + q 0 q 3 2 q 1 q 3 q 0 q 2 2 q 1 q 2 q 0 q 3 q 0 2 q 1 2 + q 2 2 q 3 2 2 q 2 q 3 + q 0 q 1 2 q 1 q 3 + q 0 q 2 2 q 2 q 3 q 0 q 1 q 0 2 q 1 2 q 2 2 + q 3 2
(8)

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

roll = arcsin ( 2 q 2 q 3 q 0 q 1 ) pitch = arctan 2 q 1 q 3 + q 0 q 2 q 0 2 q 1 2 q 2 2 + q 3 2 yaw = arctan 2 q 1 q 2 + q 0 q 3 q 0 2 q 1 2 + q 2 2 q 3 2
(9)

4.2 Extended Kalman filter design

In practical use, the attitude angles collected from the gyroscope may start from incorrect initial conditions. 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).

X k + 1 = F X k + W k Z k + 1 = H X k + 1 + V k + 1
(10)

Using the discrete time model to update attitude angles, the state vector can be described by the rotation quaternion. The state transition vector equation is shown in (11).

Q k + 1 = F Q k + w k
(11)

where F = exp 1 2 Ω ω T s 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 = T n b Q k + 1 0 0 T n b Q k + 1 g h + v k + 1 a v k + 1 m
(12)

where T n b 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 avk + 1 and mvk + 1 which can be recognized as the uncorrelated zero-mean white noise processes with the corresponding covariance matrix R.

g = 0 0 1 T
(13)
h = 0 b y b z T
(14)
R = 0 σ a 2 I σ m 2 I 0
(15)

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

H = 2 q 2 2 q 3 2 q 0 2 q 1 2 q 1 2 q 0 2 q 3 2 q 2 4 q 0 0 0 4 q 3 2 b y q 3 2 b z q 2 2 b y q 2 + 2 b z q 3 2 b y q 1 2 b z q 0 2 b y q 0 + 2 b z q 1 4 b y q 0 + 2 b z q 1 2 b z q 0 4 b y q 2 + 2 b z q 3 2 b z q 2 2 b y q 1 + 4 b z q 0 2 b y q 0 2 b y q 3 2 b y q 2 + 4 b z q 3
(16)

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 σ a 2 and σ m 2 for the sake of modifying the weight of measurement values in a real-time manner. This process is illustrated in (17) and (18).

σ a 2 = k a 1 | | a k | | | | g | | + k a 2 var a k N / 2 | | : | | a k + N / 2
(17)
σ m 2 = k m 1 | | m k | | | | h | | + k m 2 var m k N / 2 | | : | | m k + N / 2
(18)

where ||a k || and ||m k || are the modulus values of accelerometer and magnetometer. ki 1 and ki 2 are the weighting factors. var(ikN/2: ik + 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, σ a 2 and σ m 2 , to guarantee that the filtering process is determined by the output of gyroscope.

4. 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° 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.

Figure 5
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°.

Figure 6
figure 6

Results of corrected heading angles. After the low-pass filtered rotation matrix is obtained, the corrected heading angle can be calculated.

5 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.

Figure 7
figure 7

Hand-held smartphone during walking. The smartphone is hand-held with the X-axis in left direction, Y-axis in backward direction and Z-axis in down direction during the walking.

5.1 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%.

Figure 8
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.

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.

Table 1 Results of stride length estimation

5.2 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 9
figure 9

Variations of magnetometer modulus values. 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.

Figure 10
figure 10

Results of heading angles. The Reference indicates the direction of testing path. The heading angles estimated by GDA are obtained by using gradient descent algorithm. The heading angles obtained by our proposed algorithm are shown by EKF curve.

5.3 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.

Figure 11
figure 11

Walking trajectory. We choose the playground in CQUPT as the testing bed to examine the positioning accuracy of our proposed algorithm. 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.

Table 2 Tracking results

6 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 [1820]. Furthermore, the optimization of heading estimation algorithm forms another interesting work in future.