Novel WiFi/MEMS Integrated Indoor Navigation System Based on Two-Stage EKF

Indoor navigation has been developing rapidly over the last few years. However, it still faces a number of challenges and practical issues. This paper proposes a novel WiFi/MEMS integration structure for indoor navigation. The two-stage structure uses the extended Kalman filter (EKF) to fuse the information from WiFi/MEMS sensors and contains attitude-determination EKF and position-tracking EKF. In the WiFi part, a partition solution called “moving partition” is originally proposed in this paper. This solution significantly reduces the computation time and enhances the performance of the traditional Weighted K-Nearest Neighbors (WKNN) method. Furthermore, the direction measurement is generated utilizing WiFi positioning results, and a “turn detection” is implemented to guarantee the effectiveness. The navigation performance of the presented integration structure has been verified through indoor experiments. The test results indicate that the proposed WiFi/MEMS solution works well. The root mean square (RMS) position error of WiFi/MEMS is 0.7926 m, which is an improvement of 20.59% and 36.60% when compared to MEMS and WiFi alone. Besides, the proposed algorithm still performs well with very few access points (AP) available and its stability has been proven.


Introduction
In recent years, location-based services (LBS) have become increasingly important. Location-based systems are required in various fields such as mobile commerce, parcel or vehicle tracking, discovering the nearest shops or restaurants, and social networking [1]. In LBS, positioning is one of the key issues to be addressed [2]. On the other hand, researches have shown that people spend about 70% of their time indoors [3]. The demand for indoor navigation is increasing rapidly in a number of applications. Therefore, indoor navigation has gained plenty of attention from companies and researchers.
While Global Navigation Satellite Systems (GNSS) based outdoor positioning and navigation has achieved great advances and high accuracy in the past few decades, indoor navigation still remains an unsolved problem [4,5]. The main challenges consist of the unavailability or degradation of GNSS signals, the complexity of indoor environments, and the necessity of using low-grade devices [6]. Under such a circumstance, various positioning techniques have been researched, such as IEEE 802.11 WLAN (WiFi) [7][8][9][10], Radio Frequency Identification (RFID) [11], ultrasound [12], Ultra Wideband Beacons (UWB) [13], Bluetooth [14], ZigBee [15], infrared [16], and pseudolites [17]. Sometimes, multiple signal types are utilized simultaneously [18,19]. Since WiFi access points (AP) are installed ubiquitously nowadays, the WiFi approach has been much favored in most cases. Furthermore, it is also suitable in terms of both cost and accessibility [1].
Point-centred indoor positioning system that overcame common limitations presented in conventional positioning systems, such as an excessive involvement of Mobile Devices. In [33], Lim et al. established the theoretical base and developed a localization algorithm for building a zero-configuration and robust indoor localization and tracking system to support location-based network services and management.
For the integration of WiFi and MEMS solutions, there are a number of existed researches. Frank et al. [34] presented an indoor positioning system for pedestrians combining Wireless LAN fingerprinting with foot mounted inertial and magnetometer sensors. Xiao et al. [35] proposed a region-based fingerprinting approach for indoor positioning in WiFi wireless networks and a stochastic system model to track the target's position with an inertial measurement unit (IMU) integrated with the WiFi tag. Evennou and Marx [36] presented an aided DR navigation structure and signal processing algorithms for self localization of an autonomous mobile device by fusing PDR and WiFi signal strength measurements. Schatzberg et al. [37] presented a highly accurate indoor positioning system which was based on a new WiFi technology (protocol) and on MEMS inertial sensors. Iwase and Shibasaki [38] proposed a solution to reduce the accumulative error of PDR carried out with only the low cost sensors and WiFi in smartphones by realizing cooperative positioning among multiple pedestrians. Li et al. [39] developed a navigation algorithm which fused the WiFi received signal strength indicator (RSSI) and smartphone inertial sensor measurements. Table 1 lists the positioning performances from current WiFi/MEMS integrated systems in literature [24,[34][35][36][37][38][39]. Table 1. Positioning performances from other systems. IMU-inertial measurement unit; RMS-root mean square.

