A Novel Method of Adaptive Kalman Filter for Heading Estimation Based on an Autoregressive Model

: With the popularity of smartphones and the development of microelectromechanical system (MEMS), the pedestrian dead reckoning (PDR) algorithm based on the built-in sensors of a smartphone has attracted much research. Heading estimation is the key to obtaining reliable position information. Hence, an adaptive Kalman ﬁlter (AKF) based on an autoregressive model (AR) is proposed to improve the accuracy of heading for pedestrian dead reckoning in a complex indoor environment. Our approach uses an autoregressive model to build a Kalman ﬁlter (KF), and the heading is calculated by the gyroscope, obtained by the magnetometer, and stored by previous estimates, then are fused to determine the measurement heading. An AKF based on the innovation sequence is used to adaptively adjust the state variance matrix to enhance the accuracy of the heading estimation. In order to suppress the drift of the gyroscope, the heading calculated by the AKF is used to correct the heading calculated by the outputs of the gyroscope if a quasi-static magnetic ﬁeld is detected. Data were collected using two smartphones. These experiments showed that the average error of two-dimensional (2D) position estimation obtained by the proposed algorithm is reduced by 40.00% and 66.39%, and the root mean square (RMS) is improved by 43.87% and 66.79%, respectively, for these two smartphones.


Introduction
Location-based-services (LBSs) have developed rapidly in recent years, and their application brings great convenience to people's lives [1]. The core idea of LBSs is to determine a user's location quickly and effectively [2]. Outdoors, the global navigation satellite system (GNSS) provides accurate and reliable locations in open-sky environments, but it faces the challenges of signal blockage and invisibility in an indoor environment. With the development of indoor positioning technology, various positioning methods, based on WiFi [3], Bluetooth [4], ultra-wide band (UWB) [5], and inertial sensors [6], have been applied for personal navigation, emergency rescue, and tracking [7]. With the popularity of smartphones and the development of microelectromechanical system (MEMS), indoor positioning technology based on smartphones has found wide application in pedestrian navigation [8].
MEMS inertial sensors have become an appropriate choice for pedestrian navigation because they are small, low-cost, and completely autonomous [9]. Pedestrian navigation based on inertial measurement units (IMUs) can be divided into two categories [10]. One is the strap-down inertial navigation system (SINS) and the other is pedestrian dead reckoning (PDR) based on a human-motion by fusing these headings calculated by the gyroscope, obtained by the magnetometer and stored by the previous estimate-is used as the measurement of KF. Taking into account model function error and inaccurate prior noise, AKF is used to improve the accuracy of heading estimation. The change rate of the total magnetic field is used to detect its QS, and the heading calculated by gyroscope is corrected by the feedback of the estimated heading by AKF in QS. In order to intuitively and precisely express the accuracy of heading estimation, the estimated heading was used for the position estimation of PDR. Two kinematic experiments are used to verify this algorithm.

Heading Estimation Based on an AR Model
A smartphone contains a variety of sensors, and it is an effective device for pedestrian navigation. When a smartphone is used for navigation, it is held in the hand more than 87% of the time [26], so we assume that the heading of a pedestrian is consistent with the smartphone in this paper. That phone is held in the hand of a pedestrian. The heading is determined by the KF based on AR model in this paper.

KF Process
The state equation and measurement equation of a linear discrete KF system can be expressed as where x k−1 and x k represent the state vector at times k − 1 and k, respectively; Φ k,k−1 is the state transition matrix; z k is the measurement vector; H k is the measurement matrix; and w k−1 and v k are zero-mean white noise, whose variances can be expressed as Q k−1 and R k , respectively.

AR Model
The AR model not only satisfies the polynomial constraint of state variables, but also can reduce the noise by the criterion of minimizing the mean-square error (MMSE) using redundant observations [33]. In order to enhance the accuracy of heading estimation, we use the AR model to build KF.
Here, we suppose that the current heading can be predicted by the previous S samples: where att k is the current heading and h s is the coefficient matrix of the AR model. Without loss of generality, the current heading can be fitted by L polynomials, where a l is the coefficient matrix of polynomials, t k = kT, and T is the sample interval. Substituting Equation (3) into Equation (2), we can obtain When l= 0, we can obtain the equation as follows Similarly, the recursive expression of Equation (4) can be obtained by S s=1 h s s l = 0, l = 1, 2, ..., L In summary, Equations (5) and (6) can be expressed in matrix form as follows. where When S = L + 1, the matrix A is nonsingular, and Equation (7) has a unique solution. When S > L + 1, the AR model has redundant observations. Namely the AR model not only satisfies the polynomial constraint but also can reduce the noise by extra observations.

