AN INTEGRATED INDOOR POSITIONING ALGORITHM FOR SMARTPHONE USING PEDESTRIAN DEAD RECKONING WITH MAGNETIC FINGERPRINT AIDED

Indoor positioning has gained increasing attention in previous decades. There are many wireless communication technologies replacing Global Navigation Satellite System (GNSS) because of the sheltered GNSS signal in indoor environment. Most of them need to set up external transceiver with high spatial density to get user's position, such as Wi-Fi, Ultra-Wideband (UWB), Bluetooth and so on. In order to reach high positioning accuracy, the cost of external transceiver becomes higher. This research focuses on low-cost pedestrian dead reckoning (PDR) without additional external equipment. Moreover, a magnetic fingerprint-based positioning is adopted to provide redundant observations of position and heading, using Extended Kalman Filter (EKF) to update the estimation. The proposed method reduces cumulative errors of PDR, achieving an improved algorithm. Since the geomagnetic field exists over the Earth, this technology doesn’t use external equipment either. The integration of PDR and magnetic fingerprint-based positioning, which only uses built-in sensors of a smartphone, should be a low-cost and wide coverage scheme.


INTRODUCTION
Recently, the number of smartphone users has continuously increased. There are 83.7% of the world's population who own the smartphone in 2022, which means the navigation services on the smartphone become more accessible to people. Unfortunately, the GNSS signal would be sheltered in indoor environment, which leads to a challenge of indoor positioning. Since people spend about 90% of time in indoor environment, the requirement of indoor positioning occurs. The smartphone with built-in multiple sensors has high potential to achieve a stable seamless navigation system with desk-level (1-3meters) accuracy. Pedestrian Dead Reckoning (PDR) is widely used in indoor positioning, which uses Micro Electro Mechanical Systems (MEMS) based accelerometers and gyroscopes to estimate the 2D trajectory of pedestrian (Chen, Pei, and Chen, 2011). This technology is a kind of self-contained relative positioning without wireless communication with external transceiver, which has the advantages of low cost and high convenience. Nevertheless, the characteristics of inertial navigation let errors cumulate and the trajectory drift with time. The external update from other sensers should be adopted to solve this problem. The magnetic fingerprint-based positioning technology makes use of the magnetic anomalies caused by the magnetism materials in the buildings, e.g., reinforcing steel. The magnetic anomalies can become unique and stable "fingerprints" in the space, which can be used in matching algorithm. The magnetic fingerprintbased positioning is divided into two phases, i.e., offline and online phase (Gong et al., 2018). In offline phase, the magnetic field is collected, and the magnetic map is generated. In online phase, the real time measurement can be matched with the offline magnetic map; thus, the absolute positioning is achieved. This research makes the following contributions: 1. Develop the procedures of data collecting, magnetic fingerprint extraction and offline magnetic map generation in an efficient way. 2. Propose a PDR based pattern recognition method, which divides the trajectory of pedestrian in several parts. The patterns and the corresponding magnetic series are used to be matched with offline magnetic map. 3. Propose a heading correction method using the magnetic orientation information in offline map to provide the reference and compensate the magnetic anomalies. 4. Develop the integration scheme using Extended Kalman Filter with the position and heading update from magnetic fingerprint-based algorithm. The rest of this paper is organized as follows: Section 2 provides the details of methodology, including offline magnetic map generation and online integrated positioning scheme. Section 3 describes the field and the architecture of experiment. In Section 4, the result of proposed method is presented. Finally, Section 5 comes up with the conclusion.

METHODOLOGY
The overall process of the magnetic fingerprint-based positioning is shown in Figure 1. The observed magnetic vector should be projected to the gravity direction and be decomposed into vertical and horizontal component (Li et al., 2012) so as to extract a rotational invariance, i.e., the fingerprint. In addition, the extracted horizontal component should be transformed into a level frame, that the orientation of horizontal component relative to the known heading of device can be obtained. As a side note, the gravity vector can be extracted from accelerometer by using low pass filter (Yun, Bachmann, and McGhee, 2008).
In offline phase, the extracted fingerprint is used to generate the magnetic feature map and orientation map. In online phase, the real time extracted fingerprint is matched with the offline feature map to get the absolute position; moreover, the heading correction is conducted by using orientation map to compensate the magnetic anomalies in indoor environment. The details of offline map generation are provided in Section 2.1. The online magnetic fingerprint-based positioning and the proposed integration scheme with PDR are organized in Section 2.2.