System Overview
The block diagram of the proposed EKF based WiFi/MEMS integration for indoor navigation is shown in Figure 1.
The proposed system mainly includes three modules: WiFi-based navigation, PDR-based navigation, and EKF-based WiFi/MEMS integration. In the presented WiFi solution, we pass RSS values to the fingerprinting scheme with "moving partition" to generate the MU position. Besides, if the turn detection fails, the MU direction measurement is obtained from WiFi positioning results. In PDR solution, the accelerometer data are utilized for step detection and step length estimation. Then PDR algorithm is applied to calculate the position of the MU. EKF-based integration includes an attitude-determination EKF and position-tracking EKF. In attitude-determination EKF, data from gyroscopes and accelerometers are used to generate the heading of the MU. In position-tracking EKF, results from WiFi and MEMS solutions are integrated to generate final navigation outcome.
Furthermore, Weighted K-Nearest Neighbors (WKNN) method has been presented [50]. Instead of using the arithmetic mean, WKNN method utilizes the weighted mean of position coordinates of the K RPs to estimate the MU location. There are a number of approaches to

Weighted K-Nearest Neighbors (WKNN) and Moving Partition
The whole process of WiFi fingerprinting is depicted in Figure 2. In fingerprinting scheme, to estimate the position of the MU, various matching algorithms have been proposed [8]. There are probabilistic methods [40,41], deterministic methods [42,43], and neural networks [44,45]. Among them, the Nearest Neighbor (NN) method is the most basic deterministic matching algorithm [9]. Firstly, the method calculates the distances between the measured RSS vector and the RSS vectors in the database. Then the position coordinates of the RP with the minimum distance is determined as that of the MU. Commonly, the distance is Euclidean distance [46], calculated by Equation (1). In other cases, Manhattan distance [2,47] and Mahalanobis distance [48] are used.
where S and M i are the measured RSS vector and the i-th database fingerprint, respectively; S j and M i,j are the j-th elements in S and M i , respectively; N is the number of available APs.
As the NN method has low stability and low accuracy, K-Nearest Neighbors (KNN) method has been developed [49], where K nearest neighbors (those with the shortest distance) are selected, and the arithmetic mean of position coordinates of the K RPs is regarded as estimate of the MU location [2], as shown in Equation (2).
Furthermore, Weighted K-Nearest Neighbors (WKNN) method has been presented [50]. Instead of using the arithmetic mean, WKNN method utilizes the weighted mean of position coordinates of the K RPs to estimate the MU location. There are a number of approaches to determine weights [9]. In most cases, the multiplicative inverse of the distance calculated by Equation (1) determines the weight, and the MU is located by Equation (3).
where D i is the Euclidean distance calculated by Equation (1).
Micromachines 2019, 10, x FOR PEER REVIEW 5 of 21 determine weights [9]. In most cases, the multiplicative inverse of the distance calculated by Equation (1) determines the weight, and the MU is located by Equation (3).
where i D is the Euclidean distance calculated by Equation (1). The WKNN method takes full account of the effect of the current RPs for the estimated point. As a result, it performs better than KNN and NN methods [9]. However, it needs to search the overall space and go through the whole database fingerprints. For a big place and a huge database, the WKNN method seems to have low efficiency and the computation time can be unacceptable. In the current study, a partition solution is proposed and called "moving partition". As shown in Figure 3, a circle located at the previous point is drawn with the given radius, and a partition in the circle is formed. The given radius is determined by the maximum moving distance of human in 1 s and can be set as 2.5 m. Suppose there are 10 RPs in the circle. These RPs are stored in an array. The current point is calculated within the scope of the 10 RPs using the WKNN method. Once the current point is located, a new partition is got with the same radius as the old one. The method to build the new partition is removing the last RPs in the array and putting in the new ones. The number of the changing RPs is determined by Equation (4).
where [ ] means the function of rounding down to integer; L is the distance between adjacent RPs; m is the number of RPs in a row; R is the radius of the partition circle; r is the distance between the current point and the RP at the edge of the circle in the forward direction. If R r ≥ , the partition moves forward. If R r < , it moves backward. Then the next point is calculated within the scope of RPs in the new partition.
With "moving partition", the area of search space is greatly reduced. In addition, the work to update the partition is greatly reduced as well. Therefore, the computation time decreases The WKNN method takes full account of the effect of the current RPs for the estimated point. As a result, it performs better than KNN and NN methods [9]. However, it needs to search the overall space and go through the whole database fingerprints. For a big place and a huge database, the WKNN method seems to have low efficiency and the computation time can be unacceptable. In the current study, a partition solution is proposed and called "moving partition". As shown in Figure 3, a circle located at the previous point is drawn with the given radius, and a partition in the circle is formed. The given radius is determined by the maximum moving distance of human in 1 s and can be set as 2.5 m. Suppose there are 10 RPs in the circle. These RPs are stored in an array. The current point is calculated within the scope of the 10 RPs using the WKNN method. Once the current point is located, a new partition is got with the same radius as the old one. The method to build the new partition is removing the last RPs in the array and putting in the new ones. The number of the changing RPs is determined by Equation (4).
where [ ] means the function of rounding down to integer; L is the distance between adjacent RPs; m is the number of RPs in a row; R is the radius of the partition circle; r is the distance between the current point and the RP at the edge of the circle in the forward direction. If R ≥ r, the partition moves forward. If R < r, it moves backward. Then the next point is calculated within the scope of RPs in the new partition. significantly. The larger the test space is, the more obvious the effect is. In all, "moving partition" has the advantages of high efficiency and short computation time.