Derivation of AR Model under KF Frame
In this section, the AR model is introduced into KF. The state equation of KF based on the AR model can be expressed as follows, where x AR k−1 = att k−1 att k−2 · · · att k−S T , w AR k is the state noise, its variance matrix is Q AR k , and the state transition matrix is Therefore, KF based on AR model prediction can be expressed as follows.
where P is the state variance matrix, C k is the variance matrix of the innovation sequence, and K is the gain matrix.
We know from Equations (11)-(16) that KF based on the AR model needs to know µ k . A cost function based on MMSE can be constructed as follows Equation (17) can be solved by the Lagrangian multiplication operator [34] where λ is a Lagrange multiplier.
Taking the partial derivatives with respect to µ k and λ for Equation (18) and setting them to zero. We can get We can obtain µ k by solving Equation (19), We can see from Equation (20) that the solution of µ k uses the information polynomial and state variance. Thus, compared to traditional KF, KF based on the AR model can effectively reduce the noise.

The Adaptive Kalman Filter
KF based on the AR model can work well if the model function and noise statistic are both accurately known. However, the model function is an approximate expression. Moreover, a smartphone may be shaken due to human motion when the pedestrian is holding the smartphone for navigation, which makes the noise statistic unreliable. Therefore, it is necessary to adaptively adjust the noise for obtaining reliable filtering results.
To reduce the influence of inaccurate state noise, we use an adaptive method based on the innovation sequence to adjust the state covariance matrix [35].
Substituting Equation (14) into Equation (16), we can get Substituting Equation (12) into Equation (21), the state noise covariance can be got as follows.
We can get the approximate solution of the state noise covariance based on Equation (22).
The covariance matrix of innovation can be obtained by averaging the innovation sequence over N windows.Ĉ where v k = z k − H k x k,k−1 is the innovation vector.

The Calculation of Measurement Vector for Heading Estimation
In this section, we discuss the calculation of measurement vector in KF for heading estimation. In general, two methods are used to calculate the heading. One is based on the outputs of the magnetometer, and the other is obtained from raw gyroscope data

Heading Estimation by Magnetometer
The accelerometer, that measure specific force, can be used to obtain roll and pitch, and the heading can be solved by the leveled magnetic field intensity that is obtained by using roll and pitch. Many references discuss the solution of roll and pitch using acceleration, so we mainly discuss the heading calculated by magnetometer in this section. In this paper, the smartphone axis is show in Figure 1. Due to the building structure and materials, the magnetic field is more susceptible to contamination by hard iron, soft iron, and scale factors. This causes bias in magnetometer outputs; hence it is necessary to calibrate the magnetometer. The commonly used calibration method is ellipsoid fitting [36,37].
After the magnetometers are calibrated, the heading can be solved from calibrated magnetic field intensities. Firstly, the magnetic field intensities can be leveled by roll and pitch.
where m x , m y , m z and M x , M y , M z are the geomagnetic field intensities in the body frame and navigation frame, respectively, and γ and θ are the roll and pitch, respectively, calculated from the raw acceleration data. Then, taking into account the local magnetic declination, the heading can be calculated by: where ψ mag is the heading and D is the magnetic declination. γ and θ, calculated by accelerations, can be expressed as follows: θ= −arctan a y a x * sin(γ) + a z * cos(γ) where a x , a y , a z are the accelerations in the body frame.

Heading Estimation Based on Gyroscope
The relative heading can be calculated using the raw outputs of a gyroscope, and the absolute heading can be obtained when the initial heading is known. The quaternion heading can be directly derived from the outputs of the gyroscope [25].
where • q is the differentiation of the quaternion, ω is the angular rate measured by gyroscope, and M(•) is the mathematical function of ω.
The quaternion-based update with the angular rate can be obtained from the discrete form of Equation (29), where η = (ω x dt) 2 + ω y dt 2 + (ω z dt) 2 , dt is the sampling interval, and I is unit vector. In this paper, the interconversion between quaternion and the Euler angle is required. Their relationship can be expressed as follows.

