Smartphone-Based Indoor Integrated WiFi / MEMS Positioning Algorithm in a Multi-Floor Environment

Indoor positioning in a multi-floor environment by using a smartphone is considered in this paper. The positioning accuracy and robustness of WiFi fingerprinting-based positioning are limited due to the unexpected variation of WiFi measurements between floors. On this basis, we propose a novel smartphone-based integrated WiFi/MEMS positioning algorithm based on the robust extended Kalman filter (EKF). The proposed algorithm first relies on the gait detection approach and quaternion algorithm to estimate the velocity and heading angles of the target. Second, the velocity and heading angles, together with the results of WiFi fingerprinting-based positioning, are considered as the input of the robust EKF for the sake of conducting two-dimensional (2D) positioning. Third, the proposed algorithm calculates the height of the target by using the real-time recorded barometer and geographic data. Finally, the experimental results show that the proposed algorithm achieves the positioning accuracy with root mean square errors (RMSEs) less than 1 m in an actual multi-floor environment.


Introduction
In the recent decade, next generation techniques, indoor positioning and navigation have gained significant attention, since the signals from the widely-used global navigation satellite systems are often not hearable inside buildings.Furthermore, the indoor positioning and navigation approaches generally require higher accuracy and better adaptation to the environment compared to outdoor ones.Under such a circumstance, a number of positioning techniques have been studied and even used in many special scenarios, like Bluetooth, ultra-wide band (UWB), radio frequency identification (RFID) and WiFi fingerprinting-based positioning techniques [1][2][3][4].
As far as we know, the WiFi fingerprinting-based positioning technique has been much favored in the indoor and underground environments, due to the low device cost, wide infrastructure deployment and high positioning accuracy [5][6][7][8][9].However, the signal refraction, reflection, scattering and multi-path fading generally result in the low reliability of the received signal strength indicator (RSSI) measurements and, thereby, deteriorate the accuracy of fingerprinting-based positioning.To solve this problem, some previous positioning techniques by integrating WiFi fingerprinting and MEMS sensors are proposed in [10][11][12][13][14].
Since most of the current mobile devices are integrated with various sensors, like the inertial sensors, magnetometer and barometer, MEMS sensor-based positioning is becoming a popular relative and self-contained positioning technique.In generally, the MEMS sensor-based positioning features the advantages of low device cost, short-term accurate positioning results and independence of external noise [15][16][17][18][19].However, the associated accumulative error involved in MEMS sensor-based positioning is always considered one of the significant problems.
The three main contributions of this paper are summarized as follows.First of all, we rely on the gait detection approach instead of conducting acceleration integration to optimize the velocity calculation, as well as using the quaternion algorithm to improve the precision of the heading angle calculation.Second, we design a robust extended Kalman filer (EKF) by using the robust least squares estimation to reduce the accumulated errors involved in MEMS sensor-based positioning, as well as the large errors of WiFi fingerprinting-based positioning.Finally, to achieve three-dimensional (3D) positioning in a multi-floor environment, the floor height calculation algorithm is proposed.
The rest of this paper is organized as follows.Section 2 gives some related work on WiFi fingerprinting-based positioning systems, as well as the existing indoor WiFi/MEMS positioning systems.Section 3 presents the proposed integrated WiFi/MEMS positioning algorithm, as well as the height calculation approach.The experimental results by using the data from WiFi fingerprinting and MEMS sensors in an actual multi-floor environment are provided in Section 4. Finally, we conclude this paper in Section 5.

