A Hybrid Dead Reckon System Based on 3-Dimensional Dynamic Time Warping

In recent years, using smartphones for indoor positioning has become increasingly popular with consumers. This paper presents an integrated localization technique for inertial and magnetic field sensors to challenge indoor positioning without Wi-Fi signals. For dead-reckoning (DR), attitude angle estimation, step length calculation, and step counting estimation are introduced. Dynamic time warping (DTW) usually calculates the distance between the measured magnetic field and magnetic fingerprint in the database. For DR/Magnetic matching (MM), we creatively propose 3-dimensional dynamic time warping (3DDTW) to calculate the distance. Unlike traditional DTW, 3DDTW extends the original one-dimensional signal to a two-dimensional signal. Finally, the weighted least squares further improves indoor positioning accuracy. In the three different experimental scenarios—teaching building, study room, office building—DR/MM hybrid positioning accuracy is about 3.34 m.


Introduction
Because of the popularity of smart devices, mobile location-based services are required to provide real-time, highly reliable, and high-precision indoor positioning.Indoor positioning technology has been widely investigated by researchers [1][2][3].The global satellite navigation system cannot solve indoor positioning problems.Therefore, people are trying to find other techniques to solve them.
Indoor positioning techniques are usually divided into two categories: infrastructure-based positioning and infrastructure-free positioning.
Positioning technique using infrastructure, especially widely used Wi-Fi positioning, is attracting increased attention.To reduce the time and labor costs of constructing a Wi-Fi database, a crowdsourcing-based algorithm is presented to estimate access point localization and propagation parameters [4].An actual Wi-Fi indoor positioning system is deployed at the COEX complex in Korea [5].Test results reveal a positioning accuracy of 5 to 8 m.Because of the multipath and the reflection effects, the quality of the Wi-Fi signals depends on the distribution and number of access points and the transmission environment.Another practical problem is that Wi-Fi positioning consumes an inordinate amount of electricity, making it difficult for smartphones to provide long-term positioning.Therefore, this paper presents an indoor positioning technology without Wi-Fi.
The infrastructure-free positioning technique is mainly an inertial positioning system, which obtains a user's position by integrating acceleration and angular velocity.Compared with Wi-Fi, an inertial positioning system is free from external interference.However, heading drift is unavoidable in an inertial positioning system.Combined with wall information, an auxiliary particle filter is proposed to eliminate the heading drift of the inertial sensor [6].Furthermore, the literature [7] proposes a firefly particle filter to reduce the inertial accumulation error.MM determines a pedestrian's location by matching the magnetic field fingerprint in the database.Compared with Wi-Fi, an indoor magnetic field is stable [8].The indoor ferromagnetic material [9] interferes with the geomagnetic field, causing the magnetic field to vary with position.Binghao Li et al. discussed the feasibility of using a magnetic field for positioning [10].Based on alternating current magnetic fields, a method for indoor navigation is proposed [11].However, some beacons must be deployed, which increases positioning costs.For MM, magnetic field mismatch is an unavoidable problem.Based on inertial and magnetic sensors, the MALoc system proposes an actual magnetic field fingerprinting technique [12].However, the system positioning error depends on the number of particles in the particle filter and the gyroscope reading.To take full advantage of the inertial and magnetic sensors, a DR/MM integrated algorithm is proposed to improve indoor positioning accuracy and robustness.In the integrated positioning system, we use DR results to constrain the magnetic field matching range.In DR/MM, we creatively propose 3DDTW to calculate the distance.Therefore, the main contributions of this article are as follows: (1) Integrated indoor positioning system does not require infrastructure to be deployed, greatly reducing the time and money costs.(2) DTW is usually calculated the distance between the measured magnetic field and magnetic fingerprint in the database.For DR/MM, we creatively propose 3DDTW to calculate the distance.Unlike traditional DTW, 3DDTW extends the original one-dimensional signal to a two-dimensional signal.(3) Many practical problems are considered in the DR/MM positioning system.The solutions to these problems further improve the positioning accuracy.For three different walking experiments, the average positioning accuracy is about 3.34 m.
The rest of the paper is organized as follows: We review the related work in Section 2. We introduce the system model in detail in Section 3. Walking experiments to test different scenes are discussed in Section 4. The conclusion and future work are presented in Section 5.