Offline Magnetic Map Generation
The procedures of vector projection, dimension reduction and transformation introduced in this Section is applied in offline phase as well as online phase. Conversely, the strategy of data collection and calibration is specific to offline phase.

Vector Projection and Dimension Reduction
The magnetic field M(x, y, z) sensed by triaxial magnetometer is defined in body frame of the sensor, which means the results change with the orientation of sensor. In order to extract the fingerprint, the roll, pitch, yaw (heading) angle of 3 axes should be known to transform the magnetic field from body frame to navigation frame, e.g., Local-Level Frame (ENU). Since it is unreliable for smartphone to estimate the orientation by using MEMS gyroscopes only; moreover, the heading angle estimated by magnetometer is distorted by the magnetic anomalies, the transformation is invalid. The magnetic heading can only be used after the procedures in Section 2.1.2 and Section 2.2.3. In this research, a vector projection is used to replace conventional transformation method. Figure 2(a) shows the projection from magnet vector M to gravity vector g. The magnet vector can be decomposed into vertical V component and horizontal component H, which is a rotationally invariant fingerprint. Even though the dimension of M is reduced, the 2D magnetic information is enough for matching, and the fingerprint becomes more reliable.

Horizontal Component Transformation
For the purpose of magnetic heading estimation, it is necessary to get the orientation of horizontal component H. In other words, H should be transformed into a level frame so that the magnetic heading angle can be estimated. Ideally, a hand holding smartphone is supposed to be level, i.e., the roll and pitch angles are equal to zero. Based on this assumption, the component of H contains only x and y axis, the heading can be calculated by equation (1). Practically, the roll and pitch angles are not equal to zero, and the angles vary with walking. Figure 2(b) shows the roll and pitch angles of x axis and y axis. Using the gravity in body frame can not only extract the H vector but also determine roll and pitch angles as the equation (2) and equation (3) show. In this case, the H ( , , ) in body frame can be transformed into level frame H ( ′ , ′ , 0). After the transformation, the , in equation (1) can be replaced by ′ , ′ ; therefore, the magnetic heading angle, which is independent of gyroscope can be estimated.

Strategy of Data Collection in Offline Phase
In this research, the experimental fields are divided into several regular grids. It is intuitive and accurate to collect the data in each center of grid, but this procedure is inefficient. Another common strategy is showed as Figure 3. Walking along the red lines with an assumption of constant speed, dividing data by time and averaging the data in each interval, the approximate results can be obtained. The feasibility of this strategy is evaluated in Section 3.1.1. Furthermore, the error model of magnetometer, which can be expressed as equation (4) (Fang et al., 2011), should be considered in the design of strategy. The , , matrix can be combined into a matrix, which would scale the output. Since the effect of generally smaller than the effect of bias. A simplify calibration method is proposed to reduce errors without pre-processed 8 shaped movement (Grand and Thrun, 2012).
Take the x axis for example, the formula can be expressed as equation (5). By collecting the data in two opposite directions respectively, e.g., rotating 180 degrees on z axis, the bias of x and y axis can be eliminated.  Figure 4 shows the effect of bias in map generation. Collecting the data in S shaped, i.e., collecting the data of adjacent line by reverse direction is the most efficient strategy. Unfortunately, the bias of x and y axis effect on the horizontal component oppositely in two reverse directions, which leads to discontinuous strips on the map. The uncalibrated bias of magnetometer is extremely significant for map generation. Therefore, the simplify calibration method as equation (5) is implemented in the strategy. Each line would be collected both back and forth to eliminate the bias of x and y axis. The calibrated horizontal component is suitable for heading correction, i.e., generates the orientation map.
On the other hand, the bias of z axis is retained. Since the x axis nearly point upward in both offline phase and online phase, the trend and feature of vertical component would not change with heading. The difference between two phases is approximately systematic, that the matching scheme still can work.

Magnetic Feature Map and Orientation Map
Adopt the strategy mention in Section 2.1.3, the data can be divided into grids and be calibrated. The magnetic feature map can be generated after the procedure mention in Section 2.1.1. the vertical and horizontal component of each grid is stored. Also, the magnetic orientation map stores the heading angle of horizontal component of each grid, which is calculated by the procedure mention in Section 2.1.2 and is estimated with reference to the known heading of smartphone in offline phase. Figure 5 shows the flow-chart of integration scheme based on PDR, which provides a continually relative positioning (Chen, Pei, and Chen, 2011) by using step detection, step length estimation and heading estimation. The PDR becomes the prediction in EKF, and the magnetic series matching (Gong et al., 2018) becomes a position update. A 2D matching scheme, which uses the predicted trajectory to generate a specific pattern is proposed in this research. By sliding the pattern in feature grid map, the 1D series matching is conducted and the 2D positioning is achieved. The magnetic heading estimated from online phase and the heading correction from offline phase become a heading update. The EKF thus works and integrates PDR and magnetic fingerprint-based positioning to get an optimal estimation.

