Optimization-Based Wi-Fi Radio Map Construction for Indoor Positioning Using Only Smart Phones

Fingerprinting-based Wi-Fi indoor positioning has great potential for positioning in GPS-denied areas. However, establishing a fingerprinting map (also called a radio map) prior to positioning (site survey) is normally a labor-intensive task. This paper proposes a method for easy site survey without need for any extra hardware. The user can conduct the site survey adopting only a smart phone. The collected inertial-based readings are processed using the pedestrian dead-reckoning algorithms to generate a raw trajectory. Then a factor graph optimization method is proposed to re-estimate the trajectory by adding constraints originated from collected Wi-Fi fingerprints and landmark positions. The proposed method is verified through an experiment in a mall. The mean positioning error is 1.10 m and the maximum error is 2.25 m. This level of positioning accuracy is considered sufficient for radio map generation purposes. A classical baseline algorithm, the k-Nearest Neighbor (kNN) algorithm, is adopted to test the positioning performance of the radio map (RM), which also validates the quality of the constructed RM from the proposed method.


Introduction
Positioning in GPS-denied areas has been attracting great attention for decades and currently there are many solutions for that. Fingerprinting-based Wi-Fi positioning is one of these solutions with great potential for the following two reasons: (1) No extra hardware is needed. The users only need to carry Wi-Fi-enabled devices, such as smart phones, to locate themselves in indoor environments with abundant Wi-Fi signals. This feature renders the solution suitable for the consumer indoor positioning market as either Wi-Fi-enabled devices or Wi-Fi signals are prevalent in many indoor environments, such as malls and airports; (2) The positioning error is within limited bounds. Unlike inertial-based indoor positioning methods, such as [1,2], the positioning error will not accumulate with time.
The working flow of fingerprinting-based Wi-Fi indoor positioning has two phases: the offline phase (also denoted as site survey phase) and the online phase (also denoted as positioning phase). A fingerprint herein is defined as the received signal strength indication (RSSI) from different Wi-Fi access points (APs) at a fixed location in the environment. Normally, the fingerprint is a vector because there are RSSI from more than one AP. The site survey phase is essentially to associate the fingerprints to geometric positions in the environments. After the phase, each fingerprint corresponds to a position and thus a fingerprint radio map (RM) is established. As the RM is normally established offline, it is also called offline phase. The positioning phase is essentially positioning the user with a Wi-Fi-enabled device online. Each time a new fingerprint is collected by the device, it is matched The only extra information is some foreknown landmarks positions, which is commonly fulfilled because many indoor positioning applications needs some reference points to begin with. Some related work including basics of PDR and factor graph estimation is given in Section 2. Section 3 describes the trajectory generation method based on PDR and Section 4 describes the RM generation method based on factor graph optimization. Real-scenario experiments are carried out in Section 5 to validate the proposed method. Section 6 is the conclusion.

Related Work
As described in Figure 1, our method relies on trajectories generated from the sensors on the smart phone. This is possible because currently most smart phones have embedded Micro-Electro-Mechanical System (MEMS) accelerometers, gyroscopes and magnetometers. Factor graph-based optimization is widely adopted in simultaneous localization and mapping (SLAM) for finding the poses which best satisfies the measurements. In this section, we give a brief overview of the PDR algorithm and factor graph-based optimization.

Pedestrian Dead-Reckoning
The PDR algorithm consists of two aspects: orientation estimation and stepometer estimation [20]. Herein stepometer estimation includes step occurrence detection and step length estimation. For orientation estimation, the simplest form of the PDR algorithm is to use a simple Kalman filter for updating the orientation [21]. Classical step occurrence detection methods include peak detection [22] and cross-zero detection [23]. These methods assume that the peaks of the projected acceleration or the "cross-zero" points corresponds to new steps. Classical step length estimation method adopts a parametric model [24] and the parameter differs across persons. Noting that the PDR algorithm here avoids double integration of the accelerations to reduce quicker accumulation of acceleration inertial drifts. However, as both step occurrence detection and step length estimation are based on heuristic assumptions, additional positioning errors are introduced, e.g., inaccurate step counts and inaccurate step length estimation. Therefore, PDR is often a part of hybrid positioning solutions rather than a standalone one.