Direction from WiFi and Turn Detection
In the current study, the direction measurement of the MU is estimated utilizing the information from WiFi positioning results. As shown in Figure 4a, a line is drawn using the method of least squares with the information of 4 latest positioning points. If the coordinate of the kth point is larger than that of the (k-3)th point, the MU is moving forward, and vice versa. Since the MU walks straight most of the time, this method works in most cases. However, it becomes invalid at corner, as shown in Figure 4b. Therefore, a "turn detection" is necessary before the direction estimation. The detailed illustration is as follows. In the current study, the turn detection is utilized to guarantee the effectiveness of direction from WiFi, and it can be achieved with gyroscopes. When the step detection is accomplished, the vertical angular velocities obtained from gyroscope data are accumulated during the period of each step. The accumulated values are depicted in Figure 5. As shown, there are three singular points. Combining Figure 6, it can be seen that the three singular points represent the three turns of the MU With "moving partition", the area of search space is greatly reduced. In addition, the work to update the partition is greatly reduced as well. Therefore, the computation time decreases significantly. The larger the test space is, the more obvious the effect is. In all, "moving partition" has the advantages of high efficiency and short computation time.

Direction from WiFi and Turn Detection
In the current study, the direction measurement of the MU is estimated utilizing the information from WiFi positioning results. As shown in Figure 4a, a line is drawn using the method of least squares with the information of 4 latest positioning points. If the coordinate of the kth point is larger than that of the (k-3)th point, the MU is moving forward, and vice versa. Since the MU walks straight most of the time, this method works in most cases. However, it becomes invalid at corner, as shown in Figure 4b. Therefore, a "turn detection" is necessary before the direction estimation. The detailed illustration is as follows. significantly. The larger the test space is, the more obvious the effect is. In all, "moving partition" has the advantages of high efficiency and short computation time.

Direction from WiFi and Turn Detection
In the current study, the direction measurement of the MU is estimated utilizing the information from WiFi positioning results. As shown in Figure 4a, a line is drawn using the method of least squares with the information of 4 latest positioning points. If the coordinate of the kth point is larger than that of the (k-3)th point, the MU is moving forward, and vice versa. Since the MU walks straight most of the time, this method works in most cases. However, it becomes invalid at corner, as shown in Figure 4b. Therefore, a "turn detection" is necessary before the direction estimation. The detailed illustration is as follows. In the current study, the turn detection is utilized to guarantee the effectiveness of direction from WiFi, and it can be achieved with gyroscopes. When the step detection is accomplished, the vertical angular velocities obtained from gyroscope data are accumulated during the period of each step. The accumulated values are depicted in Figure 5. As shown, there are three singular points. Combining Figure 6, it can be seen that the three singular points represent the three turns of the MU In the current study, the turn detection is utilized to guarantee the effectiveness of direction from WiFi, and it can be achieved with gyroscopes. When the step detection is accomplished, the vertical angular velocities obtained from gyroscope data are accumulated during the period of each step. The accumulated values are depicted in Figure 5. As shown, there are three singular points. Combining Figure 6, it can be seen that the three singular points represent the three turns of the MU during walking. The vertical angular velocities vary intensively in short time at corners. Therefore, the accumulated gyroscope values can be used to detect turns. To achieve this, a threshold can be set, and once an accumulated value exceeds the threshold, a turn is detected. The turn detection only concerns the range of turn and is independent of accumulated errors of gyroscope data. In addition, it is important to note that the mobile phone must be kept as horizontal as possible during the detection [51]. In the current study, this requirement is satisfied.
Micromachines 2019, 10, x FOR PEER REVIEW 7 of 21 during walking. The vertical angular velocities vary intensively in short time at corners. Therefore, the accumulated gyroscope values can be used to detect turns. To achieve this, a threshold can be set, and once an accumulated value exceeds the threshold, a turn is detected. The turn detection only concerns the range of turn and is independent of accumulated errors of gyroscope data. In addition, it is important to note that the mobile phone must be kept as horizontal as possible during the detection [51]. In the current study, this requirement is satisfied.

