Extended Kalman Filter for Real Time Indoor Localization by Fusing Wifi and Smartphone Inertial Sensors

Indoor localization systems using WiFi received signal strength (RSS) or pedestrian dead reckoning (PDR) both have their limitations, such as the RSS fluctuation and the accumulative error of PDR. To exploit their complementary strengths, most existing approaches fuse both systems by a particle filter. However, the particle filter is unsuitable for real time localization on resource-limited smartphones, since it is rather time-consuming and computationally expensive. On the other hand, the light computation fusion approaches including Kalman filter and its variants are inapplicable, since an explicit RSS-location measurement equation and the related noise statistics are unavailable. This paper proposes a novel data fusion framework by using an extended Kalman filter (EKF) to integrate WiFi localization with PDR. To make EKF applicable, we develop a measurement model based on kernel density estimation, which enables accurate WiFi localization and adaptive measurement noise statistics estimation. For the PDR system, we design another EKF based on quaternions for heading estimation by fusing gyroscopes and accelerometers. Experimental results show that the proposed EKF based data fusion approach achieves significant localization accuracy improvement over using WiFi localization or PDR systems alone. Compared with a particle filter, the proposed approach achieves comparable localization accuracy, while it incurs much less computational complexity.


Introduction
Locating mobile objects enables various location based services [1] including object finding, human tracking, and emergency management, etc. In outdoor environments, Global Navigation Satellite Systems (GNSS) have been widely used in mobile devices and provided reasonable localization accuracy performance. Unfortunately, due to the GNSS signal attenuations, they are incapable of tracking indoors, where people spend the majority of their time. Though various indoor localization systems, such as WiFi localization using received signal strength (RSS) [2], ultra-wideband [3], radiofrequency identification (RFID) [4], and inertial sensors [5], have been developed, it is still a challenging task to provide accurate indoor localization with low cost.
WiFi localization systems using RSS have been considered as the most popular indoor localization approach due to its cost effectiveness. RSS readings can be easily collected by common smartphones with WiFi modules installed under the pervasively available WiFi infrastructures. The most widely used method for WiFi localization is a fingerprinting [6,7] based architecture. It collects RSS data from access points (APs) on predefined reference points to construct a database called radio map during offline phase, while it matches real time collected RSS with radio map to estimate the location during online phase. However, accurate localization results cannot be guaranteed by WiFi localization due to the severe RSS fluctuations [8,9] caused by complex indoor radio propagation conditions.
On the other hand, more and more smartphones with inertial sensors built in, including gyroscopes and accelerometers, make it feasible to deploy pedestrian dead reckoning (PDR) systems [10,11] in our daily lives. PDR systems estimate relative displacement by step detection and user heading estimation. If the initial user location is known, accurate absolute location estimation may be achieved when a pedestrian travels a short distance. In addition, PDR systems on smartphones are self-contained without requiring any external infrastructures. However, PDR systems incur drift error accumulations [12][13][14] along walking distances, especially for inexpensive but noisy inertial sensors built in smartphones.
Both systems mentioned above have their limitations and complementary strengths. WiFi localization systems provide necessary corrections for PDR systems to bind the accumulative drift errors, while PDR systems enable continuous tracking and smooth the localization results. Therefore, it is essential for indoor localization to fuse WiFi localization and PDR, which will obtain more significant performance improvement rather than deploying them alone.
Even though a lot of work [15][16][17][18][19][20][21][22] has been done in fusing both systems, some critical problems still need to be addressed to enhance accuracy and feasibility. On the one hand, previous data fusion approaches mainly focus on deploying a particle filter [18][19][20][21], which is computationally expensive and should be run on a server. However, rather than in a server, the localization system runs on a smartphone and is preferred due to its ability to protect the user's privacy. Furthermore, the server based approaches involve a time consuming communication process, which is unsuitable for real time applications. On the other hand, light computation algorithms including Kalman filter and its variants cannot be directly deployed, since an explicit measurement equation and related noise statistics are not available. Therefore, it is a crucial task for real time indoor localization to develop a light computation fusion system run on resource-limited smartphones. In this paper, a novel data fusion framework based on extended Kalman filter (EKF) is firstly designed and implemented. In order to make EKF applicable, we develop a measurement model using kernel density estimation (KDE), which accurately characterizes the RSS-location relationship and adaptively measures the related noise statistics. For the PDR system, we accomplish another EKF for user heading estimation by fusing gyroscopes and accelerometers. In order to avoid singularity problems and reduce computation cost, we describe the device orientation by quaternions rather than Euler angles and direction cosine matrix (DCM). Experiments in a realistic indoor environment show that, the proposed EKF based fusion approach achieves significant accuracy improvement with respect to the individual approaches. Compared with a particle filter, the proposed EKF based fusion approach obtains comparable accuracy performance, while it reduces computation cost greatly.