Factor Graph-Based Optimization
Factor graph model is in essence a graphic representation for estimation problems and it is widely adopted in SLAM. It is an alternative for sequential Bayesian estimation other than filter-based frameworks, e.g., Kalman filter and particle filter. In filter-based frameworks, the estimation problem is to recursively estimate a posterior and is suitable for online processing [25]. For factor graph optimization, the estimation problem is transformed to minimizing an error energy function. The error energy function is normally in a least square form and can represent the errors between the variables (needs to be estimated) derived "measurements" and the actual measurements. Unlike the filter-based framework, factor graph optimization estimates the variables in a batch and thus is processed offline.
Factor graph optimization generally consists of two steps: construct the factor graph (equivalent to form the error energy function) and optimize the graph. The first step differs across methods and implementations while the second step has general frameworks. It can be regarded as a general least square optimization (LSO) problem, which can be solved via iterative local linearizations using the Gauss-Newton or Levenberg-Marquardt [26] algorithms. By adopting the sparse nature of the graphs, the computational complexity can be greatly lowered using techniques such as Cholesky decompositions [27] and so on. As there already exists some mature and open-sourced methods for solving such LSO problem such as g2o [28] and ceres-solver [29], we focus on constructing the factor graph in this paper. In our implementation, we use the ceres-solver for the LSO problem.

Trajectory Generation Based on PDR
As aforementioned, the PDR algorithm consists of orientation estimation and stepometer estimation. In this paper a gradient descent-based orientation estimation algorithm is adopted, which adopts the measured magnetic direction and acceleration to compensate for the orientation error derived from integration over only angular rates. As for the stepometer estimation, we adopt the classical peak detection and heuristic step length estimation algorithms. With the estimated step length L t and the heading θ t at the current step at t, we can derive the current position (x t , y t ) from the previous step (x t−1 , y t−1 ) x t = x t−1 + L t cos(θ t ) y t = y t−1 + L t sin(θ t ) Noting that as Equation (1) shows, the positioning error has accumulative nature because the next position is dependent on the previous one. The processing flow of the PDR algorithm adopted in our paper in Figure 2.

Orientation Estimation
The gradient descent-based orientation estimation method was proposed by [30], which was originally adopted for an inertial-based human motion tracking system. Here we give a brief overview of how it is adopted for orientation estimation in PDR. The three steps are as follows:

1.
Orientation updates based on angular rate measurements.
To avoid singularities, a quaternion representation is adopted here. The attitude of the phone can be updated according to the angular rate measurements in Equation (2) here (ω x , ω y , ω z ) is the measured angular rate from the gyroscope. The superscript S denotes the sensor frame and the subscript N denotes the navigation frame. S Nq denotes the quaternion derivative describing change rate of the navigation frame relative to the sensor frame. ⊗ is the quaternion product operation and the bar ofq denotes the normalization operation of a quaternion. For discrete time implementation, it is δt is the sampling interval of the gyroscope and we set it to 0.01 s in our implementation. Using Equation (3), the quaternion of the attitude can be updated. However, the error of the attitude is accumulative due to gyroscope drifts.

2.
Forming the error function. To estimate the attitude more accurately, the measurements from the magnetometer and the accelerometer is adopted. An error function f (.) is formed for such purposes in Equation (4).
The error function denotes the differences of normalized measurements (accelerometer measurements or magnetometer measurements) between representation in the sensor frame ( SM ) and derived representation in the sensor frame ( S Nq * ⊗ NM ⊗ S Nq ) from the representation in the navigation frame ( NM ). Noting that SM and NM has a normalized quaternion representation.
Specifically, for the accelerometer measurements, SM and NM is replaced by Sā and Nḡ respectively, where Sā = (0, a x , a y , a z ) Nḡ = (0, 0, 0, 1) here the (a x , a y , a z ) is the normalized readings from the accelerometer. Noting that there is only one non-zero element in Nḡ , because when the phone is stationary or quasi-stationary, the only accelerometer should be the z-axis gravity.
For the magnetometer measurements, SM and NM is replaced by Sm and Nb respectively, where here the (m x , m y , m z ) is the normalized reading from the magnetometer. In the navigation frame, the magnetic field can be considered only has horizontal component and vertical component, so Nb only has two component. With the magnetometer readings and the accelerometer readings, the combined error function can be written as where f g (.) is formed by replacing SM and NM in Equations (4) and (5), and f b (.) is formed by replacing SM and NM in Equations (4)- (6). Then we have and q 1 , q 2 , q 3 , q 4 are the components of the quaternion S Nq est,t−1 .