Pedestrian Dead Reckoning
PDR is a continually relative positioning, using the position of last step to estimate the position of next step. The model can be expressed as equation (6) and (7) (Chen, Pei, and Chen, 2011). The heading is calculated by integrating angular rate from gyroscopes. Accelerometers is used to detection the steps of pedestrian by recognizing periodic signal, which is the summation of 3 axis acceleration subtracts the gravity. Figure 6 shows the illustration of step detection. The crests and troughs of signal is observed, and the timing of closest zero after a pair of peak and valley is chosen as the end of one step. Finally, the step length is estimated by using the model as equation (8), which considers the user height and step frequency. By integrating heading estimation, step detection and step length estimation, the heading and displacement of each step is estimated.

Magnetic Fingerprint Matching
A Dynamic Time Warping (DTW) based series-to-series matching method is adopted in magnetic fingerprint matching because the point-to-point matching may mismatch in some featureless area. A prerequisite of DTW is that two series should have the same reference. In fact, the magnetic series is a time series, but magnetic field varies spatially. Since the offline map is in spatial domain, the online magnetic series has to be transformed from time domain into spatial domain (Gong et al., 2018). Based on this method, an extended 2D matching method is proposed. As Figure 7 shows, the trajectory from PDR can be transformed into a specific pattern, such as pink grids. These grids can change the magnetic series into spatial domain by using the time of steps t and the time of intersection T to resample the series. The transformed magnetic series with spatial pattern is used to match with offline map. In practice, the spatial pattern is slid through the whole map to extract the corresponding grids in difference position. The extracted corresponding grids constitutes the offline series. Therefore, the DTW based series-to-series matching is conducted to the find out the optimal position.  Figure 8 describes the concept of magnetic heading correction, dealing with the issue that magnetic field does not point to North in indoor environment. The magnetic anomalies are recorded in offline phase, and be compensated in online phase after the positioning is done. In other words, the heading of magnetic field is stored in grids by the procedure in Section 2.1.2 so as to provide a corrected reference for measured magnetic heading. As the equation (9) shows, the heading of magnetic field is derived from the known heading of smartphone in offline. Therefore, the measured heading is corrected by using as the equation (10) shows.

Extended Kalman Filter
The states matrix and motion model of EKF is designed as equation (11) shows. The heading change ∆φ is the integration result of gyroscope output, which is the change angle in 0.1 second. The step length S has value only if the step is detected. Otherwise, S is equal to 0. Linearizing the equation can get the transition matrix and estimate the quality of prediction, i.e., P matrix. It is crucial that how to determine the quality of new measurement, i.e., R matrix so as to update the system. Since the heading update per step, but the position update per 3 steps, there are two R matrixes respectively. The R matrix of position is determined by using an index, cumulative distance of DTW, to evaluate the quality of matching. Multiply the cumulative distance by a fine-tuned ratio to adjust that index. On the other hand, the quality of heading can be derived from the error propagation of magnetometer. Nevertheless, the quality of heading correction should be considered. Using P matrix to estimate the positioning error, which means the uncertainty of the using of orientation map. The average gradient of orientation in that uncertainty area is adopted to multiplied by the positioning error so that the R matrix of heading can be estimated.
where φ = heading ∆φ = heading change X, Y = local Cartesian coordinates S = step length t denotes time (sampling rate = 10 Hz)

Preliminary Test of Data Collection
A preliminary test is conducted to compare the strategy of data collection. The experimental field is a small classroom with the length of 12 m and the width of 8 m in National Cheng Kung University (NCKU). This area is divided into 8 by 12 grids, which have the length of 1m. The magnetic feature map collected grid by grid is showed as Figure 9(a), and the map collected by walking along the line is showed as Figure 9(b). Both of them are calibrated by collecting data back and forth. By using correlation coefficient (CC), the similarity of two maps can be checked.