Step Detection
Methods of step detection include peak detection, zero crossings, auto-correlation or template matching, and spectral analysis [52]. In the current study, peak detection is utilized. Firstly, the total acceleration can be calculated by  during walking. The vertical angular velocities vary intensively in short time at corners. Therefore, the accumulated gyroscope values can be used to detect turns. To achieve this, a threshold can be set, and once an accumulated value exceeds the threshold, a turn is detected. The turn detection only concerns the range of turn and is independent of accumulated errors of gyroscope data. In addition, it is important to note that the mobile phone must be kept as horizontal as possible during the detection [51]. In the current study, this requirement is satisfied.

Step Detection
Methods of step detection include peak detection, zero crossings, auto-correlation or template matching, and spectral analysis [52]. In the current study, peak detection is utilized. Firstly, the total acceleration can be calculated by

Step Detection
Methods of step detection include peak detection, zero crossings, auto-correlation or template matching, and spectral analysis [52]. In the current study, peak detection is utilized. Firstly, the total acceleration can be calculated by where a ix , a iy , a iz are accelerations observed in the carrier coordinate system and L is the sampling number. Then the local gravitational acceleration can be obtained by where a s i is the acceleration observed when the mobile phone is kept static and M is the corresponding sampling number. Next, the gravitational acceleration is eliminated and the smoothed value is calculated by where (2N + 1) is the length of sliding window. Through sliding window and averaging, the high-frequency noise in acceleration signal can be restrained effectively. In addition, multi-peak waveform caused by body shake can be smoothed to single-peak waveform, which makes it easy to detect peaks [53].
The smoothed acceleration values calculated by Equation (7) are utilized to detect peaks. When detecting peaks, the following conditions must be obeyed. Firstly, the acceleration peak must be larger than a predetermined threshold. Secondly, the time interval between two adjacent peaks must be larger than a time threshold. The result of peak detection is illustrated in Figure 7, where red circles represent peaks detected.
Micromachines 2019, 10, x FOR PEER REVIEW 8 of 21 where ( ) is the length of sliding window. Through sliding window and averaging, the high-frequency noise in acceleration signal can be restrained effectively. In addition, multi-peak waveform caused by body shake can be smoothed to single-peak waveform, which makes it easy to detect peaks [53].
The smoothed acceleration values calculated by Equation (7) are utilized to detect peaks. When detecting peaks, the following conditions must be obeyed. Firstly, the acceleration peak must be larger than a predetermined threshold. Secondly, the time interval between two adjacent peaks must be larger than a time threshold. The result of peak detection is illustrated in Figure 7, where red circles represent peaks detected.

Step Length Estimation
Step length estimation is used to estimate the moving distance of the pedestrian at each step [24]. In the current study, the practical model presented in [54] is utilized to estimate step length. This model assumes that the step length is proportional to the vertical movement of the human hip. The largest difference of the vertical acceleration at each step is used to calculate vertical movement [24]. The step length is estimated as follows.
where max z a and min z a are the maximum and minimum values of the vertical acceleration, respectively; K is a calibrated constant parameter. This technique has been shown to measure distance walked to within ±8% across a variety of subjects of different leg lengths [54]. In the current study, the value of K is obtained through training, as shown in Table 2.

Step Length Estimation
Step length estimation is used to estimate the moving distance of the pedestrian at each step [24]. In the current study, the practical model presented in [54] is utilized to estimate step length. This model assumes that the step length is proportional to the vertical movement of the human hip. The largest difference of the vertical acceleration at each step is used to calculate vertical movement [24]. The step length is estimated as follows.
where a zmax and a zmin are the maximum and minimum values of the vertical acceleration, respectively; K is a calibrated constant parameter. This technique has been shown to measure distance walked to within ±8% across a variety of subjects of different leg lengths [54]. In the current study, the value of K is obtained through training, as shown in Table 2.