Related Works
As the most representative fingerprinting-based positioning systems, a RADAR system [4] relies on the K nearest neighbor (KNN) algorithm to infer the 2D locations of a static target in a building.However, the accuracy of motion tracking by using the RADAR system cannot be guaranteed, since only a small number of RSSI measurements are recorded at each fixed location.
To solve this problem, the authors in [9] proposed to use the Kalman Filter (KF) to improve the accuracy of motion tracking.One of the serious disadvantages of the approach in [9] is that the velocity of the target is assumed to be a fixed value adding a small Gaussian random variable.Thus, the tracking errors could be significantly large when the actual velocity of the target varies significantly.Furthermore, to estimate the velocity of the target in a real-time manner, the authors in [10] invented an integrated WiFi fingerprinting and inertial sensing-based positioning system in which the acceleration data of the target are record by a tri-axis accelerometer.However, the velocity of the target would not be accurate by using the Newton uniformly accelerated linear kinematic equations, since the MEMS sensors of smartphones are low precision and with a low output frequency.As a consequence, the accumulative error increases rapidly in a short time.
By considering the variations of WiFi RSSI measurements with respect to the physical locations, the authors in [11] proposed utilizing the signal propagation property to conduct localization.However, a precise signal propagation model in the indoor environment is always difficult to obtain.By taking the fluctuation of WiFi RSSI measurements and the output data of the accelerometer into consideration, a WiFi/magnetic, angular rate and gravity (MARG)-based positioning algorithm by using particle filtering (PF) is proposed in [12]; this algorithm can only be applied to 2D positioning, and the associated precision is insufficient.
To achieve 3D positioning, the K-means-based algorithm in [20] is selected to identify the floor on which the target is located.The performance of height estimation deteriorates seriously when the target is inside a staircase.In this paper, we first rely on the gait detection approach to reduce the errors of velocity estimation, as well as use the quaternion algorithm to improve the heading precision.Second, we design a robust EKF filter by using the robust least squares estimation to resist the errors involved in both MEMS-based sensing and WiFi fingerprinting-based positioning.Finally, we use the floor height calculation algorithm to achieve 3D positioning in a multi-floor environment.

System Description
The flow chart of the proposed indoor integrated WiFi/MEMS positioning algorithm is shown in Figure 1.There are four main modules contained in this system, namely WiFi fingerprinting-based positioning, velocity and heading estimation, robust EKF and height calculation modules.
The velocity and heading data obtained from the MEMS sensors, v and ϕ, together with the results of WiFi fingerprinting-based positioning are set as the input data of the robust EKF.The output data of the robust EKF is the estimated 2D coordinates of the target.After that, we integrate this estimated 2D coordinates and the height, which is calculated from the height calculation module, to output the estimated 3D coordinates of the target.

WiFi Fingerprinting-Based Positioning
In our system, the WiFi fingerprinting-based positioning involves two phases, the offline phase and online phase, as described in Figure 2.
In the offline phase, the RSSI measurements from all of the hearable access points (APs) at each reference point (RP) are recorded as the fingerprints, and the fingerprints and their corresponding Cartesian coordinates are then used to construct the fingerprint database.In the online phase, the newly recorded RSSI measurements are matched against the pre-constructed fingerprint database to obtain the estimated locations of the target.In the indoor environment, there could be large positioning errors when RSSI measurements with significant fluctuation are used for positioning.To solve this problem, we rely on the predicted EKF state to smooth the WiFi RSSI fluctuation.Specifically, we select K (K > 1) RPs' RSSI vectors recorded in the database with the minimal physical distances from the predicted EKF state.Then, we use these RPs' RSSI vectors to calculate the predicted RSSI vector. where is the i-th minimal physical distance from the predicted EKF state.RSSI i is the i-th RSSI vector recorded in database at the i-th RP.Then, the RSSI measurements can be smoothed as: where kw is the weighting coefficient.RSSI measurement n is the measurement RSSI vector.After that, the position results are obtained by using the weighted K nearest neighbor (WKNN) algorithm.

Velocity and Heading Estimation
We rely on the three-axis accelerometer, three-axis gyroscope and three-axis magnetometer in a smartphone to estimate the velocity and heading angles of the target.As can be seen from Figure 3, we first eliminate the device noise, as well as smooth the waveform with the help of a median filter and a mean filter, respectively.After that, we estimate the velocity based on the triaxial accelerometer data and, meanwhile, the heading angles by using the quaternion algorithm.

Velocity Estimation
Based on the physiological characteristics of people, the waveform of the three-axis accelerometer modulus values describes the cyclical changes.The cyclical changes can be then used to detect the steps of people.In concrete terms, we calculate the three-axis accelerometer modulus values in Equation (3): where a x , a y and a z are the output values of the triaxial accelerometer after the mean filter in x, y and z directions, respectively.To calculate the steps of people, we detect the peak points of the curve of the accelerometer modulus by using the finite impulse response (FIR) low-pass filter [16].In Figure 4, ∆N is the number of sample points between every two consecutive steps.Since the frequency of the output data from MEMS sensors is f s , the time interval during the k-th step is calculated as: For simplicity, by assuming that the velocity of the target during each step is a constant, the velocity for the k-th step is calculated by: where P k is the length of each step.We set P k = 0.68 m for the adults.