Related Works
For indoor environments, though various localization approaches have been proposed, the optimal strategy is still an open issue. Recently, with the pervasive availabilities of WiFi infrastructures and low-cost inertial sensors built in smartphones, both WiFi localization and PDR systems have been considered as promising solutions for indoor localization. Consequently, due to their complementary strengths, fusing both systems has been paid increasing attention.
The earliest work fusing WiFi signals and inertial data is found in [18]. A particle filter is used to combine the pedestrian motion model, WiFi signals, and building maps. When the user's current step is detected by an accelerometer, the estimated walking direction and step length are fed into the particle filter as a motion model to predict the new positions of particles. Then, the weight of a particle is updated by computing a Gaussian function of the Euclidean distance between the particle and the WiFi localization result, which is achieved by K-nearest neighborhood algorithm [23]. For PDR system, heading estimation is derived from the integration of gyroscope data, which are collected by a sensing box attached to the belt of a pedestrian. To compensate the integration drift error of heading estimation, a Kalman filter is deployed by fusing angles of the trajectory delivered in the WiFi localization system. Similar work can be found in [19], where a sequential importance resampling particle filter is applied to fuse a low-cost accelerometer, compass, and WiFi signals. Vertical acceleration signals are deployed to detect steps, while the user heading is obtained from a compass. In contrast to the particle updating scheme in [18], the weight of a particle is updated by the inverse Euclidean distance between real time collected RSS and RSS signals in the radio map.
In [20], Rai et al., propose an augmented particle filter, which simultaneously estimates location, step length, and user heading. For the PDR system, the user heading is firstly estimated by a compass, and then updated by the user's trajectory in the measurement model of the augmented particle filter. For the WiFi localization system, the probability of observing real time RSS vector at the location of particles is computed as in [24], and then used to update the weight of particles. The key idea is that regular indoor layout information such as straight corridors may be exploited to correct the user's path and related orientations. However, for a spacious indoor environment, there is always not enough layout information available, thus significantly degrading the performance of the augmented particle filter. In order to make the system as simple as possible to the user, instead of dedicated specific procedures, an auto-calibration procedure is further adopted in [21] to reduce the magnetic measurement errors. Though significant performance improvement is obtained, the calibration procedure model is founded on the two-dimensional horizontal plane and is inapplicable for the more common three-dimensional case.
Recently, a light computation approach based on Kalman filter is proposed in [22] to fuse PDR and WiFi localization. In real experiments, the proposed approach achieved significant improvements over individual approaches, while it reduced computation cost greatly. This approach formulates PDR as a linear function and considers the user heading estimated per step as known input vector without noise being introduced. As a result, significant estimation bias happens when Kalman filter computes the a priori error covariance of the state vector, thus degrading the performance of Kalman filter. For the WiFi localization system, the user location is estimated by the weighted coordinates of APs. The weights are normalized inverse physical distances between device and APs, which are computed by the RSS signal propagation model. Due to complex indoor radio propagation environment, the signal propagation model may be so inaccurate that little location information is obtained to correct PDR, especially when the number of APs available is limited and sparsely distributed in a large scale region.
Due to the heavy computational burden, the particle filter based approach should be run on a server and is unsuitable for real time applications. We propose a light computation fusion approach based on EKF. For heading estimation in the PDR system, instead of using a compass, we only deploy a gyroscope, since severe magnetic perturbations render poor performance of the compass in most indoor environments [25,26]. The perturbations are caused by universally available electromagnetic devices and magnetization of intricate modern structures, which include steel walls and concrete floors. Therefore, the perturbations always show complex patterns in terms of changing magnitudes and directions at different locations [26], and are difficult to be modeled and calibrated. Since gyroscopes can only provide relative heading change estimation, we assume that the user's initial orientation is known as a priori in this paper. In fact, it can be obtained by various methods, such as Global Positioning System (GPS) tracking when pedestrians enter buildings [16], landmarks [27], and WiFi localization [28]. Furthermore, in order to guarantee accurate heading estimation from gyroscope data, a self-calibration procedure called "zero attitude updates" [29,30] is deployed to calibrate and compensate the gyroscope bias errors effectively. In our experiments, a zero attitude update, similar to the one implemented in [30], is performed just at the beginning of each experiment.
For device orientation representations of gyroscopes, there are mainly three kinds of descriptors: Euler angles [5], DCM [31], and quaternions [29]. The Euler angle based method is conceptually easy to understand, but it is computationally expensive and incurs singularity problems [32]. Both DCM and quaternion based methods may avoid the singularity problems. However, the quaternion based method requires much less computations than DCM, since it is easier to be normalized and needs only four variables updated during state propagating procedure. Therefore, we deploy quaternions for device orientation representations. Furthermore, to compensate the heading estimation drift caused by the tilt of hand-held smartphones, we develop an EKF to fuse the three dimensional gyroscope and accelerometer signals, which may infer tilt angles of smartphones.
For the WiFi localization system, due to various factors, such as obstacles, human body attenuations, and multi-path effects, it is impossible to construct an explicit equation for characterizing RSS-location relationship [24]. In [33], a stochastic model is developed to characterize the RSS-location relationship, with the posterior density approximated by a particle filter. In this paper, we deploy KDE [34] for density estimation to develop a RSS-location measurement model. The developed model may adaptively measure the noise statistics of WiFi localization, which cannot be achieved by previous fusion approaches. Besides, we further reduce the computation cost by restricting WiFi localization into the vicinity of the estimated location of the previous user step. Therefore, as shown in our experimental results, the proposed EKF based fusion approach obtains comparable accuracy in comparison to a particle filter, while it reduces computational complexity greatly. Figure 1 presents the architecture of the proposed EKF based fusion approach on smartphones. The proposed approach includes two EKFs. The first EKF is used to integrate gyroscope with accelerometer for heading estimation of PDR. The second EKF achieves the location estimation by fusing the WiFi localization system and PDR system. The measurement model of the second EKF is the developed RSS fingerprinting algorithm based on KDE. In addition, a spatial filtering process is introduced to restrict the WiFi localization into a sub-region. The state model of the second EKF is the PDR system, which comprises step detection, step length estimation, and quaternion based heading estimation modules.