Extended Kalman Filter (EKF)-Based Integration
The EKF is usually utilized to fuse other information to reduce the drift of MEMS-based navigation approach [24]. It is a generalization of Kalman filter for nonlinear systems presenting small or moderate nonlinearities [55]. In this paper, a novel two-stage EKF structure to fuse the information from WiFi/MEMS sensors is proposed. The proposed structure contains attitude-determination EKF and position-tracking EKF, where the calculation of the former is used in the latter to generate final navigation results. The two-stage EKF structure has the advantage of high navigation accuracy. One thing to note is that all formulas in this section apply the International System of Units.

Attitude-Determination EKF
In the first stage, the information from gyroscopes and accelerometers is fused using the attitude-determination EKF to calculate the Euler angles between the carrier coordinate system and the navigation coordinate system. In the attitude-determination EKF, the system model is constructed utilizing the Euler angle differential equation and the measurement model is the conversion of tri-axial accelerations between the carrier coordinate system and the navigation coordinate system.
The state vector is written as: where ψ is the heading angle, θ is the pitching angle, γ is the roll angle, and T denotes transpose. The initial state vector is set at:D The initial covariance matrix of the state vector is set at: The system model is as follows: where ω x , ω y , ω z are angular velocities observed in the carrier coordinate system, w ψ , w θ , w γ are noise, and ∆t is the sampling interval.
The covariance matrix of system noise is set at: The measurement vector is written as: where a x , a y , a z are accelerations observed in the carrier coordinate system. The measurement model is as follows: where T k is the direction cosine matrix calculated by Equation (16), and v k is noise.
The covariance matrix of measurement noise is set at:

Position-Tracking EKF
In the second stage, the information from PDR and WiFi is fused using position-tracking EKF to calculate the MU position. In position-tracking EKF, the system model is established through PDR algorithm and the measurement model is the equivalence between WiFi results and PDR results. The heading angle obtained from attitude-determination EKF is utilized in position-tracking EKF.
The state vector is written as: where x, y are position coordinates of the MU, S is the step length, and ψ is the heading angle calculated by attitude-determination EKF. The initial state vector is set at:B The initial covariance matrix of the state vector is set at: The system model is as follows: where w x , w y , w S , w ψ are noise. The covariance matrix of system noise is set at: The measurement vector is written as: where x WiFi , y WiFi are position coordinates from WiFi results, S acc is the step length calculated by Equation (8), and ψ WiFi is the heading angle from WiFi results. The measurement model is as follows: where B k is the state vector and u k is noise. The covariance matrix of measurement noise is set at: The two-stage EKF algorithm for WiFi/MEMS integration is summarized in Algorithm 1.
Algorithm 1 Two-stage EKF for WiFi/MEMS integration.