3.
Gradient descent for orientation estimation. To minimize the error function, the gradient descent method is adopted. Noting that here we only update the current estimation per time sample according to and γ t is a proper scale controlling descending velocity. Same as [30], γ t is set to where δt is the sampling interval.
Combined with Equation (3), the attitude update process can be written as where the coefficient β is ω err,max is the maximum gyroscope measurement error. The derivation of β is explained in detail in [30] and is directly used in our paper. Then from the attitude quaternion, we can solve for the heading angle as the orientation θ t .

Stepometer Estimation
For step occurrence detection we adopt the classical peak detection method. For the step length estimation, we adopt a heuristic parametric model in [24] as where a max and a min are the maximum and minimum acceleration during the step. K is a parameter which should be different across user to user. Here we set is as a constant 0.5. Noting that the step length estimation error is one of the error sources of PDR-based position tracking. The trajectories generated from PDR will later be re-estimated using Wi-Fi fingerprints and some pre-known landmark positions.
To sum up, the processing flow of orientation estimation is shown in Figure 3, where z −1 denotes one sample interval time back.
Error function Update according to angular rate Figure 3. The processing of orientation estimation using readings from the accelerometer, magnetometer and gyroscope.

Factor Graph Optimization for RM Generation
The factor graph for RM generation in our method is shown in Figure 4. The variables in the circles denotes the poses at different times, which needs to be estimated. In our implementation, a pose consists of three components where x t and y t are the horizontal positions and θ t is the heading. From the factor graph, both Wi-Fi-based edges and PDR-based edges denote constraints between two poses, while the landmark-based edge denotes a constraints to a single pose. An error energy function can be drawn from the factor graph All the three sources of error energy have a quadratic form where e (.) (.) denotes the error between the actual measurements and measurements derived from the poses to be estimated. Ω (.) denotes the information matrix of the measurements. By minimizing (s 1:t ), the maximum likelihood estimation of poses can be acquired. As the minimization process can be regarded as a general LSO problem, we adopt the ceres-solver [29] for solving the problem. Here we focus on how to form the different sources of error energy functions. After the optimization, the sequences of optimal poses are acquired. With these poses and the collected fingerprints, a raw RM can be established with associated fingerprints and geometric positions. We use an interpolation and extrapolation method in [31] to transform the raw RM into a grid-based one and make it ready for the online positioning phase.

PDR-Based Error Energy
The PDR algorithm can provide inertial generated trajectories. These trajectories (time sequences of poses) can be regarded as the initial values of the poses to be estimated or optimized. The PDR algorithm can also provide pose changes between adjacent steps. The pose change from the PDR algorithm is where L PDR t is the step length from PDR and δθ PDR t is the heading change from PDR. The pose change derived from the pose variables s is Then the PDR-based error energy is where the error e PDR (.) is dependent on adjacent pose variable s t−1 , s t and the pose change from the PDR process u PDR The information matrix for the PDR-based error has the form where In f o(L t ) and In f o(δθ t ) should be the reciprocal of the variance of PDR-based step length and heading change estimation respectively, In our implementation, In f o(L t ) and In f o(δθ t ) are set to 20 and 500 respectively. If no other types of error energy are available, the minimum of e PDR (.) should be zero, when u s t equals u PDR t at every step. In this situation, the optimal pose estimations are the poses in the inertial generated trajectories from PDR.

Wi-Fi-Based Error Energy
Wi-Fi-based error energy is formed using the following two steps: 1.
Find the distance between two fingerprints at the k th and q th step.
In Wi-Fi-based fingerprinting methods, a common assumption is often held true: if two fingerprints are with vicinity in signal space, then the positions where the fingerprints are collected are with vicinity in the coordinate space. In our method, we also find the correspondences of positions by solving for the vicinities in signal space. We compare two arbitrary Wi-Fi fingerprints f k and f q which are collected at the k th step and the q th step (k = q).
Then we define their distance in signal space like this using a metric similar to [6] d where the superscript i on f i k denotes the RSS from the i th AP in the vector f k , and N is the number of AP in the vector. The correspondences of the fingerprints and the pose variables are shown in Figure 5.