Related Work
In [13], foot-mounted inertial measurement units are developed to locate an indoor pedestrian location.When a user is walking, 'Heading Update' eliminates heading drift in rectangular buildings.During a non-walking situation, 'Zero Integrated Heading Rate Update' reduces heading drift.'Height Update' limits the error growth in height.These constraints appropriately reduce the drift of low-cost inertial sensors; however, the error of the inertial sensors continues to accumulate over time.Using an indoor floor map, Fan Li et al. designed an end-to-end positioning system integrating step detection, stride length estimation and heading inference models [14].Results show an average accuracy of 1.5 m with handheld smartphones and 2 m in the pocket.Map information effectively suppresses cumulative error growth.However, for large buildings, the acquisition of maps is very time-consuming.An end-to-end positioning system is lost for indoor positioning without maps.A hybrid system, integrated smartphone inertial sensors and iBeacon, is proposed to locate and track pedestrian paths in an indoor environment [15].Step detection, walking direction estimation, and initial point estimation are studied.Because of the computational burden of a particle filter, the extended Kalman filter is used to reduce smartphone power consumption.Indoor user activities seriously affect the quality and reliability of wireless signals.The literature [16] proposes an INS/Wi-Fi indoor localization system based on the weighted least squares.The precondition of using INS/Wi-Fi location system is the deployment of Wi-Fi access points in the positioning area, which limits the scope of use.
The directional drift reduction technique, consisting of a zero angular rate update, a heuristic heading reduction, and an electronic compass, reduces heading drift and obtains better solutions for estimating human trajectory in indoor complex environments [17].Experimental results reveal a relative error of 1 percent during walking.This technique can be used only on sensors attached to the foot.In [18], the data from the gyroscope and the magnetometer are fused for indoor intelligent mobile robot localization.A fuzzy compensation algorithm is used to eliminate regular error.The Kalman filter is used to eliminate irregular error.A reliability-augmented particle filter is used to deal with magnetic field data and inertial data from smartphones [19].A self-heuristic particle filter and a dynamic step length estimation algorithm are proposed to improve the localization accuracy and robustness.In addition, a hybrid measurement model further improves indoor localization performance.The particle filter requires a lengthy time to calculate, which poses a challenge to real-time positioning.Another problem is that the system requires wireless positioning to provide a rough range when the particle filter suffers from "Kidnapped Robot Problem".An integrated Wi-Fi, magnetic field matching, and pedestrian dead-reckoning (DR) systems are designed for indoor positioning [20].Wi-Fi reduces magnetic field mismatch by limiting the range of magnetic field matching.Pedestrian DR is used to correct Wi-Fi and magnetic matching mismatches.The integrated positioning system achieves an average positioning accuracy of 3 to 4 m in the two environments.When scanning wireless signals, smartphones consume a large quantity of power, thereby posing a major challenge for long-term continuous positioning.
A Kalman filter with magnetic field observations is presented to correct the cumulative error of the inertial navigation [21].The difference between the geomagnetic model value and the measured magnetic field value is taken as an observation of the Kalman filter.However, the indoor magnetic field is subject to large disturbances, which is difficult to have a reasonable model to describe the magnetic field changes.The Kalman filter is designed to fuse the gyroscope and the magnetic field to obtain a more precise direction [22].It is obvious that the indoor magnetic field fluctuates greatly and is prone to large errors.In [23], based on two rotational invariance features such as magnetic field norm and vertical projection, the probability model of the Euclidean distance is used to estimate the position of the user.Reducing the dimensions of the magnetic field reduces the magnetic field characteristics.In [24], INS and MM techniques are designed to improve indoor positioning accuracy.A variety of constraints-a threshold-based method, an adaptive Kalman filter-based method, DTW, and weighted k-nearest neighbor-are designed to reduce magnetic field mismatch.The mismatch detection mechanism reduces INS/MM errors by 45.9 to 67.9 percent.Different environments and different users require different empirical parameters, which results in the performance of the algorithm depending on the empirical parameters.
Based on the shortcomings of the above work, we propose a new technology (3DDTW).3DDTW extends the dimensions of traditional DTW.Subsequently, the weighted least squares is proposed to further reduce the positioning error.Three walking experiments verify the effectiveness of the proposed algorithm.