Experiment Description and Comparison of "Moving Partition" and WKNN
To evaluate the performance of the proposed indoor navigation method, several experiments were performed. The experiment platform can be any Android smartphone equipped with an accelerometer triad, a gyroscope triad and a WiFi receiver. In the current study, a Samsung Galaxy S2 and a Mi 5s were used. The IMU data was collected through the app "Physics Toolbox Suite", and the WiFi data was collected through the app "RSS Collection".
The experiments were conducted in the ninth floor of Block C, New Main Building at Beihang University, as shown in Figure 8. The layout of the floor is shown in Figure 9. The size of test area is around 30 × 20 m 2 and the loop corridor is 1.8 m wide. There were 158 RPs and 155 positioning points in all. A total of 270 APs were involved in testing. The exact positions of these APs are unknown. To eliminate the effect of randomness of human behavior [56], the offline training data were collected systematically using a 1.  The performance comparison of "moving partition" and the traditional WKNN method is illustrated in Table 3. As shown, the running time of "moving partition" and WKNN on the same device was 0.28 s and 0.62 s, respectively. With "moving partition", the computation time decreased by more than half. Besides, the average positioning error reduced from 1.9840 m to 1.8857 m. Therefore, "moving partition" enhances navigation performance.  Figure 10 depicts the navigation performance comparison of WiFi (with "moving partition"), MEMS, and WiFi/MEMS integration (with "moving partition") in one loop. The "Ref" represents the actual trajectory which the tester walked along. As shown, the estimation of WiFi/MEMS integration proposed in this paper has a nice performance, making a good fit with the reference trajectory. Also, compared with WiFi, the phenomenon of reciprocating motion has been eliminated significantly. This figure depicts the estimation result of MEMS as well. As is known, the estimation error accumulates quickly for low grade MEMS sensors in smart devices which usually have large accelerometer and gyroscope biases. In the first part of the corridor, the MEMS estimation keeps good performance. However, when turning to the second part, the trajectory deviates. This  The performance comparison of "moving partition" and the traditional WKNN method is illustrated in Table 3. As shown, the running time of "moving partition" and WKNN on the same device was 0.28 s and 0.62 s, respectively. With "moving partition", the computation time decreased by more than half. Besides, the average positioning error reduced from 1.9840 m to 1.8857 m. Therefore, "moving partition" enhances navigation performance.  Figure 10 depicts the navigation performance comparison of WiFi (with "moving partition"), MEMS, and WiFi/MEMS integration (with "moving partition") in one loop. The "Ref" represents the actual trajectory which the tester walked along. As shown, the estimation of WiFi/MEMS integration proposed in this paper has a nice performance, making a good fit with the reference trajectory. Also, compared with WiFi, the phenomenon of reciprocating motion has been eliminated significantly. This figure depicts the estimation result of MEMS as well. As is known, the estimation error accumulates quickly for low grade MEMS sensors in smart devices which usually have large accelerometer and gyroscope biases. In the first part of the corridor, the MEMS estimation keeps good performance. However, when turning to the second part, the trajectory deviates. This The performance comparison of "moving partition" and the traditional WKNN method is illustrated in Table 3. As shown, the running time of "moving partition" and WKNN on the same device was 0.28 s and 0.62 s, respectively. With "moving partition", the computation time decreased by more than half. Besides, the average positioning error reduced from 1.9840 m to 1.8857 m. Therefore, "moving partition" enhances navigation performance. Table 3. Performance comparison of "moving partition" and Weighted K-Nearest Neighbors (WKNN).

Moving Partition WKNN
running time (s) 0.28 0.62 average positioning error (m) 1.8857 1.9840 Figure 10 depicts the navigation performance comparison of WiFi (with "moving partition"), MEMS, and WiFi/MEMS integration (with "moving partition") in one loop. The "Ref" represents the actual trajectory which the tester walked along. As shown, the estimation of WiFi/MEMS integration proposed in this paper has a nice performance, making a good fit with the reference trajectory. Also, compared with WiFi, the phenomenon of reciprocating motion has been eliminated significantly. This figure depicts the estimation result of MEMS as well. As is known, the estimation error accumulates quickly for low grade MEMS sensors in smart devices which usually have large accelerometer and gyroscope biases. In the first part of the corridor, the MEMS estimation keeps good performance. However, when turning to the second part, the trajectory deviates. This phenomenon becomes more and more serious in the third and fourth parts of the corridor. Therefore, MEMS needs to be integrated with WiFi using the EKF to achieve a more accurate estimation, as illustrated in the above section. The result of WiFi/MEMS integration in Figure 10 has shown its advantage that it has the highest accuracy.

Comparison of WiFi, MEMS, and WiFi/MEMS Integration
phenomenon becomes more and more serious in the third and fourth parts of the corridor. Therefore, MEMS needs to be integrated with WiFi using the EKF to achieve a more accurate estimation, as illustrated in the above section. The result of WiFi/MEMS integration in Figure 10 has shown its advantage that it has the highest accuracy.
The detailed estimation errors and running time of these algorithms are listed in Table 4. As shown, the maximum error of WiFi/MEMS is 1.2498 m, which is 16.07% of MEMS and 23.97% of WiFi. The mean error of WiFi/MEMS is 0.6835 m, which is 24.67% of MEMS and 36.25% of WiFi. The root mean square (RMS) of WiFi/MEMS position errors is 0.7926 m, which is 20.59% of MEMS and 36.60% of WiFi. Therefore, the EKF-based WiFi/MEMS algorithm proposed in this paper has improved the estimation accuracy. Besides, it has low computational complexity as the running time is short.  Furthermore, the error probabilities of these algorithms are depicted in Figure 11. As shown, the maximum error of WiFi/MEMS is far smaller than the other two. The cumulative error percentages of MEMS and WiFi/MEMS are close when the error is smaller than 0.5 m, but WiFi/MEMS solution quickly achieves the best performance when the error is larger than its mean error, showing a very stable estimation. In all, this figure illustrates the advantage of EKF-based WiFi/MEMS integration algorithm as well. The detailed estimation errors and running time of these algorithms are listed in Table 4. As shown, the maximum error of WiFi/MEMS is 1.2498 m, which is 16.07% of MEMS and 23.97% of WiFi. The mean error of WiFi/MEMS is 0.6835 m, which is 24.67% of MEMS and 36.25% of WiFi. The root mean square (RMS) of WiFi/MEMS position errors is 0.7926 m, which is 20.59% of MEMS and 36.60% of WiFi. Therefore, the EKF-based WiFi/MEMS algorithm proposed in this paper has improved the estimation accuracy. Besides, it has low computational complexity as the running time is short. Furthermore, the error probabilities of these algorithms are depicted in Figure 11. As shown, the maximum error of WiFi/MEMS is far smaller than the other two. The cumulative error percentages of MEMS and WiFi/MEMS are close when the error is smaller than 0.5 m, but WiFi/MEMS solution quickly achieves the best performance when the error is larger than its mean error, showing a very stable estimation. In all, this figure illustrates the advantage of EKF-based WiFi/MEMS integration algorithm as well. Micromachines 2019, 10, x FOR PEER REVIEW 14 of 21 Figure 11. Cumulative error percentages.