Pedestrian Dead Reckoning
We deploy the smartphone inertial sensors, including an accelerometer and a gyroscope, for pedestrian dead reckoning. Theoretically, the pedestrian walking distance can be obtained by the double integration of acceleration signals. However, this approach suffers from unbounded error growth due to sensor noises. An effective solution is the PDR approach, which detects the walking step, estimates the step length and user heading. Thus, the position of the current step can be determined by the position of a previous step as follows: is the estimated coordinates of the th i step, i d is the estimated step length of the th i step, and i ψ is the estimated user heading. In this paper, we assume that the initial user's location and walking direction are known, which can be obtained by various methods, such as the user's input [11] and GPS tracking when a pedestrian enters a building [16].

Step Detection and Step Length Estimation
Steps can be detected based on periodic acceleration fluctuation patterns during walking. To avoid the negative effect of the accelerometer unit tilt, we deploy the norm of measured three dimensional acceleration signals for step detection, since the pattern of acceleration signal norm is insensitive to different device orientations. To reduce the acceleration signal noise, a smoothing function [22] is deployed to average the raw acceleration data. After smoothing the raw data, a peak detection algorithm is applied to identify a distinct step, as shown in Figure 2. Two thresholds are used to filter out false peaks caused by acceleration jitters with too small magnitude or too short time intervals, where T ∆ is the time interval between adjacent peaks, AccNorm is the norm of the measured three dimensional acceleration signal, g is the value of local gravity, Th T and Th A represent the time threshold and the magnitude threshold for peak detection, respectively. Practically, the time threshold is set around two-thirds of the walking period. The false peak with a small magnitude will be easily filtered out by the magnitude threshold Th A . For the false peak with a magnitude exceeding Th A , the motion law of the pedestrian walking makes the time interval between it and true peak within one step much shorter than the time threshold, and thus they can be easily distinguished between each other [11,12]. As shown in Figure 2, the marked false peak exceeding Th A will be firstly considered as a peak for a new step, if the time interval between it and the previous peak exceeds the time threshold.
Then, this will be corrected by the following true peak with bigger magnitude and shorter time interval than the time threshold. The step lengths are determined by various factors, including height, attitude, and walking frequency [11,35]. Since step length models for different pedestrians vary a lot, it is difficult to develop a generic model that is accurate for all pedestrians. For the same person, the step length mainly depends on the walking speed. Therefore, we apply the empirical model [36] to estimate the step length in Equation (1) as follows: where max i Acc and min i Acc represent the maximum and minimum of acceleration signal norms for step i , C and 1 C are the personalized coefficients for different pedestrians. The coefficients can be easily estimated by counting steps when pedestrians travel a known distance.