System Model
Figure 1 shows the overall structure of system model including DR module, DR/MM module.In DR module, the user's attitude angle is estimated by integrating gyroscope reading.Step length and step counting are calculated from the accelerometer and gravitational acceleration.DR module calculates the user's position.In DR/MM module, the magnetic field is converted from the body coordinate system to the navigation coordinate system.Then, we use 3DDTW to calculate the distance between the measured magnetic field and the fingerprint.Finally, the weighted least squares further improves indoor positioning accuracy.

Attitude Angle Estimation Model
We use gyro reading to estimate the attitude of smartphone.Direct cosine matrix (DCM), quaternion, and Euler angle are the main techniques.The quaternion vector q = [q 1 , q 2 , q 3 , q 4 ] is updated using the angular rate measurements from gyroscope reading.Then, the updated quaternion is used to get an attitude of the navigation system in terms of Euler angle.In [25], the relationship between DCM and quaternion is expressed as The attitude angle[ϑ, φ, ψ] in terms of DCM can be calculated as follows [25] where c n b (m, k) is the mth row and the kth column element in the matrix (c n b ).Roll, pitch and yaw from the smartphone are ϑ, φ and ψ.

Step Length Model
Each user's step length is affected by mood, height, body weight, age, environment, and walking time.Therefore, a fixed step length is not appropriate.Different users have different step lengths.
The estimated step length needs one or more training values to calibrate in the training step length model [26].A linear step length model is developed using walking frequency and acceleration variance [27,28].Another nonlinear step length model is one in which the vertical acceleration is segmented and analyzed to estimate step length.An empirical relation between vertical acceleration and step length is given by [29] as follows where, during one step, a max and a min are the maximum and minimum vertical acceleration, respectively.K is a calibration parameter, which adjusts step length estimation to a specific user.Different users require different empirical parameters, and this is the main disadvantage.The reliability of the model depends on the calibration parameters.
Step length is calculated using the triangle model [30].The distance of the smartphone from the ground is L when the user is stationary.The distance of the smartphone from the ground is (L-H) when the user is walking.The vertical displacement of the smartphone (H) is calculated as follows where the start and end times of each step are t 1 and t 2 ; the vertical acceleration is a z .Based on the Pythagorean theorem, step length is calculated according to [30] as follows

Step Counting Model
The vertical acceleration has a certain periodicity during walking.In general, the number of steps is estimated by detecting the peak of the vertical acceleration.Two peak points are treated as one step.Vertical acceleration is calculated as follows where acceleration and gravitational acceleration are a and g.When a vertical acceleration is greater than the previous value and less than the latter value, a peak is detected.Due to noise, one shortcoming is that many false peaks are detected, which lead to overload statistics.False peaks are removed using a variance technique.Therefore, two detection techniques, defined as follows, are designed to estimate the exact number of steps where the vertical acceleration variance is a z_var .A threshold (THD) is a constant.In this paper, detection results, expressed as follows, are the logical results of the two detection conditions.
where R indicates that the vertical displacement of a user during walking is unlikely to be too small.

DR-Based Position Path
The heading from the attitude angle, step length and step counting determine the user's path.DR updates the new position [x k+1 , y k+1 ] T based on a previous position [x k , y k ] T , step length and attitude, as Equation (10) expressed.