Results Using Different Numbers of Access Points (APs)
To further validate the navigation performance of the proposed WiFi/MEMS solution, estimation results using different numbers of APs and in different loops are discussed as follows.
As shown in Figure 12, the algorithms using 20 APs, 15 APs, 10 APs and 5 APs are compared. In this figure, the results of 20 APs and 15 APs are very close. The worst is the estimation using 5 APs. However, it still keeps good performance in most areas, illustrating that the WiFi/MEMS solution still works well when there are very few APs available.
The detailed estimation errors using different numbers of APs are listed in Table 5. As shown, the maximum error is the smallest when using 10 APs, while the mean error and the RMS of position errors are the smallest when using 15 APs. Therefore, the result of 15 APs fits the best. The mean error when using 15 APs is 0.6823 m, which is 82.66% of 5 APs, 94.41% of 10 APs, and 99.82% of 20 APs. The RMS of position errors using 15 APs is 0.7868 m, which is 84.12% of 5 APs, 99.27% of 20 APs, and 99.42% of 10 APs. As a result, more APs do not necessarily mean more accurate estimation.
The error probabilities using different numbers of APs are depicted in Figure 13. As shown, there is no big difference between the results of 20 APs and 15 APs. Obvious difference appears when the results of 10 APs and 5 APs are considered. In all, the positioning result using 15 APs has the best navigation performance and the result using 5 APs is the worst.

Results Using Different Numbers of Access Points (APs)
To further validate the navigation performance of the proposed WiFi/MEMS solution, estimation results using different numbers of APs and in different loops are discussed as follows.
As shown in Figure 12, the algorithms using 20 APs, 15 APs, 10 APs and 5 APs are compared. In this figure, the results of 20 APs and 15 APs are very close. The worst is the estimation using 5 APs. However, it still keeps good performance in most areas, illustrating that the WiFi/MEMS solution still works well when there are very few APs available.
The detailed estimation errors using different numbers of APs are listed in Table 5. As shown, the maximum error is the smallest when using 10 APs, while the mean error and the RMS of position errors are the smallest when using 15 APs. Therefore, the result of 15 APs fits the best. The mean error when using 15 APs is 0.6823 m, which is 82.66% of 5 APs, 94.41% of 10 APs, and 99.82% of 20 APs. The RMS of position errors using 15 APs is 0.7868 m, which is 84.12% of 5 APs, 99.27% of 20 APs, and 99.42% of 10 APs. As a result, more APs do not necessarily mean more accurate estimation.
The error probabilities using different numbers of APs are depicted in Figure 13. As shown, there is no big difference between the results of 20 APs and 15 APs. Obvious difference appears when the results of 10 APs and 5 APs are considered. In all, the positioning result using 15 APs has the best navigation performance and the result using 5 APs is the worst.

Results in Different Loops
To verify the stability of the proposed WiFi/MEMS solution, the tester walked along the loop corridor for four loops continuously. Also, a different smartphone was used to record the accelerations and angular velocities in order to prove the validity of the proposed WiFi/MEMS solution on various devices. The positioning results in different loops are shown in Figure 14. As shown, there is no obvious difference among the first three loops, and a little decrease of estimation accuracy occurs in the fourth loop. Since the proposed algorithm is the integration of WiFi and MEMS, it is inevitable that it is affected by the accumulated errors from MEMS. However, this algorithm can control these errors within a relatively lower level. Besides, further work should focus on how to compensate them at certain points.
The detailed estimation errors in different loops are listed in Table 6. As shown, the smallest of mean errors appears in Loop 2, while the maximum error and the RMS of errors are the smallest in The error probabilities in different loops are depicted in Figure 15. As shown, the order of the four loops varies in different intervals. Besides, the accuracy does not vary remarkably among the four loops. In all, the stability and validity on different devices of the proposed algorithm have been proven.