2.
Find the error e Wi f i (s k , s q , f k , f q ) according to the distance in the signal space.
In our implementation, if two fingerprints' distance is less than a pre-defined threshold, the distances of the corresponding poses should be within a threshold (with vicinity). Then we define the Wi-Fi-based error like this where d(s k , s q ) means the Euclidian distance between the horizontal positions of (x k , y k ) and (x q , y q ) calculated from the pose variables s k and s q . Figure 6 shows the relationships between the mean positioning errors and different values of d thres,rss in the experiment (details of the experiment will be described in Section 5). We can see that in our implementation, the mean error reaches the lowest around d thres,rss = 15. This value is thus adopted for creating Wi-Fi-based constraints.
Then the Wi-Fi-based error energy is where k and q are two arbitrary step index from 1:t and k = q. Noting that the error is a constant zero when d(f k , f q ) > d thres,rss as shown in Equation (25) and will not contribute to Equation (26). In our implementation, we only include the errors when d(f k , f q ) < d thres,rss . This will significantly reduce the number of constraints and is favorable in terms of computational cost for the optimization process later. Here the error e Wi f i (.), as well as Ω Wi f i are both scalars.

Landmark-Based Error Energy
Assuming we have a pre-defined landmark position p lm,j = (x lm,j , y lm,j ) and we have already established the correspondence to the pose variable s j at the j th step. This can be easily done by ask the user to press a button on the smart phone when walked to the landmark. Then the landmark-based error is e landmark (u j , p lm,j ) = (x lm,j − x j ) 2 + (y lm,j − y j ) 2 (27) where (x j , y j ) is the horizontal positions taken from the pose variable u j and the error e landmark (u j , p lm,j ) is also a scaler. Then the landmark-based error energy function is F landmark (s 1:t ) = ∑ j e 2 landmark (u j , p lm,j )Ω landmark (28) where the sum is over all recorded landmarks by the users and Ω landmark should be a relatively large number, because it is believed the landmark positions are accurate.

Experimental Setup
In our experiment, the Huawei Mate 9 smart phone is adopted. An Android application is developed for collecting data. The application has three main functions.

1.
Generate the raw trajectories based on the PDR algorithm. The sampling rate of the accelerometer, gyroscope and magnetometer sensors in the phone is set to 100 Hz. The readings from these sensors can be processed in real time and can generate inertial-based raw trajectories. These poses of the trajectories with timestamps of the phone's system time are saved as file.

2.
Collect Wi-Fi-based fingerprints. The Wi-Fi scanner on the phone is set to continuous scan mode with scanning interval of 1 s. However, the actual scanning interval can only reach about 2.5 s (due to system limitations). The fingerprints along with their collecting time are also saved as a file.

3.
Record landmarks by pressing the landmark button. When walks to a pre-defined landmark, the user can press the buttons on the phone to record the time and landmark number.
All the types of data are saved as file on the phone with its collecting time. Afterwards, the data can be synchronized and processed offline to generate the RM. We assess the accuracy of the generated RM by assessing the accuracy of the positions where the fingerprints are collected (or the trajectories).
In our implementation, we record as many landmarks as possible. In this way, a part of the landmark recordings can be taken to generate the RM, the left part as ground truth positions to assess the accuracy of the optimized poses (trajectories). In the experiment, the positions of the landmarks are measured with a total station with sufficient accuracy.

Raw Trajectories Based on PDR
In Figure 7, a user walks in a mall with a hand-held smart phone. The generated trajectories from the PDR algorithm are shown. It is obvious that the estimated trajectory with magnetometer readings is more consistent with the true trajectory than the one without magnetometer readings. This is because the orientation estimation is much more accurate using magnetometer readings. This validates the orientation estimation method adopted in this paper. However, even adopting magnetometer readings, the PDR trajectory still cannot reach sufficient accuracy (the trajectory does not fit the floor plan and the true trajectory well). Other information is needed to re-estimate the trajectory to improve accuracy.

Factor Graph Optimization Results
The PDR trajectory can be re-estimated using factor graph optimization if other types of information are available. Here we present the optimized trajectory using PDR trajectory and 1.