First EKF: Quaternion Based Heading Estimation
All inertial data, including three dimensional accelerations and angular velocities, are measured in a right-handed body frame B attached to the smartphone by axes B X , B Y and B Z . Define the front face of the screen as a plane FR . The B X axis is parallel to FR and points to the right; The B Y axis is parallel to FR and points forward; The B Z axis is perpendicular to FR and points outside of FR .
Thus, the orientation of a smartphone is determined when the axis orientation of the frame B is specified with respect to the absolute coordinate system called navigation frame NA . Note that, during walking, the user heading may be different from the smartphone forward when a smartphone is put in a pocket or a bag. This paper only considers the most common hand-held situation [17][18][19], in which the smartphone is held in a hand faced in front. The smartphone's forward axis is always the same as the user's walking direction at the horizontal level frame. Therefore, we assume that the smartphone forward and the user heading are aligned in the same direction. We apply rotation quaternion to describe the time model of smartphone orientations, since it can avoid the singularity problems and require the least computations [32]. First, we construct the relationship between a quaternion and the smartphone orientation. The transformation from frame NA to B can be represented as follows: is the 3 1 × column-vector at time t relative to B and NA . For the sake of simplicity, the argument t will be omitted. We deploy the rotation quaternion to describe the DCM, q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q where [ ] is the normalized orientation quaternion, 0 q is the scalar part and 1 2 3 , , q q q is the vector part of the quaternion. Therefore, the orientation of a smartphone with respect to navigation frame NA is described by three angles as follows: yaw q q q q q q q q pitch q q q q roll q q q q q q q q Secondly, according to the rigid body kinematic equations [32], the discrete-time model of orientation quaternions can be given as: where s T is the system interval, T Ω w is given as follows: The quaternion at time instants ( ) is determined, starting from initial conditions 0 q that may be calculated by initial known orientation of the smartphone. Finally, the EKF is applied to fuse gyroscopes with accelerometers for heading estimation. We deploy the rotation quaternion of a smartphone as the state vector, and thus the state transition vector equation is: where state transition matrix Equations (9) and (10) are derived from Equation (7) and can be considered as a first order approximation of the "noisy" transition matrix. The gyroscope measurement noise vector gyro k w is assumed small enough in the application area, thus the first order approximation always performs well. Therefore, the process noise covariance matrix k Q can be given as follows: The measurement model is constructed by observed acceleration vectors, ( ) where 1 k + a is the acceleration vector of the smartphone, g is the local gravity vector relative to NA , and 1 a k + v is the white Gaussian measurement noise of the accelerometer. Note that Equation (13) is true only when the human body is not affected by any acceleration. Assume that the covariance matrix of the measurement noise To filter out the disturbance of significant human motions, we construct adaptive measurement covariance matrix Because of the nonlinearity of Equation (13), the EKF approach linearizes the first part on the right side of Equation (13) by computing the Jacobian matrix: Based on the state model in Equation (9) and the linearized formula of the measurement model in Equation (16), the a posteriori estimation of the quaternion 1 k q + and the corresponding covariance matrix 1 k + q P may be obtained by the first EKF. The detailed procedures for the first EKF are given as follows: Firstly, compute the a priori state estimation and related error covariance matrix: where ˆk q is the a posteriori estimation of the quaternion at time instants s kT , and k q P is the related error covariance matrix. Then, compute the Kalman gain: ( ) Finally, compute the a posteriori state estimate and related error covariance matrix: After obtaining 1 k q + , the user heading at time instants ( ) is ultimately determined as in Equation (6). More detailed descriptions about the EKF process can be found in [37].