Fused Heading Estimation
The heading estimated by single sensor is noisy due to sensor performance and external disturbance, and a reliable heading can be determined by fusing headings calculated by different sensors [22]. A heading estimation by fusing these headings that are calculated by a magnetometer, obtained by gyroscope and stored by previous estimate can be expressed as follows. where where β prev , β mag , and β gyro are the respective weights of the heading stored by the previous estimate, the heading calculated by the outputs of the current magnetometer and the heading obtained by the gyroscope-ψ mag k is the current heading calculated by Equation (26), ψ gyro k is the current heading calculated by Equation (31), ψ prev k−1 is the heading of previous time updated by KF, ψ cor δ and ψ mag δ -are thresholds.

The Filter Design of KF Based on AR Model for Heading Estimation
In this paper, KF based on AR model is used to estimate the heading. In Section 2, the AR model is introduced to build KF for heading estimation, and the heading measurement is introduced in Section 3. In this section, we sum up the process of KF for heading estimation. In this paper, the current heading is predicted by the previous four samples in AR model constructed in Section 2, so S is set as four. The fused heading presented in Section 3.3 is used for the measurement of the KF update. The state and measurement equations of KF based on AR model for the proposed heading estimation can be expressed as follows, The state model can be obtained by k,k−1 is the state transition matrix that can be obtained by Equation (10). att + k−1 is the estimated heading at time k − 1, att − k is the predicted heading at time k. The measurement model can be calculated by where, Z AR k = ψ k that can be calculated by Equation (32), H AR k = 1 0 0 0 1×4 . In this paper, Equations (38) and (39) were constructed to predict and update the KF for heading estimation.

The Detection of a QS Magnetic Field
The geomagnetic field suffers severe perturbations in indoor environments, causing the magnetic field magnitude to not be constant. However, locations are possible where these magnetic field magnitudes are constant, and these situations can be considered as QS [38]. The heading calculated by magnetic field intensity in QS can achieve an accurate result. In this paper, the change rate of the magnetic field intensity is used to detect QS.
The detection model based on the change rate of magnetic field magnitude is expressed as where • m k is the change rate of magnetic field magnitude and v k is noise. The magnetic field can be considered as QS if o k = 0. Therefore, the detection of QS can be expressed as a binary hypothesis test. Here, the two hypotheses H 0 and H 1 are The probability density function (PDF) of Equation (40) based on hypothesis H 0 can be given by where σ 2 o k is the noise variance of o k . We assume that the maximum likelihood estimate (MLE) of o k isô k , which can be obtained by the mean of samples asô Therefore, the PDF of H 0 can be changed to For the hypothesis H 1 , o k = 0, so the PDF of H 1 can be obtained by The detection of QS based on the generalized likelihood ratio test (GLRT) can be expressed as Substituting Equations (44) and (45) into Equation (46), we can obtain Taking the natural logarithm on both sides of Equation (47), we get the test statistics as follows.
where χ m = 2σ 2 o k ln(χ m ) is the threshold and N is the window size. If Equation (48) is true, the magnetic field is considered as QS. Then the heading calculated by Equation (31) can be corrected with the heading updated by Equation (15). Similarly, the roll and pitch can also be corrected with the solution estimated by KF.
The following algorithm is tabulated for expression of the proposed heading estimation.