Wi-Fi fingerprints and landmark positions
Respectively. In this experiment, we have set 18 different landmarks with known positions. The user has walked to these landmarks for 88 times, so that there are 88 landmark recordings in total. We only take 20 of them for factor graph optimization and the left 68 recordings as ground truth positions to verify the accuracy. Figure 8a shows the constraints of poses derived from Wi-Fi fingerprints. If two poses are connected with a green line, it means the fingerprints collected at the two poses are with vicinity in the signal space (Wi-Fi distance less than a threshold). In this case, the two poses should be also with vicinity and the term of the error energy should grow with the distances between the two poses. Noting that there are some false alarm constraints and can be regarded as outlier constraints. Figure 8b shows the optimized trajectory using Wi-Fi fingerprints, which is more accurate than the original PDR trajectory.

Results for Fusing PDR Trajectory and Landmark Based Constraints
As mentioned before, the user has walked to the landmark for 88 times. However, we only randomly choose 20 of them as landmark constraints for optimization (training data), and the left is adopted to test the positioning accuracy (test data). As shown in Figure 9a Table 1 gives some statistics of the positioning errors using different types of constraints. For pure PDR results, adopting magnetometer readings as suggested in Section 3.1 can help improve the accuracy of the generated trajectory. Noting that the mean error can decrease from 11.35 m to 8.67 m. We can also see that either adopting Wi-Fi-based constraints or landmark based constraints can contribute to improve the positioning accuracy. The mean error of the optimized trajectory adopting all types of constraints can be decreased to about 1.10 m. In addition, the maximum error for the trajectory is only 2.25 m, which shows robustness for position estimation. The errors of the estimated trajectory are sufficient for RM generation purposes. After the graph optimization process, a series of positions (a trajectory) can be estimated. According to the timestamps of the positions and the timestamps of the fingerprints, a simple linear interpolation is made to solve for the positions where the RPs are. After interpolation, the positions of the RPs are available are shown in Figure 12. Noting that we only take one fingerprint at each location for factor graph creation purposes. The final RM includes all fingerprints collected. These fingerprints are directly adopted for Wi-Fi-based positioning using the classical kNN algorithm as the baseline approach. Experiments are carried out to show the performance of Wi-Fi-based positioning adopting the constructed RM. According to Figure 13, the CDFs of positioning errors at different times in the day are shown. We can see that about 90% of the errors are less than 5 m for the test in the afternoon (when the RM data are collected). Although in the morning and in the evening the positioning performances are worse, the accuracies are still considered enough for many commercial indoor positioning cases, and can demonstrate the good quality of the constructed RM.
Another experiment is carried out to test how the different types of devices can affect the positioning performance. Here we have shown the positioning errors for 3 different devices adopting the RM (constructed from Huawei Mate 9) in Figure 14. Not surprisingly, the positioning performance of the Xiaomi Mix2 and Samsung S9 is not as good as the Huawei Mate 9, because their measurements of RSS are different. However, this shows that heterogeneous devices do have a large impact on the positioning performance. An easy way for solving the problem is to carry different devices and construct different versions of RMs. The detailed issues of the heterogeneous devices are considered as another topic and will be studied in the future.

Conclusions
A method for generating Wi-Fi-based RM is proposed in this paper. The method can work without any extra hardware such as an IMU, much additional information such as a detailed indoor map, and any extra surveying process such as collecting Wi-Fi fingerprints at known positions. The user only needs a smart phone to collect inertial-based readings (from the inertial sensors in the phone), Wi-Fi fingerprints and landmark positions. The inertial-based readings are adopted to generate a PDR-based raw trajectory. Then the factor graph optimization method is adopted to re-estimate the trajectory using constraints provided by Wi-Fi fingerprints and landmark positions. An experiment is carried out in a mall with a smart phone for data collection. The results have shown that both Wi-Fi-based constraints and landmark-based constraints can contribute to accurate position estimations in the RM. The accuracy of the optimized trajectory using both Wi-Fi fingerprints and landmark positions can reach a mean error of 1.10m, which is considered sufficient for RM generation purposes. Then the constructed RM can be adopted for Wi-Fi-based positioning with satisfactory accuracies.
Author Contributions: J.T., X.F. and S.W. conceived and worked together to achieve this work. Y.R. performed the experiments. J.T. wrote the paper.