Heading Estimation
In this paper, we use the quaternion algorithm to estimate the heading angles of the target.The quaternion algorithm features the advantages of low computation cost and wide applications.
As shown in Figure 5, we define a local smartphone x-y-z frame with respect to the mobile platform, as well as a reference coordinate frame in which the E-axis points east, the N-axis points north and the U-axis points upwards with respect to the horizon ground.The attitude rotation matrix depicts the relationship of the coordinates in the reference coordinate frame and in the local smartphone x-y-z frame, such that: where T b n (q) is the attitude rotation matrix.q = q 0 +q 1 i+q 2 j +q 3 k is the quaternion.x n y n z n T is the vector of coordinates in the reference coordinate frame.
is the vector of coordinates in the local smartphone x-y-z frame.Based on the relationship between the attitude rotation matrix and quaternion [16], the rotation matrix is calculated as: 2(q 1 q 2 + q 0 q 3 ) 2(q 1 q 3 − q 0 q 2 ) 2(q 1 q 2 − q 0 q 3 ) q 2 0 − q 2 1 + q 2 2 − q 2 3 2(q 2 q 3 + q 0 q 1 ) 2(q 1 q 3 + q 0 q 2 ) 2(q 2 q 3 − q 0 q 1 ) q In Equation ( 7), the attitude rotation matrix is determined when the quaternion, q, is obtained.Based on the vector differential equation in rigid body angular motion, we have: where w = 0 + w x i + w y j + w z k is the quaternion of the attitude angular velocity in the local smartphone x-y-z frame.The notation "⊗" denotes the multiplication of quaternion [16].Equation ( 8) can also be represented in a matrix form, such that: where w x , w y and w z are the angular velocities in the x, y and z directions in the coordinates of the smartphone.q = q 0 q 1 q 2 q 3 T is the vector of the quaternion.The discrete-time model corresponding to Equation ( 9) is described as: where T s is the sampling interval.I is a unit matrix.q(0) is the initial quaternion.The quaternion is a standardized quaternion, which means || q|| = 1.We normalize the quaternion by Equation (11).We use Equation (7) to update the attitude rotation matrix when the solutions of Equations ( 10) and ( 11) have been obtained.In this case, the heading angles can be estimated by using the attitude rotation matrix.
In practical applications, the low-cost gyroscope in a smartphone is not ideal.Thus, the heading angles could involve accumulated errors due to the gyroscope drift.Therefore, the integration of the gyroscope, accelerometer and magnetometer for the sake of calculating the attitude angles can effectively improve the heading precision.To achieve this goal, the EKF model is considered in this paper to integrate all of the sensing information to obtain the accurate estimation of the heading angles.The EKF model is described as: where q = q 0 q 1 q 2 q 3 T is the state vector.A m = (I + 1 2 Ω(wT s )) is the state transition matrix.W m is the vector of the processing of the white Gaussian noise.Y m+1 is the measurement vector.V m+1 is the vector of the observation the white Gaussian noise.The measurement model is constructed by integrating the normalized accelerometer and magnetometer measurement vectors, as shown in Equation (13).
where a m+1 = a x a y a z T is the vector of the accelerometer measurement in the x, y and z directions, respectively.c m+1 = c x a y a z T is the vector of the three-axis magnetometer measurement.g = 0 0 1 T is the vector of the normalized gravity in the reference coordinate frame.h = 0 b y b z T is the vector of the normalized magnetic field intensity.b y = c 2 x + c 2 y .b z = c z .From the observation equation, we can find that the relationship between the state vector and the measurement vector is nonlinear.We linearize the first part on the right side of Equation ( 11) to obtain the observation matrix Φ m+1 in Equation (14).

EKF Model
The locations of people depend on the walking velocity and heading.On this basis, we set the state vector X = x y v ϕ T , which consists of the locations of the people (x, y), the velocity v and the heading ϕ.The EKF model is shown in Equation (16). where is the state vector.W n−1 is the process noise vector obeying the zero-mean Gaussian distribution.
The measurement vector T consists of the locations estimated by WiFi fingerprinting-based positioning (x W iF i , y W iF i ) and the velocity and heading data obtained from MEMS sensors, v M EM S and ϕ M EM S . where is the measurement vector.V n is the measurement noise vector obeying the zero-mean Gaussian distribution.