Dead-Reckoning and Magnetic Matching (DR/MM)
For the DR/MM positioning system, the first step is to construct a magnetic fingerprint database.The collection mode of magnetic field fingerprint is referenced in literature [16].To collect magnetic field fingerprints, users, carrying smartphones, walk from the starting point to the end point.The fingerprints are stored in the database as < pos ii , m ii >.The subscript ii represents the ii th fingerprint in the database.The second step is to calculate the user's position by DR.DR constrains the range of MM.Fifteen meters is used as the range of the MM.The third step is to use the measured magnetic field to match the fingerprints.The proposed DTW (3DDTW) is designed to calculate the distance between the measured magnetic field and the magnetic fingerprints.Finally, the weighted least squares is used to improve indoor localization accuracy and robustness.

Dynamic Time Warping (DTW) for DR/MM
The magnetic field corresponding to each step is treated as a measured value.Each fingerprint represents a path from the beginning to the end.To extract the position corresponding to a measured value, each fingerprint is cut into many small fingerprints.The distance between measured magnetic field and small fingerprint is calculated using DTW [31].For the magnetic fingerprint, the DTW distance (D) is expressed as Equation (11).
where M mea (i) and M db (j) are the i th measured magnetic field and the j th fingerprint in the database, respectively.d denotes the square of Euclidean distance among pairs of values in M mea and M db ;

3-Dimensional Dynamic Time Warping (3DDTW) for DR/MM
Traditional DTW requires that the input signal be a one-dimensional signal.A simple strategy is to use the amplitude of the magnetic field as the input signal.It is obvious that the one-dimensional signal reduces the three-dimensional magnetic field characteristics, which is not conducive to fingerprint matching.Directly using a magnetic field from a smartphone as a fingerprint is clearly unreasonable because the attitudes from the fingerprint construction phase and the magnetic field matching phase are difficult to maintain the same [32].An effective method is to transform the magnetic field in the body frame into the navigation frame, as Equation ( 12) denotes.
where the three-dimensional magnetic field reading in the navigation frame and the body frame are [m nx , m ny , m nz ] T and [m bx , m by , m bz ] T , respectively.Unlike traditional DTW, 3DDTW extends the original one-dimensional signal to a two-dimensional signal.In Figure 2, the left side represents the measured magnetic field (m mea ); the bottom surface represents the fingerprint (m db ).D represents the 3DDTW distance between the measured magnetic field and fingerprint in the database.Based on the idea of dynamic programming, the 3DDTRW distance at the current moment is equal to the newly added distance plus the distance from the previous moment.Therefore, the 3DDTW process is divided into two steps.The first step is to calculate the newly added distance between the measured magnetic field (m mea (k, i)) and the fingerprint (m db (k, j)), as Equation (13) expressed.
In the three-dimensional coordinate system, the 3DDTW distances at the previous moment are , respectively.To search for the best alignment between two signals, the second step is calculated as Equation ( 14) expressed Algorithm 1 shows the 3DDTW calculation process.In MM, the traditional DTW calculates the distance between the two magnetic signals by means of dimensionality reduction.It is obvious that the dimension reduction method reduces the characteristics of the magnetic field.3DDTW calculates between two magnetic field signals by extending the dimension, which enhances the robustness of indoor positioning.

Input:
The measured signal m mea with p rows and n columns, fingerprint signal m db with p rows and m columns.1.Let d denote the distance among pairs of values in m mea and m db .2. for i = 1 to n do 3. for j = 1 to m do 4.
for k = 1 to p do 5.
for k = 2 to p do 14.
End for 22. End for 23.End for 24.Output: The 3DDTW distance D.

Weighted Least Squares for DR/MM
The weighted least squares is an effective technique to improve positioning accuracy.Referring to the weighted least squares of Reference [16], we use similar technique to improve indoor positioning accuracy.The 3DDTW distances , y r ] T ) are selected to estimate a user's location.Based on the idea of linear weighting, a user's position is estimated as follows where ω i represents a weighting factor.we construct the weighted least squares objective function is designed as follows where || • || is the Euclidean distance; [x, y] T is the real position.We assume that the position error and the 3DDTW distance construct a linear relationship, as Equation ( 18) expressed where the position error ∆z i is expressed as [x, y] T − [ x i , y i ] T ; σ represents a configuration factor.Bring Equation ( 18) into Equation ( 17), using the Lagrange function [33], the expressions of ω i is calculated as follows