Algorithm 1:
The heading estimation with KF based on AR model Step 0. Given S, L with S ≥ L + 2. We set S = 4, L = 1.
Step 0.1 Initial state: , where z is the measurement heading calculated by Equation (32).
Step 0.2 Initial state variance matrix P 0 , state noise covariance Q 0 and measurement noise covariance R 0 .
Step 1. Calculation of coefficients matrix: Calculate the coefficient of an AR model by Equation (20), and calculate the state transition matrix by Equation (10 (31) is corrected by the updated heading of Step 3.
Step 5. Terminate the process, otherwise return to Step 1.

The Principle of PDR Algorithm
The PDR algorithm includes four procedures: Step detection, step-length estimation, heading estimation, and position calculation. In this paper, peak detection is used for step detection, and the time interval of two peaks is considered as the time of a step. A linear model is used to estimate the step-length [39].
where SL is the step-length, F is the step frequency, v is noise, and a and b are coefficients dependent on human motion. After step detection, step-length estimation, and heading estimation are obtained, the position can be calculated as follows.
where N and E are the north and east direction positions, respectively.

Filter Design of UKF for Position Estimation
In this paper, the position estimation is solved based on the UKF that reference the method proposed in [38]. After the heading is updated and the step-length is estimated, these values can be used to estimate the position based on the UKF.
According to Equation (50), a system model of nonlinear formula can be built as follows: where, ∆ϕ k is the increment of heading at time k, W k−1 is state noise. The measurement equations can be obtained by where, V k is measurement noise. In this paper, Equations (51) and (52) are used to estimate the position at every step. And the calculated process of UKF can be found in [25,40].

Static Experiment
A Huawei Honor V9 (HV9) and XiaoMi8 (XM8) smartphone were used to collect static data. The collection time was about 30 min, and the sampling frequency was 50 Hz. Three methods were used to calculate the heading using these data. The first was the heading calculated by the outputs of the magnetometer (the method discussed in Section 3.1), the second was the heading obtained by a gyroscope (the method introduced in Section 3.2), and the last was the proposed method by this paper. Figure 2 shows the heading error of different methods. The solid line is the error of heading calculated by magnetometer (Mag), and we can see that the margin of error is about 5 degrees even though the data are static in Figure 2a, and the jump range of error is 1 degree for XM8 in Figure 2b. The dashed line is the error of heading obtained by gyroscope (Gyr). The error is low and smooth in the short term, but it gradually accumulates with time, and the maximum error reaches 50 degrees for HV9. The chain line expresses the error of heading estimated by the proposed method that the AKF based on AR is used to estimate heading (ProA). We can see from Figure 2 that the drift error of heading is effectively contained by the proposed algorithm compared with the method of Gyr. Compare with the method of Mag, the error is smooth and accurate for XM8, however, the result of Pro is worse than that of Mag for HV9 with time. We can see from Equation (32) that the accuracy of a heading calculated by Gyr will affect the result of ProA, so the accuracy of ProA is affected by the cumulative error of Gyr in Figure 2a. Comparing Figures 2a and 2b, we found that the heading calculated by XM8 is better than that estimated by HV9. That's because the sensors accuracy of XM8 are better than that of HV9. In summary, the heading calculated by a single sensor embedded in a smartphone still has disadvantages even under great observation.

Kinematic Experiment
The kinematic data were used to further verify the effectiveness of the proposed algorithm. The site of data collection was on the third floor of the J9 office building of Shandong University of Science and Technology, and many iron materials were on site. The floor plan is shown in Figure 3. The tester held the HV9 and XM8 smartphones in their hand to collect data along the preplanned trajectory.  Figure 4 shows the calculated heading that used the data collected by the HV9 and XM8, and true north was used to largely avoid the heading jumps between 0 and 360. Five methods were used for heading estimation in these kinematic experiments. The first was Mag, the second was Gyr, the third was proposed in [22] that the current heading was determined by magnetometer, gyroscope and previous estimate (MGP), the fourth was Pro that is the proposed method in this paper without the adaptive filter, and the last was ProA that the adaptive filter is used in Pro. And the reference is the reference heading in Figure 4. Compared to the other four methods, the heading based on the magnetometer severely jumped for these smartphones, and the maximum jump achieved 30 degrees, although the heading calculated by magnetic field was close to the reference at some locations. Thus, it is not appropriate to obtain the heading just using the outputs of the magnetometer for pedestrian navigation in complex indoor environments.   Figure 4a, and Figure 6 shows the heading errors of the local trajectory of Figure 4b. The heading errors of Mag for HV9 and XM8 are not shown in Figures 5 and 6 because these errors fluctuate widely. However, these statistical results, of heading errors of these five methods for HV9 and XM8, are all shown in Tables 1 and 2, respectively. In Tables 1 and 2, the mean RMSs of heading error for Mag are 8.62 • and 10.88 • for HV9 and XM8, respectively, and these accuracies are not appropriate for pedestrian navigation. In Figure 5a, most heading errors of Pro and ProA are within 4 • , and these heading errors are smaller than those of Gyr and MGP. In Figure 5b-d, these heading errors of Pro and ProA are within 2 • , and these accuracies of heading estimation are better than those of Gyr and MGP. In Table 1, the RMS of MGP is slightly superior to that of Gyr, and the mean RMS decreases from 2.38 • to 2.19 • . The accuracy of Pro is better than that of MGP in every section. The RMS decreases from 2.20 • to 1.74 • in the local trajectory of mark A, the RMS drops from 1.17 • to 1.09 • in the local trajectory of mark B, the RMS reduces from 3.01 • to 1.26 • in the local trajectory of mark C, and the RMS decreased from 2.38 • to 1.55 • in the local trajectory of mark D. And the mean accuracy increased by 35.62%. In Table 1, the accuracy of Pro is basically the same as that of ProA. We also can see from these lists of Mean in Table 1 that these results of heading estimation are bias. The first reason for this bias is that the tester cannot strictly walk in accordance with the preplanned trajectory, and the other is that the smartphone will inevitably shake with the movement of the tester. These conditions can cause the biased estimation. We can see from Table 1, the bias of Pro and ProA is smaller than that of the other methods. In summary, compared with the heading estimated by Mag, Gyr and MGP, the heading solved by the proposed algorithm is close to the reference for this experiment.   Figure 6b-d, these errors of Pro and ProA are principally less than 5 • , and these results of Pro and ProA are superior to those of Gyr and MGP. In Table 2, The RMS of MGP is slightly smaller than that of Gyr, and the mean RMS is decreased by 1.97%. For these two kinematic experiments, the accuracy of heading estimation for MGP is better than that of Gyr, and this conclusion is consistent with that of the literature [22]. We can also see from Table 2 that these accuracies of Pro are better than those of MGP in these four sections. The RMS decrease from 3.45 • to 2.25 • in the local trajectory of mark A, the RMS drops from 3.66 • to 3.28 • in the local trajectory of mark B, the RMS reduces from 5.35 • to 3.39 • in the local trajectory of mark C, and the RMS decreases from 5.51 • to 2.58 • in the local trajectory of mark D. Compared with the mean accuracy of MGP, the mean accuracy of Pro increases by 35.86%. In Table 2, the accuracy of heading estimation is further improved by the adaptive algorithm. The RMS decreases from 2.25 • to 1.70 • in the local trajectory of mark A, the RMS drops from 3.28 • to 2.69 • in the local trajectory of mark B, the RMS reduces from 3.39 • to 2.02 • in the local trajectory of mark C, and the RMS decreases from 2.58 • to 2.19 • in the local trajectory of mark D. Also, the mean of RMS is improved by 25.35% for this kinematic data. Similarly, the biased heading estimation can be observed in Table 2, and the bias of mean for ProA is the smallest among these methods. Compared with these methods of Mag, Gyr and MGP, these methods of Pro and ProA can obtain the higher accuracy of heading estimation.  In order to intuitively and precisely express the accuracy of heading estimation, the estimated heading was used for the positioning estimation of PDR. The method of Mag was not used to estimate the position in this section because the heading accuracy is poor, and we designed four programs to obtain the position estimation of these two kinematic experiments.
(1) The Gyr is used to calculate heading, and UKF is used for position estimation (Gyr-UKF).
(2) The MGP is used to obtain heading, and position is estimated based on UKF (MGP-UKF).
(3) The Pro is applied to estimate heading, and position estimation is obtained by UKF (MGP-UKF). (4) The ProA is applied to estimate heading, and UKF is used for position estimation (MGP-UKF).
We compare the position estimation of these four methods in this section. Figure 7 shows the position trajectories calculated by the outputs of the HV9. We can see from Figure 7 that these position trajectories of Gyr-UKF and MGP-UKF deviate from the reference with time, and the results of position estimation for these two methods are almost identical. The trajectory is improved by the method of Pro-UKF, and the position trajectory of ProA-UKF is basically the same as that of Pro-UKF. Figure 8 shows these trajectories obtained by XM8. We can see that these trajectories of Gyr-UKF and MGP-UKF deviate from the reference with time, and the trajectory of MGP-UKF is slighter better than that of Gyr-UKF. The trajectory is improved by the method of Pro-UKF, and the trajectory is further improved when ProA is used to estimate heading. Therefore, the trajectory calculated by a ProA-UKF algorithm is more accurate than that obtained by the other three methods.  In order to provide a reference at each step, these timestamps were recorded when the tester passed corners, and the coordinates of these corners can be obtained by the reference trajectory and reference heading. The coordinates of each step between these two corners can be calculated by linear interpolation in time. In order to accurately analyze the heading, the step-length error is ignored here. Figure 9 shows the 2D position error of each step using HV9 and XM8. Figure 9a shows the position error of HV9. When the method of Gyr-UKF and MGP-UKF is used, the position error gradually accumulates with the walking distance, and the maximum error exceeds 5.5 m. The estimated position of MGP-UKF is slightly better than that of Gyr-UKF. The position error is improved by the Pro-UKF, and the maximum error is less than 2.8 m. We can also see that the position error of ProA-UKF is slightly smaller than that of Pro-UKF. Figure 9b is the position error of XM8 for different methods. The position error deviates from the reference with time when the Gyr-UKF is used, and the maximum error is over 5.0 m. The position estimation is slightly improved when MGP-UKF is used. The position errors are effectively constrained when the proposed algorithm of Pro-UKF is used, and the maximum error is less than 3.0 m. The position errors are further improved if the adaptive algorithm is used to estimate the heading, and the maximum error is less than 2.0 m. In Figure 9b, the positions accuracy of Pro-UKF is worse than those of Gyr-UKF and MGP-UKF at times. We can see from Figure 6c that the heading error is mostly positive for Pro, that will make the error accumulate, and the heading errors have positive and negative values for Gyr and MGP that will offset the error accumulation. The corresponding position cumulative error estimation percentages (CEF) of Figure 9 is explained in Figure 10. In Figure 10a, the CEF within 1.5 m is 24.92% and 25.24% for Gyr-UKF and MGP-UKF, respectively, and the CEF is raised to 40.38% and 41.01% for Pro-UKF and ProA-UKF, respectively. The CEF within 2 m are 38.80% and 31.86% for Gyr-UKF and MGP-UKF, respectively. The CEF is increased to 68.45% for both Pro-UKF and ProA-UKF. When the CEF is about 75%, the position error is over 4 m for Gyr-UKF and MGP-UKF, and the position error is less than 2.25 m for Pro-UKF and ProA-UKF. For HV9, the proposed method can enhance the accuracy of position estimation. Figure 10b shows the CEF of XM8. In Figure 10b, the CEF within 1.5 m is just 20.79% for both Gyr-UKF and MGP-UKF, the CEF achieves 36.30% for Pro-UKF, and the CEF is, as expected, increased to 97.03% for ProA-UKF. When the position error is within 2 m, the CEF is 38.94% and 47.52% for Gyr-UKF and MGP-UKF, respectively, and the CEF is slight improved for Pro-UKF with 50.50%, however, the CEF is raised to 100% when the ProA-UKF is used. When the CEF is about 75%, the position errors are both over 3.25 m for Gyr-UKF and MGP-UKF, the error is within 2.50 m for Pro-UKF, and the error is less than 1.25 m for ProA-UKF. Therefore, we can obtain the conclusion that the proposed algorithm can improves the accuracy of heading estimation for smartphone.  Table 3 shows the statistics of position errors. In Table 3 where the adaptive filter is used to estimate heading, is better than that by Pro-UKF, the position error of Pro-UKF is smaller than that of the traditional method and the position error of MGP-UKF is slightly superior to that of Gyr-UKF. Compared with the method of MGP, the mean error of ProA-UKF is reduced by 40.00%, and RMS is improved by 43.87% for the HV9. And the mean error is reduced by 66.39%, and the RMS is improved by 66.79% for the XM8. Therefore, the method of heading estimation proposed in this paper can improve the accuracy of heading estimation, and it directly enhances the accuracy of position estimation for pedestrian navigation.

Conclusions
A novel method of heading estimation based on smartphones is proposed in this paper. This method uses the AR model to build KF, and the current heading-determined by fusing these headings calculated by magnetometer, estimated by gyroscope and stored by the previous estimate-is used as measurement value of KF update. To effectively suppress the accumulated error of the heading estimated by the outputs of the gyroscope, the estimated heading by KF in QS is used to correct the heading calculated by gyroscope. To improve the accuracy of heading estimation, an AKF based on the innovation sequence is used to adaptively adjust the state noise covariance. HV9 and XM8 smartphones were used to collect data. In order to intuitively and precisely express the accuracy of heading estimation, the estimated heading is also used for the position estimation of PDR. The following conclusions were obtained, (1) The heading calculated by a magnetometer is susceptible to disturbances in the complex indoor environment that can cause dozens of degrees bias. Also, it is possible that the heading calculated by magnetometer is close to the reference at some locations. The heading estimated by gyroscope is affected by cumulative error. The heading obtained by the proposed method can not only reduce the noise but also constraint the cumulative error. (2) Compared with the mean accuracy of traditional methods for heading estimation, the mean accuracy of the heading estimated by proposed algorithm is increased by 35.62% and 35.86%, respectively, for HV9 and XM8. And compared with KF, AKF can further improve the accuracy of heading estimation. (3) The estimated heading is used for position calculation of PDR. Compared to traditional methods, the mean errors of position estimation for the proposed method decrease by 40.00% and 66.39%, and the corresponding RMS is improved by 43.87% and 66.79%, respectively, for HV9 and XM8 smartphones with different performance sensors.