Robust Least Squares Estimation
Based on the robust least squares estimation, we distribute smaller weights to the measurement vector, , which correspond to the residuals larger than the standard deviation of the measurements.By using the IGG3 weight function [22], the weights of measurements are calculated by: where bi and b i are the diagonal elements in the equivalent weight matrix and the weight matrix, respectively.The standard residual vector u i is calculated by: where v i is the i-th residual vector.
is the mean square error.q v i is the reciprocal of b i .σ 0 = med{ √ q v i , v i }/0.6745,where the notation "med" stands for the median calculation.The values of k 0 and k 1 are in the ranges of [1, 1.5] and [2.5, 3.0], respectively [22].Finally, the prediction and updating process of the robust EKF is described as follows.
• Prediction process: • Updating process: where n is the Jacobian matrix.Kn is the gain of the robust EKF.P n is the error covariance matrix.H n is the measurement sensitivity matrix.I is a unit matrix.Bn is the equivalent weight matrix.Rn = Bn − .

Altitude Estimation
The altitude is estimated based on the characteristic that the atmospheric pressure measured by the barometer decreases as the altitude increases [23,24].The process of altitude calculation is described as follows.
When the force balance is preserved, the air is in a stationary condition, as shown in Figure 6.In Figure 6, the static atmosphere equation in the vertical force condition is described by: where P is the atmospheric pressure.g is the acceleration of gravity.ρ is the gas density.h is the geopotential height.S is is the cross-sectional area in the vertical direction.As discussed in [23], the ideal gas equation is defined as: where T is the absolute temperature.R = 287.05287m 2 /Ks 2 is the universal gas constant.Based on Equations ( 22) and ( 23), we obtain: By conducting the integration calculation on both sides of ( 23), one has: where P 0 is the initial atmospheric pressure.For simplicity, we assume that the gravity acceleration, g, is a constant.Then, the temperature is calculated by: where β is the variation rate of the vertical temperature.h 0 and T 0 are the initial geopotential height and the absolute temperature.The values of the three groups of parameters h 0 , T 0 , β and P 0 that are used in this paper are shown in Table 1 [24].
Based on Equations ( 25) and ( 26), the geopotential height, h, is calculated by: where P s is the atmospheric pressure measured by the barometer.We assume that the altitude is equal to the geopotential height for the sake of simplicity.In the staircase scenario, the accuracy of the WiFi-based height calculation deteriorates seriously.Furthermore, there is no significant impact on accuracy by adding the height into the state vector in the condition that the target is on a floor.On this basis, the height is calculated separately in our system.
The motion behaviors of the people inside a building can be simply classified into two categories, walking up or down stairs in staircases and walking on a floor.Figure 7 shows the flow chart of height calculation.In our experiments, the step lengths of the people with respect to the motion behaviors in a staircase and on a floor are set to be 0.4 m and 0.68 m, respectively.
When the target is located in a staircase, we first use Equation (25) to estimate the altitude of the target, h 1 .Second, we calculate the height of the target based on the distance between h 1 and the altitude of the entrance of staircase h 2 , ∆h = h 1 − h 2 , as shown in Figure 8.
In Figure 8, by setting a threshold λ, if |∆h| ≤ λ, we set the height of the target in the current step as equal to the height of the target in the previous step.If |∆h| > λ and ∆h > 0, we set the height of the target in the current step as the previous height, adding a stair height h stair .Otherwise, we set the height of the target in the current step as the previous height, subtracting h stair .
When the target is located on a floor, we set the height of the target equal to the current floor height.Furthermore, the steps of the judgment of whether the n-th location of the target is in a staircase or on a floor are as follows.