Experiments and Discussions
We use Mi5 smartphone to build magnetic fingerprint database.Nexus5 smartphone is used to perform walking experiments.When the user walks, the smartphone maintains four motion gestures, including calling, dangling, handheld, and pocket.Walking experiments in three different scenarios were carried out in Xiamen University, as shown in Figure 3.The first experimental scenario consists of metal doors, metal windows, and a small number of students walking.The second experimental scenario consists of bookshelves, concrete columns, and many students.The third experimental scene consists of a metal fence and many metal doors.The magnetic field mean of three different environments are 123 µT, 113.75 µT and 117.74 µT, respectively.Experimental results from three different walking trajectories are presented in this section.

Walking Experiment in Teaching Building
A walking positioning experiment was performed with the smartphone maintaining four motion gestures.The user walked about 90 m.The DR cannot eliminate heading drift, which results in error accumulation.Therefore, as seen in Figure 4, the cumulative errors from DR increase over time in the four motion gestures.Figure 5 shows that mismatching is a major problem in MM even though k-nearest neighbor is used to reduce the positioning error.Magnetic field mismatches lead to excessive positioning results in some areas.The DR and MM positioning results are diverged from the true trajectories on some occasions.As seen in Figure 6, integrated DR/MM technology reduces the mismatch by limiting the matching range.3DDTW enhances the performance of magnetic field matching by extending the dimensions of the input signal.Weighted least squares further reduces positioning errors by linear weighting.Thus, integrated DR/MM technology improves positioning accuracy.The position errors and the cumulative distribution function (CDF) curves are shown in Figures 7 and 8.It can be seen from Figure 7 that in the initial stage, the inertial navigation positioning result is better than fusion positioning results in the four gestures.The main reason is that the inertial navigation system error has a cumulative effect, which is small at the beginning stage and increases with increase of walking time.Since the fluctuation of the magnetic field depends on the change of the environment, in the global matching range, the mismatch of the magnetic field reaches a large error, as shown by the black line in Figure 7.In most cases, integrated positioning system performance is superior to DR and MM in four gestures.The fusion positioning system uses the inertial navigation results to constrain the magnetic field matching range, while 3DDTW and weighted least squares improve the magnetic field matching performance.At less than 3 m, probability for DR, MM and DR/MM are as follows: 13.74%, 12.21% and 53.43%, respectively in calling gesture (see Figure 8a); 21.22%, 4.47% and 44.13%, respectively in dangling gesture (see Figure 8b); 16.41%, 1% and 49.75%, respectively in handheld gesture (see Figure 8c); 23.94%, 3.52% and 42.96%, respectively in pocket gesture (see Figure 8d).The positioning results indicate DR/MM integrated algorithm is robust to different motion gestures.
The average error, root mean square error (RMSE), maximum error, and circular error probability (CEP) for the four motion gestures are shown in Table 1.As expected, the smallest average positioning error in the four motion gestures, which is 3.09 m, belongs to DR/MM, and the average positioning errors for DR, and MM are 6.95 and 15.43 m, respectively.In comparison with DR, the average error, RMSE, maximum error, CEP (75%) and CEP (95%) for DR/MM are reduced by 47.28%, 49.21%, 50.32%, 42.12%, and 54.34%, respectively.In comparison with MM, the average error, RMSE, maximum error, CEP (75%) and CEP (95%) for DR/MM are reduced by 77.94%, 77.3%, 78.79%, 76.05%, and 78.45%, respectively.