Preliminary Test of Electro-Magnetic Effect
Since the electrical device would cause magnetic anomalies because of the magnetic effect of electric current. Different from the magnetic anomalies caused by building, the electrical devices, such as laptop can be moved around, which may lead to an unstable magnetic feature. A preliminary test is designed to evaluate the effect from laptop. The experimental field is a corridor. Use wood shelf to put the laptop in different distance as Figure 10 shows, and walk through the laptop holding the smartphone with a height of 90 cm. The path with a length of 7 m is divided into 14 grids, and the magnitude of magnetic field (μT) of each grid is showed as Figure 11. The result descripts that the trend and the feature of 5 different tests is similar to each other. Even if the small difference exists, it appears to be system errors, uncalibrated bias, that would not defeat magnetic fingerprint matching. The electro-magnetic effect should be insignificant. The effect becomes significant only if the smartphone contact laptop directly. The magnitude of magnetic field can increase tens of μT.

Magnetic Map Generation
The main experiment is conducted in the underground parking garage below the library of NCKU, which is an indoor environment with the length of 38 m and the width of 7 m as Figure 12 shows. This area is divided into 7 by 38 grids, which have the length of 1m. The smartphone Xiaomi Mi 8 is used, logging the data of accelerometers, gyroscopes and magnetometer by AndroSensor APP. The offline magnetic feature map and orientation map is generated by using the proposed strategy in 2020/Dec./10 and 2021/Aug./04, respectively as Figure 13 shows. There are 8 months between two maps, but they have high similarity. This result verifies the temporal stability of magnetic anomalies is enough for the propose of fingerprint matching.

Online Test with 5 Different Paths
An online test of proposed integrated positioning algorithm is conducted with the designed 5 different paths. Path 1 and path 2 are tested in 2021/Jan./13, Path 3 is tested in 2021/Jan./21 and Path 4 and path 5 are tested in 2021/Mar./9. The range of test distance is about 37 to 78. The conventional PDR algorithm would be implemented to compare with proposed algorithm. Both of two maps generated in different time would be used and be compared. In Section 4, the detail of the result is presented and discussed. Figure 14 displays the results of online test with 5 different paths, where the gray rectangle is the coverage of magnetic map, the reddish-brown grids are the ground truth of designed paths. The results in left hand side use the map generated in in 2020/Dec./10 (map (a)), and the results in right hand side use the map generated in in 2021/Aug./04 (map (b)). The green trajectories are the results of the original conventional PDR algorithm, which use accelerometers and gyroscopes only. The trajectory drift with time and distance significantly, which is caused by the low-cost MEMS gyroscopes. The blue trajectories are the results of EKF integrated algorithm, and red points are the position update provided by magnetic fingerprint matching. The improvement of proposed algorithm is significant; moreover, the results using two maps perform similarly.

RESULTS AND DISCUSSION
Compared the trajectories to the designed ground truth, the overall positioning errors are smaller than about 2m. The errors of endpoints are calculated as Table 1 shows. The results using map (a) is smaller than 1m, and the mean error is 0.66m. The results using map (b) is smaller than 1.6 m, and the mean error is 0.87m. The performance of map (b) is inferior to map (a), but the overall improvement compared with original PDR is about 90%, and the mean ratio of error to path distance is about 1.3%. The reason why map (a) performs better is that the time of generation is closer to the time of online test. Nevertheless, the results show the stability of magnetic anomalies again. It is reasonable to update the magnetic map in an about half-year period.
The proposed algorithm has a large improvement on account of the worst heading of original PDR. In other words, the main contribution of this algorithm is the reduction of the cumulative errors in original PDR, especially in heading. Path 5 Figure 14. The online test with 5 different paths

CONCLUSION
This research focus on the development of magnetic fingerprintbased positioning and the integration with PDR. A smartphone based self-contained positioning algorithm is proposed to reduce the cost and become user-friendly. The 2D magnetic fingerprint matching, magnetic heading correction and the integration with PDR is the main contribution. The results of online tests demonstrate that it is suitable for the indoor positioning to use this integrated positioning algorithm, and the positioning accuracy can reach desk-level (1-3meters). Furthermore, an efficient procedure of offline magnetic map generation is developed, and the accuracy can meet the requirements. In this case, the magnetic map is generated by smartphone. Since the magnetic map has a high potential for navigation application, the high-level magnetometer, such as HMR2300 can be used to generate the map. By using the complete error model of magnetometer, a high accuracy magnetic map can be achieved, which might be attached to the HD-map, providing more spatial information for autonomous applications.