WiFi Localization Based on Kernel Density Estimation
In this section, we propose the KDE based WiFi localization for measurement update. Due to the lack of explicit measurement equation and related noise statistics, WiFi localization cannot be directly deployed for measurement update in EKF. Instead of an explicit measurement equation, we note that the density function may accurately characterize the RSS-location relationship. Assume that r is the real time RSS vector collected by the user, l is the user's coordinate vector, and the posterior density of the user's location is ( ) f l r . If we know ( ) f l r , Minimum Mean Squared Error (MMSE) [37] location estimation and its covariance matrix can be given as follows: ( ) However, the posterior density is unavailable in WiFi localization. To solve this problem, we propose KDE for approximating the posterior density due to its success in probability density distributions estimation. Given the radio map storing RSS training pairs ( ) RSS vector i r at the reference point i l , and a Gaussian kernel ℘, the posterior density estimation [34] is given as follows: ; , ˆ; ,  25) where N is the number of reference points at the target region, i r and i l are mean vector of the Gaussian kernels, and diagonal matrices Σ r and Σ l are the related covariance matrices, respectively.
Essentially, the estimated probability density is a Gaussian mixture, whose first two moments [34] are: Equations (26) and (27) can be used for measurement update and the corresponding covariance of the second EKF, respectively. Besides, to reduce the number of reference points involved in WiFi localization for measurement update, we deploy a spatial filtering process. The spatial filtering assumes that the pedestrian walking distance between adjacent steps cannot exceed a predefined distance threshold. Thus, we restrict the reference points involved in WiFi localization into a sub-region, whose centre is the localization result of the previous step and the radius is the distance threshold. Define that , which is much smaller than N. Then, the spatial filtering process may effectively reduce the computation cost for measurement update of the second EKF by reducing the number of reference points involved.

Second EKF: Fusing PDR and WiFi Localization
PDR and WiFi Localization systems both have their limitations and advantages. The PDR system can obtain relative displacement with high accuracy in a short period, while it suffers from cumulative drift errors during walking. The WiFi localization system can provide the absolute location estimation, while it incurs the inaccurate localization results when significant RSS fluctuations happen. Fusing both systems will exploit their complementary advantages. PDR enhances the accuracy of WiFi localization, while WiFi localization is useful for binding the cumulative PDR drift errors.
The most widely used fusion approach is a particle filter, which incurs substantial computation cost. It is unsuitable for real time indoor localization on resource-limited smartphones. Moreover, Kalman filter and its variants cannot be directly used since an explicit measurement equation and RSS noise statistics are unavailable. To make the proposed light computation EKF based approach applicable, Section 3.2 proposes a measurement model based on KDE. This section describes the detailed process of the proposed fusion approach. The complete summary of the second EKF is shown in Figure 3.
First, we give the formula of state model. Assume _ ψ i step is the yaw angle estimated at the th i step from Equation (6) in the navigation frame NA, and _axis ψ x is the yaw angle of a predefined positive x-axis, whose definition is shown in Figure 4 in our experiments. Define ψ i  as the anticlockwise rotation angle from the predefined positive x-axis to the user walking direction. Then, PDR model can be rewritten by substituting where _ ψ i step is obtained at the acceleration peak time of the th i step. Note that if the navigation frame NA is aligned with the predefined coordinate, the PDR model will be simplified and the same as Equation (1) is the quaternion estimated by the first EKF at the acceleration peak time of the th i step. Then, we rewrite Equation (29) as: , and can be obtained by substituting Equation (30) into the second part on the right side of Equation (29). Secondly, compute the a priori state estimation i − L and the a priori error covariance matrix i − P , Finally, the location at the th i step can be estimated by fusing state model in Equation (31) and measurement model in Equation (35). The Kalman gain can be given as follows: Then, the a posteriori location estimation at the th i step is given as follows: The corresponding a posteriori error covariance matrix is given as follows:

Experimental Setup
Experiments were carried out in a 43.5 m × 11.2 m indoor office area, part of the second floor of our department, as seen in Figure 4. The ground is laid with square floor tiles, whose sizes are 0.6 m × 0.6 m. We deploy a Huawei Mate smartphone running the Android 4.1 operation system as the experimental device. For the WiFi localization system, there are total 8 APs (indicated by blue squares) available and 50 reference points (indicated by red circles) deployed. The distance between neighbor reference points in the hall and corridor are 1.2 m and 1.34 m, which is the length and diagonal distance of two floor tiles, respectively. During offline phase, we collected 100 RSS training samples per reference point to build the radio map. During online phase, the user collected real time RSS vectors at about 2 Hz sampling rate. We define the reference point in the lower-left corner as the coordinate origin; the x-axis points to the right, being parallel to the corridor, and the y-axis points upward. The proposed fusion approach is compared with individual approaches of WiFi localization and PDR, the particle filter [19] using 1000 particles. To test the effectiveness of the proposed KDE based WiFi localization, we develop and test an improved particle filter (PF). Compared with the particle filter in [19], the only difference of the improved one is the particle weight update scheme, which is achieved by computing the Gaussian kernel function between the location of particles and WiFi localization results. As shown in Equations (26) and (27), the WiFi localization results are obtained by deploying KDE, while the kernel width of the Gaussian kernel function is adaptively adjusted by the related covariance. For the PDR system, we use the gyroscope module and accelerometer module built in the Huawei Mate smartphone to track the user. The gyroscope and accelerometer sensing rates are set to 100 Hz and 50 Hz, respectively. To make the gyroscope output more precise and robust, we do the necessary calibration process before carrying out experiments. Note that we only consider the common hand-held situation, and assume that the misalignment angle between the device forward and user heading is zero. The other situations, such as when the smartphone is put in a pocket or a bag, will be considered in our future works. As in much of the literature [11,16], we assume that the user's initial location and orientation is known as a priori. To label the ground truth, we place some tags on the ground and apply a camera to record the entire walking process. Then, we manually label the coordinates of each step carefully. The localization error is calculated as the Euclidean distance between the estimated coordinates per step and the labeled coordinates per step along the true path.