Walking Experiment in Study Room
A study room experiment was carried out to verify the effectiveness of our proposed algorithms.The walking distance was about 140 m.The positioning results of the four motion gestures for a smartphone are shown in Figure 9.The average errors in the four gestures for the walking experiment are 2.34, 3.48, 3.05 and 3.6 m, respectively.Reference [10] describes how to use the magnetic field alone to MM for indoor positioning.In the offline phase, the localization area is divided into many grids, and a magnetic field is acquired at each grid point.In the positioning phase, the collected magnetic field is used to match the magnetic fingerprint to obtain the user's position.Reference [34] introduces a smart indoor positioning system (SmartPDR), which uses the magnetic field and gyroscope to estimate a user direction.In [30,35], Kalman Filter (KF) is used to reduce static moment error, but the cumulative error continues to expand over time.Figure 10 shows CDFs of four algorithms.At less than 3 m, the probabilities for MM, SmartPDR, KF, and 3DDTW are as follows: (a) for calling: 4.74%, 2.31%, 8.06%, and 65.88%, respectively; (b) for dangling: 9.22%, 6.7%, 25.53%, and 47.52%, respectively; (c) for handheld: 2.05%, 4.24%, 7.53%, and 46.23%, respectively; (d) for pocket: 9.43%, 5.97%, 14.75%, and 40.98%, respectively.3DDTW obtains satisfactory positioning performance under four gestures.For MM, SmartPDR, KF, and 3DDTW, the average error, RMSE, maximum error, CEP (75%), and CEP (95%) are shown in Table 2. Compared with MM, SmartPDR, and KF, the errors of 3DDTW are reduced as follows: 66.13%, 80.68%, and 69.9% for the average error, respectively; 65.4%, 80.93%, and 71.26% for RMSE, respectively; 64.17%, 83.8%, and 72.87% for maximum error, respectively; 62.7%, 78.94%, and 69.53% for CEP (75%), respectively; 67.05%, 84.41%, and 75.09% for CEP (95%), respectively; The best positioning technology belongs to 3DDTW.

Walking Experiment in Office Building
A more complicated walking trajectory experiment was performed in office building.The walking distance was about 390 m.The pictures in Figure 11 illustrate the positioning results of four different gestures (calling, dangling, handheld and pocket) for office building; the pictures in Figure 12 show the corresponding position errors.As shown in Figure 11, the integrated positioning system still achieves satisfactory positioning results under a complicated walking path.In Figure 12, most of position errors in the four motion gestures are less than 10 m.The average errors in the four gestures for the walking experiment are 2.8, 3.47, 3.1 and 5.91 m, respectively.Figure 12 shows that the positioning errors from these four gestures are relatively stable.Experimental results show that the DR/MM hybrid algorithm improves positioning accuracy and robustness.Table 3 shows the position errors for DR/MM in the office building.The pocket gesture error in the table is large, mainly due to the large jitter of smartphone.In general, the fusion algorithm proposed in this paper still obtains better positioning performance in the complex office building environment.

Conclusions and Future Work
The above three walking experiments prove that our proposed algorithm effectively improves indoor positioning accuracy.First, we introduce attitude angle estimation, step length, and step counting models.Subsequently, DR estimates the user's position based on acceleration and angular velocity.Second, the magnetic field in the body coordinate system is converted to the navigation coordinate system.Based on the traditional DTW, we propose an improved DTW (3DDTW) that extends a one-dimensional input signal into a two-dimensional input signal.3DDTW is used to calculate the distance between the measured magnetic field and the fingerprint, which reduces the mismatch of the magnetic field fingerprint.Finally, a weighted least squares is used to further reduce indoor positioning error.The average errors from three walking experiments are 3.09, 3.12 and 3.82 m.The experimental results show that the integrated algorithm is stable, and it can adapt to different magnetic environment and different walking trajectories.
However, there are still some issues that need to be addressed further.Due to the changes of environment and time, the magnetic fingerprint database needs to be updated in real time.In addition, how to focus on the integration of more sensors of smartphones to improve positioning accuracy and robustness warrants further consideration.

FingerprintFigure 1 .
Figure 1.The structure of system model.

Table 1 .
Position errors for DR, MM and DR/MM (m) in teaching building.

Table 3 .
Position errors for DR/MM (m) in office building.