Results in Different Loops
To verify the stability of the proposed WiFi/MEMS solution, the tester walked along the loop corridor for four loops continuously. Also, a different smartphone was used to record the accelerations and angular velocities in order to prove the validity of the proposed WiFi/MEMS solution on various devices. The positioning results in different loops are shown in Figure 14. As shown, there is no obvious difference among the first three loops, and a little decrease of estimation accuracy occurs in the fourth loop. Since the proposed algorithm is the integration of WiFi and MEMS, it is inevitable that it is affected by the accumulated errors from MEMS. However, this algorithm can control these errors within a relatively lower level. Besides, further work should focus on how to compensate them at certain points.
The detailed estimation errors in different loops are listed in Table 6. As shown, the smallest of mean errors appears in Loop 2, while the maximum error and the RMS of errors are the smallest in     The error probabilities in different loops are depicted in Figure 15. As shown, the order of the four loops varies in different intervals. Besides, the accuracy does not vary remarkably among the four loops. In all, the stability and validity on different devices of the proposed algorithm have been proven.

Conclusions
This paper presents a novel WiFi/MEMS fusion structure for indoor navigation. In the WiFi fingerprinting scheme, a partition solution called "moving partition" is originally proposed. With "moving partition", the computation time decreases by more than half compared with the traditional WKNN method. Also, the direction measurement of the MU using the information of four latest positioning points from WiFi is presented, and a "turn detection" is applied before the direction fusion. Then a novel two-stage structure to integrate the information from WiFi/MEMS sensors using the EKF is proposed. In the first stage, the information from the gyroscope and the accelerometer is fused using attitude-determination EKF to calculate the Euler angles. In the second stage, the information from PDR and WiFi is fused using position-tracking EKF to calculate the MU position.
With these improvements, the navigation performance of the proposed WiFi/MEMS integration solution is compared with results from WiFi and MEMS. Experiment results show that the RMS position error of the proposed WiFi/MEMS solution is 0.7926 m, which is 20.59% of MEMS and 36.60% of WiFi. Furthermore, the presented WiFi/MEMS algorithm still works well when there are very few APs available and its stability has been proven. Therefore, the proposed WiFi/MEMS solution has been validated in indoor tests, and its performance is illustrated to be very competitive for indoor navigation. Furthermore, it can be easily applied on most handheld devices, such as smartphones, and presents broad market prospect. Acknowledgments: This work was sponsored by the National Natural Science Foundation of China (grant number 11501022). The authors fully appreciate the financial support. The authors would like to thank the reviewers and the editor for many valuable suggestions that helped improve this paper.

Conclusions
This paper presents a novel WiFi/MEMS fusion structure for indoor navigation. In the WiFi fingerprinting scheme, a partition solution called "moving partition" is originally proposed. With "moving partition", the computation time decreases by more than half compared with the traditional WKNN method. Also, the direction measurement of the MU using the information of four latest positioning points from WiFi is presented, and a "turn detection" is applied before the direction fusion. Then a novel two-stage structure to integrate the information from WiFi/MEMS sensors using the EKF is proposed. In the first stage, the information from the gyroscope and the accelerometer is fused using attitude-determination EKF to calculate the Euler angles. In the second stage, the information from PDR and WiFi is fused using position-tracking EKF to calculate the MU position.
With these improvements, the navigation performance of the proposed WiFi/MEMS integration solution is compared with results from WiFi and MEMS. Experiment results show that the RMS position error of the proposed WiFi/MEMS solution is 0.7926 m, which is 20.59% of MEMS and 36.60% of WiFi. Furthermore, the presented WiFi/MEMS algorithm still works well when there are very few APs available and its stability has been proven. Therefore, the proposed WiFi/MEMS solution has been validated in indoor tests, and its performance is illustrated to be very competitive for indoor navigation. Furthermore, it can be easily applied on most handheld devices, such as smartphones, and presents broad market prospect.