Experimental Results
The testbed is selected on the first and second floors in a building at a university.These first and second floors have different dimensions of 64.6 × 18.5 m 2 and 81.2 × 18.5 m 2 , respectively, as shown in Figure 9.There are 10 D-Link DAP 2310 APs (marked in red) deployed in this environment, named orange, pear, apple, banana, coco, blackberry, cherry, lemon, mango and grape, respectively.The RPs are uniformly calibrated with an interval of 0.6 m.In our experiments, a Samsung Galaxy S3 smartphone, which is integrated with a WiFi module, accelerometer, gyroscope, magnetometer and barometer, is selected as the receiver.We invented two apps, WifiSensors and WifiLocation, to conduct MEMS sensors and WiFi RSSI recording.The recorded data are saved in the security digital (SD) card with the frequency of recording equal to 50 Hz.
The real path of the target is shown in Figure 10.Specifically, the target starts the motion at the starting point, A, on the first floor and goes straight to the entrance of a staircase, B. After that, the target goes upstairs to Location C, which is the entrance of this staircase on the second floor, and then continues to go to the entrance of another staircase, D. Finally, the target goes downstairs and back to the starting point, A. During the testing, we always keep the smartphone in the direction of walking in the system.In this case, the orientation of the smartphone is not fixed.The path distance is about 107 m, and the walking time is 140 s.
Figure 11a shows the estimated paths by using the conventional MEMS sensor-based positioning (MSBP) approach [16], the WiFi fingerprinting-based positioning (WFBP) approach [4] and the proposed integrated WiFi/MEMS positioning (IWMP) approach.The results in Figure 11a prove that the proposed approach effectively reduces the accumulated errors involved in MSBP and, thereby, significantly improves the accuracy of 3D positioning in a multi-floor environment.In Figure 11b, we observe that in some certain areas, the results of WFBP exhibit significant errors, which result in a standard deviation of positioning errors larger than 16 m, while the proposed approach achieves a standard deviation of positioning errors smaller than 1 m.
The cumulative distribution functions (CDFs) of the errors for height estimation by adopting the proposed height calculation approach and the conventional barometer-based height calculation approach [24] and K-means-based height calculation approach [20] in IWMP, MSBP and WFBP,  respectively, are compared in Figure 12a.From Figures 11a and 12a, we can observe that the results of the barometer-based height calculation approach are not stable, and the performance of the K-means-based height calculation approach deteriorates seriously when the target is inside a staircase.The CDFs of errors for 3D positioning by using the IWMP, MSBP and WFBP approaches are also compared in Figure 12b.As shown in Table 2, we can find that the proposed approach achieves the root mean square error (RMSE) of 0.8 m, and 90% of the errors are smaller than 1.7 m, which is much better than the accuracy performance of the conventional MSBP and WFBP approaches.
In general, there are three main reasons that the proposed algorithm can achieve an accuracy of 1 m.First of all, since the test bed is selected in long and straight corridors, we can easily detect most of the large errors by WiFi positioning when the initial locations of the target are obtained.Second, we only use the results of WiFi positioning with errors smaller than 5 m to integrate with MEMS sensor-based positioning for the sake of avoiding the influence of large errors from WiFi positioning.As can be seen from Figure 12b, we observe that about 33% of the errors from WiFi positioning in our system is smaller than 5 m.Third, the robust EKF is an adaptive filtering approach, which is able to adaptively adjust the weights of the measurement vector.

Conclusions
In this paper, we proposed a novel smartphone-based indoor integrated WiFi/MEMS multi-floor positioning algorithm to conduct 3D positioning in a multi-floor environment.The experimental results show that our approach can reduce the accumulated error involved in MEMS sensor-based positioning, as well as the significant errors of WiFi fingerprinting-based positioning.Compared to the conventional MEMS sensor-based positioning and WiFi fingerprinting-based positioning approaches, our approach achieves higher accuracy performance with an RMSE of 0.8 m and 90% of the errors smaller than 1.7 m for 3D positioning.However, a better way to modify the step lengths to adapt to different people forms interesting work for the future.

Figure 1 .
Figure 1.Flow chart of the proposed system.

Figure 3 .
Figure 3. Flow chart of velocity and heading estimation.

Figure 4 .
Figure 4. Modulus values of the accelerometer.

Figure 6 .
Figure 6.Force balance in the air in the stationary condition.

Figure 7 .
Figure 7. Flow chart of the height calculation.

Figure 8 .
Figure 8. Height calculation in a staircase.

Figure 9 .
Figure 9. Layout of the first and the second floors.

Figure 10 .
Figure 10.Real path of the target.

Figure 11 .
Figure 11.Results of positioning in the x-y-z plane and the x-y plane.(a) Results of positioning in the x-y-z plane.(b) Results of positioning in the x-y plane.

Figure 12 .
Figure 12.The cumulative distribution functions (CDFs) of errors for height calculation and 3D positioning.(a) CDFs of errors for height calculation.(b) CDFs of errors for 3D positioning.