Performance Analysis
First, since the tracking performance is greatly affected by the heading estimation bias, we evaluate the heading estimation performance of the developed PDR system. Figure 5 shows the true path of the user. According to the different user heading, the whole path is divided into seven sub-paths. Figure 6 compares the heading estimation performance between approaches using gyroscope only (Gyro) and combining gyroscope with accelerometer (Gyro + Acc). One can clearly see that the estimated user headings of both approaches are close to the ground truth. Particularly, from path 1 to path 4, both approaches have approximate estimated user heading. However, from path 5 to path 7, the Gyro + Acc approach obtains better heading estimation performance than Gyro approach. The Gyro approach assumes the initial inclination angle of the hand-held smartphone is known and remains stable along the walking path. This assumption may be corrupted temporarily when drastic body swinging happens. In contrast, the EKF based Gyro + Acc approach may fuse the acceleration information well, which contains real time tilt angle information, and thus may decrease the negative effect caused by drastic body swinging.  Secondly, we compare the tracking performance between the proposed approach and the individual approaches of WiFi localization and PDR. Figure 7 shows the trajectories of the true path, PDR (Gyro), PDR (Gyro + Acc), WiFi localization and the proposed approach. PDR has comparable tracking accuracy with the proposed approach from path 1 to path 3, while it performs progressively worse with the tracking error accumulated. Particularly, from path 5 to path 7, PDR (Gyro + Acc) performs better than PDR (Gyro), since the former has a smaller heading estimation error than the latter, as can be seen in Figure 6. Though WiFi localization obtains inaccurate tracking results along the whole path, it also provides useful localization information, especially along path 4 and path 5, whose y-axis coordinates are restricted into a small region. Clearly, the proposed approach, whose estimated trajectories match the ground truth closest, performs best. This may be contributed to the effective corrections of the drift errors of PDR by fusing WiFi localization. Thirdly, we compare the localization accuracy between various approaches. As seen in Table 1, compared with PDR (Gyro), PDR (Gyro + Acc), WiFi localization and the particle filter, the proposed EKF reduces mean localization errors by 54.5% (0.85 m), 42.7% (0.53 m), 74.9% (2.12 m), and 12.3% (0.10 m), while it reduces standard deviations by 65.4% (0.70 m), 30.2% (0.16 m), 86.7% (2.42 m), and 7.5% (0.03 m), respectively. Compared with the improved particle filter, little performance degradation is achieved by the proposed EKF. The corresponding cumulative error distributions are shown in Figure 8. Clearly, the proposed EKF performs much better than the individual approaches, while it achieves comparable accuracy with that of the two particle filter based approaches. Particularly, the particle filter performs a little worse than both the improved particle filter and the proposed EKF, since its particle weight update scheme may incur the adverse effect caused by some RSS observations with severe fluctuations. In contrast, the improved particle filter and the proposed EKF may mitigate the adverse effect by giving a smaller weight to the noisy RSS observation, which renders a larger WiFi localization error covariance. The related error covariance may be adaptively estimated by deploying KDE during particle weight update or EKF filtering process.
Finally, we compare the calculation time of the location estimation per step between a particle filter and the proposed EKF, as shown in Figure 9. The calculation time is obtained by running the compared approaches in Matlab and averaging calculation time per step of ten traces along the true path. The calculation time required by the proposed EKF takes 0.185 s. It is mainly caused by two modules: first EKF for heading estimation takes 0.119 s; and second EKF for location estimation takes 0.064 s. The calculation time for step detection and step length estimation only takes 0.002 s. For a particle filter with 1000 particles, it takes 11.3 s and thus is unsuitable for real time applications. The proposed EKF based fusion approach greatly reduces calculation time in comparison to the particle filter in two ways. First, except for computing Jacobian matrix, EKF requires the same computation cost as that of a Kalman filter, while the particle filter needs to calculate and update the states of a great number of particles whenever implementing a new location estimation. Secondly, the computation cost for measurement update is reduced significantly by a spatial filtering process, which reduces the number of reference points involved in Equations (36) and (37). In summary, the proposed approach achieves comparable accuracy performance to that of a particle filter, while maintaining a low computation cost comparable to that of a Kalman filter. It is more suitable than the particle filter for real time indoor localization on resource-limited smartphones.  Figure 8. Accuracy comparisons between the proposed EKF based fusion approach, improved particle filter, particle filter, PDR with Gyro + Acc, PDR using gyroscope only and WiFi localization. Figure 9. Comparisons of the calculation time for location estimation per step between a particle filter and the proposed EKF based approach, whose two main modules are: first EKF for heading estimation; and second EKF for location estimation.

Conclusions and Future Work
The main contributions of this work are three-fold. First, we design a novel data fusion framework for combing PDR and WiFi localization by using an extended Kalman filter. The proposed fusion approach reduces mean localization errors by 42.7% and 74.9% as compared to using PDR and WiFi localization alone, respectively. Compared with a particle filter, the comparable accuracy is achieved, while the computation cost is reduced greatly.
Secondly, to adapt the unknown measurement equation and related noise statistics, we propose a RSS-location measurement model by using KDE. Unlike previous approaches setting measurement noise covariance manually, we adaptively and accurately estimate it by approximating the probability density using KDE. In addition, a spatial filtering process is combined to reduce the computation cost by restricting localization into a vicinity of the localization result of previous step.
Finally, we develop a quaternion based heading estimation method by using another EKF to fuse gyroscopes and accelerometers. Instead of using the most widely used Euler angles and DCM based orientation descriptors, we use the quaternion descriptor, since it can both avoid the singularity problems and require the least computations simultaneously.
In future works, we will further expand the proposed approach to the situation when the placement of a smartphone is unconstrained, such as in a pocket or a handbag. This situation has been paid little attention, and may present critical challenges for heading estimation in PDR systems. In addition, building maps and related landmarks will also be combined to correct the heading estimations and improve the localization accuracy.