Accurate and Robust Floor Positioning in Complex Indoor Environments

With the widespread development of location-based services, the demand for accurate indoor positioning is getting more and more urgent. Floor positioning, as a prerequisite for indoor positioning in multi-story buildings, is particularly important. Though lots of work has been done on floor positioning, the existing studies on floor positioning in complex multi-story buildings with large hollow areas through multiple floors still cannot meet the application requirements because of low accuracy and robustness. To obtain accurate and robust floor estimation in complex multi-story buildings, we propose a novel floor positioning method, which combines the Wi-Fi based floor positioning (BWFP), the barometric pressure-based floor positioning (BPFP) with HMM and the XGBoost based user motion detection. Extensive experiments show that using our proposed method can achieve 99.2% accuracy, which outperforms other state-of-the-art floor estimation methods.


Introduction
Recently, more and more huge multi-story buildings have mushroomed, such as gymnasiums, super malls, convention centers, etc. To promote security supervision levels and facilitate the movement of people around complex indoor environments, accurate indoor positioning is getting more and more urgent. When an earthquake or fire occurs various complex indoor environmental factors, e.g., smoke and rubble, can increase rescue difficulties dramatically [1]. In this emergency case, indoor positioning can help rescuers plan a safe and reasonable route [2][3][4]. Nowadays, smartphones are not only communication tools but also measuring instruments embedded with various sensors [5], which can be used as a reasonable positioning terminal. Though there are many studies on indoor positioning, as an important prerequisite for indoor positioning in multi-story buildings, accurate and robust floor positioning remains a big challenge, especially in the multi-story buildings with large complex hollow areas through multiple floors. In practical applications, floor positioning is useful and plays an important role in indoor localization, which not only can reduce the location search space, but also can improve the positioning accuracy.
Current floor positioning methods are mainly classified into Wi-Fi-based methods, pressure-based methods and hybrid methods. Wi-Fi-based methods stem from Wi-Fi signal propagation characteristics. Wi-Fi signals decay rapidly when passing through concrete floor slabs from other floors. On the contrary, the Wi-Fi signals attenuate gradually when propagating without going through concrete walls on the same floor [6]. Such a propagation attenuation pattern leads to different sets of APs received on 1.
We propose a BWFP augmentation method with BPFP using HMM. In areas where Wi-Fi signals are highly distinguishable, BWFP is applied and the high-confidence floor estimation result is used to provide a reference value for a barometer. In the hollow areas with low discrimination for Wi-Fi signal, BPFP is applied by the mapping between the barometric pressure and altitude. HMM is utilized to correct the occasional floor positioning errors caused by the BWFP or the BPFP method.

2.
We propose a motion detection method to identify user's floor switching behavior based on accelerometer and gyroscope readings. Once the floor switching motion is detected, the vertical coordinates are estimated. Under this floor switching periods, location-based services can still be provided in the intermediate areas between adjacent floors. 3.
We model the floor positioning into a supervised multi-classification problem and use the XGBoost [12] to make advantage of the received signal strengths for accurate floor positioning. Through combining multiple tree models, the XGBoost-based floor positioning method (i.e., BWFP) can obtain high-confidence floor positioning result in the closed areas. To speed up training of XGBoost, we introduce exponential preprocess for all Wi-Fi fingerprints. 4.
We evaluate our proposed algorithm in several different scenarios and the experimental results demonstrate that our proposed algorithm outperforms the Wi-Fi-only-based method, the pressureonly-based method and the comparative hybrid method with 99.2% average accuracy and better robustness. Furthermore, the probability of floor switching detection delay within 2 s exceeds 90%, which is a vital metric for the floor positioning method.
The rest of this paper is organized as follows: In Section 2, related works are introduced. The materials and methods are described in Section 3. The experimental results are shown in Section 4. Finally, the discussion and conclusions of this paper are presented in Section 5.

Related Works
Many studies on floor positioning has been conducted in the past decades, which can be broadly classified into Wi-Fi-based methods, barometric pressure-based methods and hybrid methods.

Wi-Fi-Based Methods
Wi-Fi based methods, which integrate collected Wi-Fi fingerprints for floor positioning, are the most popular methods. Alsehly et al. [13] designed a group variance algorithm. It groups the variances of RSSI values in each floor. During the prediction phase, it compares the variance of newly-collected Wi-Fi signals with each group to find the best matching floor level. Deng et al. [14] attempted to use a k-means clustering algorithm for floor number identification. Campos et al. [15] employ the majority voting committees of back-propagation artificial neural networks (ANNs) to identify floors. It first clusters the collected RSS levels by unsupervised learning, and subsequently utilizes ANNs to identify the cluster of the newly-collected RSS values. FloorLoc-SL [16] introduced a self-learning scheme to create fingerprints for each floor. It proposes the use of an activity classification module and a floor counting module to detect the traces of users. When the received characteristic Wi-Fi signal cannot be found in the fingerprint database, the current floor will be given by the floor counting module and the new characteristic Wi-Fi signal will be added into the fingerprint database with the floor estimation. Sun et al. [17] propose a multi-floor localization framework and apply Fisher's linear discriminant method to maximize the margin discrepancy between neighboring floors in fingerprint space. Stair walking and elevator taking event recognition trigger the floor estimation. F-Loc [11] collects and clusters the Wi-Fi fingerprints near the entrances of elevators and identifies the floor by detecting the taking elevator action using accelerometer readings. Li et al. [18] proposed a wireless received signal strength-profile-based floor-detection approach to enhance RSS-based floor detection performance. By calculating the average dilution of precision of successive Wi-Fi signals from different APs on each floor when users walk, the floor with the smallest positional DOP value is regarded as the floor estimation. Kim et al. [19] extend the single-input and multi-output deep neural network to enable hybrid building/floor classification and location coordinate regression with Wi-Fi fingerprints. This method exploits the hierarchical and different nature of the estimation of building/floor and floor-level location coordinates. Though many works have been conducted on the floor positioning with Wi-Fi signals, the existing Wi-Fi-based floor positioning methods still cannot accurately discriminate adjacent floors in the multi-story buildings which contain complex and large hollow areas.

Barometric Pressure-Based Methods
Without the large attenuation generated by concrete floor slabs in the larger hollow areas, smartphones situated in adjacent floors are prone to measure similar Wi-Fi fingerprints in multi-story buildings, which leads to wrong floor estimations by Wi-Fi-based methods. Some studies have proposed barometric altimetry for floor determination. However, barometric pressure is easily affected by weather conditions and ambient air flows. Muralidharan et al. [20] observed that although the absolute barometric pressure on each floor varies dramatically with time, the pressure difference across different floor pairs remains stable. They obtained the relative floor level instead of the actual floor by detecting the number of floor switches using pressure differences. In order to estimate an absolute floor number, Liu et al. [21] deployed a barometer in the building as reference. By calculating the pressure measurement difference between reference barometer and a user's mobile phone, they obtain the actual floor the user is on, but this method depends on deploying a reference barometer in the environment, which has poor scalability in practice. Ye et al. [22] established a mapping between barometric pressure values and the corresponding floor levels in a crowdsourcing fashion. The mapping is calibrated by encounters between different users. Li et al. [23] obtained the initial barometric pressure by detecting Wi-Fi fingerprints near the entrance of the target building. The limitation of this method is that the Wi-Fi fingerprints near the building entrance must be known. Falcon et al. [24] detected the entrance Sensors 2020, 20, 2698 4 of 20 of the target building by training a neural network using GPS signals. The effectiveness of this method depends heavily on the accuracy and timeliness of indoor and outdoor recognition. Banerjee et al. [25] developed a positioning solution combining Wi-Fi-based localization and barometric altimetry using an unsupervised probabilistic learning method. In summary, due to the fact the barometric pressure is easily affected by weather conditions and ambient air flows, accurate and real-time calibration of a reference pressure is a big challenge for pressure-based methods.

Hybrid Methods
In complex multi-story buildings, adoption of only a single Wi-Fi-based method or barometric pressure-based method cannot produce accurate and robust floor positioning. Several studies have designed hybrid methods to improve floor positioning performance. BarFi [10] exploits the combination of Wi-Fi RSS and barometric pressure for accurate floor positioning. It trains the RSS fingerprint floor map with the aid of a barometer in a crowdsourcing fashion, which is computationally complex. HYFI [9] combines the wireless access point distribution by Bayesian classification and barometric pressure information to determine the floor level. They identify the floor level by discriminating the slow and quick pressure changes. However, the accuracy of using the likelihood-based method in HYFI [9] is low because it only uses the keying-like AP information instead of using the received signal strengths. Li et al. [18] integrated the data from an inertial sensor, magnetometer, and barometer with RSS data through an extended Kalman filter to gain more reliable and smoother floor detection. Reference [26] describes a new barometric altimetry error model, which includes white Gaussian noise and a first order random walk. Then the signals are updated by Wi-Fi RSS measurements using a Kalman filter. Nevertheless, their likelihood to maximum a posteriori (MAP) conversion is loose.
Different from the abovementioned floor positioning methods, our proposed floor positioning algorithm introduces the concept of a confidence parameter into the Wi-Fi-based floor positioning method. The floor positioning result with high confidence obtained by the Wi-Fi-based floor positioning method is used to calibrate the reference barometric pressure in time. To correct occasional floor positioning errors, the HMM is also adopted. Furthermore, we propose an XGBoost-based motion detection method to identify floor switching behavior in real time, which not only can improve floor positioning accuracy, but also can give continuous vertical coordinates once the floor switching motion is detected in the intermediate areas between adjacent floors.

Materials and Method
In this section, we outline the overall system and divide it into three parts in detail: BWFP Module, BWFP Augmentation Module and Motion Detection Module.

System Overview
In existing multi-story buildings, such as shopping malls, large office buildings, etc., the geographical environment is often complex, which may contain the intersections of hollow and non-hollow areas, and users may cross multiple floors by various transportation modes (taking elevators, escalators, or going up/down stairs.). This poses a challenge to floor positioning and makes it difficult to rely on a single floor positioning approach. For concision, we define the non-hollow area as a closed area, which means that the adjacent floors are completely separated by concrete slabs.
Benefiting from the various sensors embedded in common smartphones, our system takes both the Wi-Fi [27] fingerprints received by mobile phones and the readings of accelerometers, gyroscopes [28] and barometers [29] as input. Through the combination and improvement of various methods, the floor can be located robustly and accurately.
As shown in Figure 1, our Motion Detection Module is designed to accurately detect users' floor switching motions, including but not limited to going upstairs, going downstairs, taking an elevator up, and taking an elevator down. When no floor transition motion is detected, BWFP is performed to achieve accurate floor positioning in closed areas. However, in hollow areas, it is observed that the Wi-Fi fingerprints between adjacent floors are very similar and it is difficult to accurately localize floors because there is no concrete slab barrier and the wireless signal propagation attenuation is very small. To achieve accurate floor positioning both in hollow and closed areas, we develop Bthe WFP Augmentation Module, which combines BPFP and HMM as a compensation method. BPFP is applied by the mapping between the barometric pressure and altitude. HMM is utilized to correct the occasional floor positioning errors caused by the BWFP or the BPFP method. Once the floor transition event is detected, the vertical coordinates in the intermediate areas between adjacent floors is estimated by the barometric pressure difference between current time and the last time when the motion detection result was changed from the walking motion to the floor switching motion.
Sensors 2020, 20, x FOR PEER REVIEW 5 of 20 achieve accurate floor positioning in closed areas. However, in hollow areas, it is observed that the Wi-Fi fingerprints between adjacent floors are very similar and it is difficult to accurately localize floors because there is no concrete slab barrier and the wireless signal propagation attenuation is very small. To achieve accurate floor positioning both in hollow and closed areas, we develop Bthe WFP Augmentation Module, which combines BPFP and HMM as a compensation method. BPFP is applied by the mapping between the barometric pressure and altitude. HMM is utilized to correct the occasional floor positioning errors caused by the BWFP or the BPFP method. Once the floor transition event is detected, the vertical coordinates in the intermediate areas between adjacent floors is estimated by the barometric pressure difference between current time and the last time when the motion detection result was changed from the walking motion to the floor switching motion.    Figure 1. System overview design.
In order to accurately localize floors in all complex indoor areas, including hollow, closed areas and intermediate areas between adjacent floors, we must ensure that the right remedy is applied, i.e., the BWFP Module is applied in closed areas, and BPFP and HMM are combined to strengthen floor positioning in hollow areas. However, it is difficult to decide when and which method to apply, because the system does not know whether the user is in a hollow or closed area at any given time. We propose a confidence threshold judgment method to handle this problem. Our system uses the BWFP results with high confidence to opportunistically calibrate barometric pressure. Detailed design will be described in Sections 3.3. and 3.4 describes how to judge user's floor switching behavior.

BWFP Module
Due to the barrier of concrete slabs, the access point set and received signal strength of the same AP are remarkably different between adjacent floors in closed areas. By making full use of these characteristics, we can achieve accurate floor positioning in such areas. We model the floor positioning as a supervised multi-classification problem. Each floor is given a different label. The floor with the largest prediction probability is taken as the final floor estimation.
The BWFP method contains two phases: offline training phase and online predicting phase. In the offline training phase, the AP fingerprints collected along all paths on the same floor are given the same label. The number of fingerprints in each floor should be balanced.
Let L represents the p consecutive floors of a multi-story building and represents the floor:  In order to accurately localize floors in all complex indoor areas, including hollow, closed areas and intermediate areas between adjacent floors, we must ensure that the right remedy is applied, i.e., the BWFP Module is applied in closed areas, and BPFP and HMM are combined to strengthen floor positioning in hollow areas. However, it is difficult to decide when and which method to apply, because the system does not know whether the user is in a hollow or closed area at any given time. We propose a confidence threshold judgment method to handle this problem. Our system uses the BWFP results with high confidence to opportunistically calibrate barometric pressure. Detailed design will be described in Sections 3.3 and 3.4 describes how to judge user's floor switching behavior.

BWFP Module
Due to the barrier of concrete slabs, the access point set and received signal strength of the same AP are remarkably different between adjacent floors in closed areas. By making full use of these characteristics, we can achieve accurate floor positioning in such areas. We model the floor positioning as a supervised multi-classification problem. Each floor is given a different label. The floor with the largest prediction probability is taken as the final floor estimation.
The BWFP method contains two phases: offline training phase and online predicting phase. In the offline training phase, the AP fingerprints collected along all paths on the same floor are given the same label. The number of fingerprints in each floor should be balanced.
Let L represents the p consecutive floors of a multi-story building and l i represents the i th floor: and let O be a set of D observations as given by: Considering the fact that the number of scanned APs in different locations on a floor is different, the dimension of observation vector O d is dynamic. For convenience, we use RSS r to indicate the received signal strength from the r th AP.
We introduce XGBoost [12] into the BWFP. The XGBoost classifier combines multiple tree models to build a strong multi-classifier. Before applying the XGBoost classifier, we embed original AP fingerprints in the Euclidean space. In this way, we can define the distances and similarities over features in the Euclidean space. The concrete operation is to run the exponential operation on every RSS j in O d , as Equation (1) shows: where λ is the index coefficient. The hyperparameter λ is determined by experiments (in this paper, it is set to 1.035). Since the received signal strengths are negative, the exponential operation maps original signal strengths between 0 and 1, which can speed up the training process. SV is the signal vector after the embedding operation. Next, we attach the ground truth floor as a label to the original data. The set of SFV O d = SV O d ; label = l O d represent training and testing samples. Through training, K trees in XGBoost are obtained and the cumulative value of K trees is the estimated floor positioning result as Equation (2) shows: where F are all possible trees, f k SV O d is the weight of sample SV O d on the leaves of the k th tree which represents the scores of different floors,ŷ i is the final estimated floor positioning result obtained by accumulating the f k SV O d of all K trees. Our loss function is defined as Equation (3) shows and the second element in Equation (3) is the regularization term as Equation (4) shows, where T is the number of leaf nodes, ω is the output score of each leaf node, γ and η are the weight ratios representing preference for two terms. In Equation (3), y i represents the ground truth floor,ŷ i . represents the output of classifier and f represents the MSE (Mean Squared Error) between y i andŷ i . n is the number of training samples and K is the number of trees in the model: Our goal is to balance between MSE and regularization term so as to obtain the optimal model based on a large number of fingerprint training data. Using regularization term can avoid over-fitting by controlling the complexity of model. During the online floor positioning phase, the exponential operation is first applied on the real-timely collected RSSI fingerprints. Then preprocessed RSSI fingerprint is inputted into the pre-trained model to identify the most likely floor on which a user stays.
We introduce the confidence parameter to represent the accuracy of the BWFP method, which is the floor prediction probability using BWFP. Only high confidence floor positioning results are used to calibrate the barometric pressure (which will be detailed in the next section). For example, if the BWFP Module is employed in a four-story building, the four-floor estimation probability is (0.23, 0.28, 0.27, 0.22). We can see that although the prediction probability of F2 is the highest, it is better to discard the floor estimation result and resort to other methods instead. Therefore, we define the maximum probability of floor estimation using BWFP as the confidence. The floor positioning probability can be directly obtained by setting the 'objective' to 'multi:softprob' in XGBoost. Only the floor estimation with high confidence is accepted. Those floor prediction results with low confidence is discarded. We will detail it in the Section 3.3.
To evaluate the performance of BWFP, we conducted several experiments in four different buildings and their structure is described in Table 1. Building 1 contains large hollow areas from the first floor to the third floor. Building 2 and Building 3 have small hollow interior between adjacent floors. Building 4 is almost entirely hollow from the first floor to the fourth floor. Three Wi-Fi-enabled smartphones (Xiaomi 5s/Huawei Mate20/Huawei Mate9) are used to collect floor fingerprints. We used an application that queried the Android Application Programming Interface (API) for the Wi-Fi fingerprints (0.5-Hz sampling rate for all smartphones). We uniformly collected the AP fingerprints along all paths of each floor in the four buildings. We And the test samples of Building 2, Building 3 and Building 4 were collected five days after the training samples were collected. We totally collected 10849 test samples. The accuracy of floor positioning is defined as the number of correctly identified floor over the total number of test samples. Table 2 compares the accuracy of our proposed classification-based BWFP using XGBoost and Bayesian used in HYFI [9] in these four experimental buildings. From this Table, we can find that using the XGBoost based method can obtain better floor positioning accuracy than the likelihood-based method. In order to verify whether our proposed BWFP model works well in the hollow areas, we established a comparative experiment between hollow and closed areas. We used the pre-trained BWFP model to localize floors in the hollow and closed areas of Building 2, respectively. As can be seen from Table 3, the accuracy in the closed areas reaches nearly 100%, while the average accuracy in the hollow areas is about 95.3%. Besides, the accuracy in F3 is only 89.3%, which is far from meeting the requirements of practical applications. This shows that even though we use the powerful classifier XGBoost, the positioning accuracy of BWFP in the hollow areas is still unsatisfactory because of indistinguishable Wi-Fi fingerprints between adjacent floors.

BWFP Augmentation Module
The previous section shows that even though we use the powerful XGBoost classifier, the positioning accuracy of BWFP in the hollow areas is still unsatisfactory. In the regions with hollow areas, the Wi-Fi signals are similar and prone to confuse between adjacent floors, so it is difficult to accurately identify floor only by using BWFP. In addition, classification-based BWFP cannot accurately localize floor in the intermediate areas between adjacent floors, which is critical for complete floor positioning. Therefore, we combine BPFP and HMM together as complement.
The BPFP utilizes the physical relationship [8] between altitude and barometric pressure, as Equation (5) shows, to obtain altitude change for floor positioning: where T 0 and P 0 are the temperature and pressure at sea level, respectively. T 0 is 288.15 (K) and P 0 is 1013.25 (hPa) in the standard atmosphere. Lapse is lapse rate of temperature, R is the universal gas constant and g is the gravitational constant. H 0 is set to 0 at sea level, and P s represents real-time barometer measurements. However, Equation (5) is only applicable to the calculation under the standard atmosphere condition. For non-standard atmosphere conditions, the obtained altitude using Equation (5) need to be furthermore calibrated as described in [7]. For convenience, we use H c to represent the calibrated altitude: where parameter ξ h represents the bias of altitude caused by different air-data conditions which is opportunistically calibrated with high confidence BWFP result. After calculating the calibrated barometric altitude and assuming that the sea level is an approximation of geoid level, we can obtain the altitude with the barometer measurements and vice versa. The BPFP can not only compensate for the unreliable positioning of the BWFP in the hollow areas, but also estimate vertical coordinates in the intermediate area between adjacent floors during floor transitions. However, barometric pressure is susceptible to environmental factors, such as temperature and humidity change. In modern large-scale buildings, we find that the barometric pressure may be different between areas with a front view towards the sun and a rear view away from the sun. Air conditioning also may affect barometer measurements. In brief, barometer measurements cannot be directly used to identify floor levels without calibration.
Therefore, the mapping between floor levels and the corresponding barometric pressures must be updated in real time to ensure that the pressure maintained by the system is of confidence and accurate for BPFP. Assuming that each height between adjacent floors is previously known, we only need to maintain a "reference pressure" automatically for a multi-story building during the whole positioning period. We define "reference pressure" as the real-time calibrated pressure of the "reference floor", which can be any floor within the building (e.g., the first floor in this paper). In the area where the Wi-Fi signals can be distinguished with high confidence, the "reference pressure" is calibrated by the high-reliable result from BWFP. While in the hollow areas, the floor is predicted by using BPFP with "reference pressure".
As mentioned in Section 3.2, the BWFP Module simultaneously gives the floor positioning confidence corresponding to the floor positioning estimation. We utilize a confidence threshold judgment method to select appropriate floor positioning result of BWFP for BPFP calibration. As a hyperparameter, the floor positioning confidence threshold is selected based on experiments. The higher the threshold, the higher the positioning accuracy requirement for BWFP. By filtering confidence using preset threshold, the right remedy is applied. The relationship between the threshold and the number of BPFP triggers will be discussed in detail in Section 4.1. More specifically, the method includes the following two steps: 1.
"Reference pressure" calibration: when the confidence of BWFP exceeds the preset threshold, update the "reference pressure" algorithm as Figure 2 shows. Parameter p c represents the current barometer measurements, and f c represents the floor estimation result obtained by BWFP. We use an array of heights [] to record each height between adjacent floors within a multi-story building.
Variable ∆h is the height difference between the current floor and the reference floor (the first floor as the reference floor in this paper), which can be estimated based on the parameter f c and heights []. The ref_pre is the calibrated pressure of the reference floor and reference_height is the estimated height of the reference floor.

2.
Floor prediction: the "reference pressure" is calculated to predict the floor level. The inference process is shown in Figure 3.
Sensors 2020, 20, x FOR PEER REVIEW 9 of 20 different between areas with a front view towards the sun and a rear view away from the sun. Air conditioning also may affect barometer measurements. In brief, barometer measurements cannot be directly used to identify floor levels without calibration. Therefore, the mapping between floor levels and the corresponding barometric pressures must be updated in real time to ensure that the pressure maintained by the system is of confidence and accurate for BPFP. Assuming that each height between adjacent floors is previously known, we only need to maintain a "reference pressure" automatically for a multi-story building during the whole positioning period. We define "reference pressure" as the real-time calibrated pressure of the "reference floor", which can be any floor within the building (e.g., the first floor in this paper). In the area where the Wi-Fi signals can be distinguished with high confidence, the "reference pressure" is calibrated by the high-reliable result from BWFP. While in the hollow areas, the floor is predicted by using BPFP with "reference pressure".
As mentioned in Section 3.2, the BWFP Module simultaneously gives the floor positioning confidence corresponding to the floor positioning estimation. We utilize a confidence threshold judgment method to select appropriate floor positioning result of BWFP for BPFP calibration. As a hyperparameter, the floor positioning confidence threshold is selected based on experiments. The higher the threshold, the higher the positioning accuracy requirement for BWFP. By filtering confidence using preset threshold, the right remedy is applied. The relationship between the threshold and the number of BPFP triggers will be discussed in detail in Section 4.1. More specifically, the method includes the following two steps: 1. "Reference pressure" calibration: when the confidence of BWFP exceeds the preset threshold, update the "reference pressure" algorithm as Figure 2 shows. Parameter represents the current barometer measurements, and represents the floor estimation result obtained by BWFP. We use an array of heights [] to record each height between adjacent floors within a multistory building. Variable ∆h is the height difference between the current floor and the reference floor (the first floor as the reference floor in this paper), which can be estimated based on the parameter and heights []. The ref_pre is the calibrated pressure of the reference floor and reference_height is the estimated height of the reference floor.  2. Floor prediction: the "reference pressure" is calculated to predict the floor level. The inference process is shown in Figure 3. 2. Floor prediction: the "reference pressure" is calculated to predict the floor level. The inference process is shown in Figure 3.    Considering that the floor level estimated by the abovementioned floor prediction method may not be exactly an integer, and a user may stay in the intermediate areas between two adjacent floors, we design a threshold-based floor detection scheme, as Figure 4 shows. Considering that the floor level estimated by the abovementioned floor prediction method may not be exactly an integer, and a user may stay in the intermediate areas between two adjacent floors, we design a threshold-based floor detection scheme, as Figure 4 shows. If − ≤ ℎ ≤ , the user is judged to stay on the floor. Otherwise, once the floor switching motion is detected, which will be described in the next section, the user is judged to be situated in the intermediate area between adjacent floors and the vertical coordinates are then estimated using Equation (7). We define: where is the height calculated by the BPFP method, and 1 is the real height of the 1 floor level.
Considering that the instability of Wi-Fi signals and the sudden transition between the hollow and closed areas, the occasional floor estimation error may occur. In order to reduce the jump problem, we intuitively leverage the Hidden Markov Model (HMM) [30] to correct the final floor prediction. Based on the Markov hypothesis, HMM has the temporal characteristics of recording historical information. We define our HMM model as Equation (8) shows: where A is the transition probability, which is the probability of moving from one floor to another. It is calculated from the statistical analysis of user behavior training datasets. B is the emission probability and is obtained from the prediction confusion matrix. Parameter π is the initial state probability vector, which is obtained by probabilistic statistics from the user behavior training dataset. We regard the floor estimation obtained by BWFP or BPFP as the observation and the groundtruth floor as the hidden state in the Markov chain. We utilize the uncertain floor estimation obtained by BWFP or BPFP to speculate the floor which the user most likely stays on. It is equivalent to the decoding problem in HMM. Given the model and floor observation sequence, the HMM reveals the hidden (real) floor level using Viterbi method [31]. We abbreviate real floor as rf, prediction floor as pf. The floor estimation is modeled as maximum optimization problem as Equation (9) shows.
3 , the user is judged to stay on the F i+1 floor. Otherwise, once the floor switching motion is detected, which will be described in the next section, the user is judged to be situated in the intermediate area between adjacent floors and the vertical coordinates are then estimated using Equation (7).
We define: where h BPFP . is the height calculated by the BPFP method, and h Fi+1 is the real height of the F i+1 floor level.
Considering that the instability of Wi-Fi signals and the sudden transition between the hollow and closed areas, the occasional floor estimation error may occur. In order to reduce the jump problem, we intuitively leverage the Hidden Markov Model (HMM) [30] to correct the final floor prediction. Based on the Markov hypothesis, HMM has the temporal characteristics of recording historical information. We define our HMM model as Equation (8) shows: where A is the transition probability, which is the probability of moving from one floor to another. It is calculated from the statistical analysis of user behavior training datasets. B is the emission probability and is obtained from the prediction confusion matrix. Parameter π is the initial state probability vector, which is obtained by probabilistic statistics from the user behavior training dataset. We regard the floor estimation obtained by BWFP or BPFP as the observation and the ground-truth floor as the hidden state in the Markov chain. We utilize the uncertain floor estimation obtained by BWFP or BPFP to speculate the floor which the user most likely stays on. It is equivalent to the decoding problem in HMM. Given the model and floor observation sequence, the HMM reveals the hidden (real) floor level using Viterbi method [31]. We abbreviate real floor as rf, prediction floor as pf. The floor estimation is modeled as maximum optimization problem as Equation (9) shows.
(r f 1 , r f 2 , . . . , r f N ) = argmax P(r f 1 , r f 2 , . . . , r f N p f 1 , p f 2 , . . . , p f N ) (9) According to the Markov hypothesis, Equation (9) is equivalent to: To make a conclusion, we propose a BWFP augmentation with BPFP and HMM. The augmentation mainly includes two parts: firstly, the BPFP is used to strengthen the hollow areas and the intermediate areas between adjacent floors where the BWFP cannot accurately provide floor positioning result. In this case, only "reference pressure" needs to be maintained. On the other hand, HMM is used to correct the occasional errors of floor positioning. The overall performance is evaluated in Section 4.

Motion Detection Module
Most existing floor positioning methods can only estimate floor level, which cannot provide services while users are moving in the intermediate area between adjacent floors. As a critical judgment condition, as Figure 1 shows, we first detect users' motion using inertial sensor measurements. Once the floor transition motion is detected, the vertical coordinate of user is continuously estimated. Otherwise, the floor is estimated by the BWFP Module or the BPFP Augmentation Module.
When a user moves between different floors (going upstairs/downstairs, taking elevator up/down), the changing patterns of barometric pressure, acceleration and angular velocity are different from those when user walks along the same floor. This provides inspiration for us to accurately detect floor switching motion.
However, due to the pressure drift with environment factors, it is very unreliable to calculate the height change directly using barometer measurements as described in [32]. Therefore, we propose to detect users' motion using accelerometer and gyroscope readings. We regard motion detection as a binary classification problem, which includes floor switching motion and non-floor switching motion. Floor switching motions include but not limited to going upstairs/downstairs, taking elevator up/down. Once the floor switching motion is detected, then we calculate the barometric pressure difference between current time and the last time when the motion detection result was changed from the non-floor switching motion to the floor switching motion. Combined with Equation (6) in the previous section, the user's vertical coordinates can be calculated.
Theoretically, acceleration can characterize a sudden change of user motion, such as an overweight or underweight state during floor switching behavior. The gyroscope can detect the turning motion between the floors when the user goes upstairs or downstairs. In order to verify the feasibility of this idea, we collected the measurements of accelerometer and gyroscope during walking, going upstairs, going downstairs, taking elevator up, and taking elevator down. The experimental results are shown in the Figure 5. Note that non-floor switching motion measurements are collected on the same floor and we stretch the data for comparison. As can be seen from Figure 5a,b different motions produce different acceleration change modes, such as a sharp drop and increase while taking the elevator up or down. And the acceleration also demonstrates a large degree of oscillation while going upstairs or downstairs compared to walking on the same horizontal floor. As shown in Figure 5c,d the gyro data are slightly different under different motion modes, and we expect the classifier to judge the user's motion pattern by distinguishing the change pattern of acceleration and gyro.
increase while taking the elevator up or down. And the acceleration also demonstrates a large degree of oscillation while going upstairs or downstairs compared to walking on the same horizontal floor. As shown in Figure 5c,d the gyro data are slightly different under different motion modes, and we expect the classifier to judge the user's motion pattern by distinguishing the change pattern of acceleration and gyro.  Considering that the device attitude fluctuation with different holding modes and user walk produces various noise, we perform the coordinate transformation from the carrier coordinate system (b-system) to the navigation coordinate system (n-system) for all sensor data to obtain uniform sensor features, which is free of different holding modes and user walk. The coordinate system transformation from the carrier coordinate system to the navigation coordinate system [33] is shown as follows: where is the angular velocity obtained by the gyro measurements .Δ is the angle at which the carrier rotates from time m-1 to m. Motion detection is divided into offline training phase and online motion detection phase. In the offline training phase, to improve floor transition detection accuracy and reduce the detection delay, a sliding window with 50% data overlap is used to collect 2.56 s of accelerometer and gyro measurements (called a data frame). Then all of training data frames are labelled according to the corresponding user motion. Data frames encapsulated based on different sensor data are carefully observed from four different levels of granularity, i.e., statistical features, time domain features, peak and segment features and frequency domain features. They are combined into the final frame feature vector.
More specifically, we extract a total of 46 features based on frame data as Table 4 shows. "vertical" represents Z-axis measurements and "horizontal" represents the modulus of X-axis and Y- Considering that the device attitude fluctuation with different holding modes and user walk produces various noise, we perform the coordinate transformation from the carrier coordinate system (b-system) to the navigation coordinate system (n-system) for all sensor data to obtain uniform sensor features, which is free of different holding modes and user walk. The coordinate system transformation from the carrier coordinate system to the navigation coordinate system [33] is shown as follows: where ω b ib is the angular velocity obtained by the gyro measurements. ∆θ m is the angle at which the carrier rotates from time m-1 to m. Motion detection is divided into offline training phase and online motion detection phase. In the offline training phase, to improve floor transition detection accuracy and reduce the detection delay, a sliding window with 50% data overlap is used to collect 2.56 s of accelerometer and gyro measurements (called a data frame). Then all of training data frames are labelled according to the corresponding user motion. Data frames encapsulated based on different sensor data are carefully observed from four different levels of granularity, i.e., statistical features, time domain features, peak and segment features and frequency domain features. They are combined into the final frame feature vector.
More specifically, we extract a total of 46 features based on frame data as Table 4 shows. "vertical" represents Z-axis measurements and "horizontal" represents the modulus of X-axis and Y-axis measurements. In this module, we also employ the XGBoost method to fit the collected training data and extract the features from the real-time readings for motion detection. Table 4. Motion detection features selected for the XGBoost.

Gyro
Modulus Mean, std, var, median, min, max, range, iqr, kurtosis, skewness, rms, integral, double integral, correlation, FFT Note: more detailed description of the features seen in the Appendix A.
As a vital decision factor, the accuracy of motion detection should be ensured. Similar to Section 3.2, the HMM is also used to correct the occasional motion detection errors. We collected training data with 2774 floor switching data (including going upstairs and downstairs, taking elevator up and down) and 3761 walking data on the horizontal floors using three different mobile phones (Huawei Honor V1, Huawei Mate9, Xiaomi MIX2).
The sensor sampling frequency is set to 100 Hz, i.e., for every 10 ms, an acceleration sample and a gyroscope sample of mobile phones are collected. Next, a data sample (256 pieces of data) was constructed every 2.56 s to construct a feature vector.
From the simulation experiment, the importance of each feature for XGBoost classifier was obtained. The red mark features in Table 4 are the most important features. It can be seen that the FFT amplitude of acceleration and angular velocity can differentiate stride span and frequency when users walk on the same floor or a vertical movement happens.
On the real-time testing stage, two testers walk on the horizontal floors and take floor switching activities for 5 min in Building 2, respectively. The motion detection accuracy is shown in Figure 6.

Modulus
Mean, std, var, median, min, max, range, iqr, kurtosis, skewness, rms, integral, double integral, correlation, FFT Note: more detailed description of the features seen in the Appendix A.
As a vital decision factor, the accuracy of motion detection should be ensured. Similar to Section 3.2, the HMM is also used to correct the occasional motion detection errors. We collected training data with 2774 floor switching data (including going upstairs and downstairs, taking elevator up and down) and 3761 walking data on the horizontal floors using three different mobile phones (Huawei Honor V1, Huawei Mate9, Xiaomi MIX2).
The sensor sampling frequency is set to 100 Hz, i.e., for every 10 ms, an acceleration sample and a gyroscope sample of mobile phones are collected. Next, a data sample (256 pieces of data) was constructed every 2.56 s to construct a feature vector.
From the simulation experiment, the importance of each feature for XGBoost classifier was obtained. The red mark features in Table 4 are the most important features. It can be seen that the FFT amplitude of acceleration and angular velocity can differentiate stride span and frequency when users walk on the same floor or a vertical movement happens.
On the real-time testing stage, two testers walk on the horizontal floors and take floor switching activities for 5 min in Building 2, respectively. The motion detection accuracy is shown in Figure 6.

Augmentation BWFP with BPFP Using HMM
The above experiments confirm that purely using the BWFP cannot meet the application requirements both in the hollow areas and in the closed areas. And purely pressure-based method cannot identify floor level directly without calibration. Therefore, we combine BWFP with BPFP, and further use HMM to filter out occasional floor estimation errors. In this part, the effectiveness of our proposed method and each component is tested.
As shown in the Figure 7, the total test results in Building 1 and Building 2 confirm that the proposed method can improve the accuracy of floor positioning compared with only using a single

Augmentation BWFP with BPFP Using HMM
The above experiments confirm that purely using the BWFP cannot meet the application requirements both in the hollow areas and in the closed areas. And purely pressure-based method cannot identify floor level directly without calibration. Therefore, we combine BWFP with BPFP, and further use HMM to filter out occasional floor estimation errors. In this part, the effectiveness of our proposed method and each component is tested.
As shown in the Figure 7, the total test results in Building 1 and Building 2 confirm that the proposed method can improve the accuracy of floor positioning compared with only using a single floor positioning method. In more detail, we tested the relationship between the threshold value in the calibration process and the number of times BPFP is triggered, as well as the accuracy. Trigger tests were carried out on the seventh floor (F7) of Building 3. The floor plan of the F7 is shown in Figure 8. The hollow area is located at the right of the whole map, which is marked in red. It is worth noting that the HMM component was turned off during the trigger tests. As shown in Figure 9, the higher the threshold, the more times BPFP is triggered. In our tests, the accuracy of floor positioning also increases with the increase of the threshold Figure 10 benefiting from the high accuracy of BPFP in short time and in confined space. However, in practical applications, excessive dependence on BPFP is unreliable because of the long-term instability of barometric pressure. For trade-off, we choose a threshold of 0.7 in this paper.    In more detail, we tested the relationship between the threshold value in the calibration process and the number of times BPFP is triggered, as well as the accuracy. Trigger tests were carried out on the seventh floor (F7) of Building 3. The floor plan of the F7 is shown in Figure 8. The hollow area is located at the right of the whole map, which is marked in red. It is worth noting that the HMM component was turned off during the trigger tests. In more detail, we tested the relationship between the threshold value in the calibration process and the number of times BPFP is triggered, as well as the accuracy. Trigger tests were carried out on the seventh floor (F7) of Building 3. The floor plan of the F7 is shown in Figure 8. The hollow area is located at the right of the whole map, which is marked in red. It is worth noting that the HMM component was turned off during the trigger tests. As shown in Figure 9, the higher the threshold, the more times BPFP is triggered. In our tests, the accuracy of floor positioning also increases with the increase of the threshold Figure 10 benefiting from the high accuracy of BPFP in short time and in confined space. However, in practical applications, excessive dependence on BPFP is unreliable because of the long-term instability of barometric pressure. For trade-off, we choose a threshold of 0.7 in this paper.  As shown in Figure 9, the higher the threshold, the more times BPFP is triggered. In our tests, the accuracy of floor positioning also increases with the increase of the threshold Figure 10 benefiting from the high accuracy of BPFP in short time and in confined space. However, in practical applications, excessive dependence on BPFP is unreliable because of the long-term instability of barometric pressure. For trade-off, we choose a threshold of 0.7 in this paper.
As shown in Figure 9, the higher the threshold, the more times BPFP is triggered. In our tests, the accuracy of floor positioning also increases with the increase of the threshold Figure 10 benefiting from the high accuracy of BPFP in short time and in confined space. However, in practical applications, excessive dependence on BPFP is unreliable because of the long-term instability of barometric pressure. For trade-off, we choose a threshold of 0.7 in this paper.  To correct occasional error of floor positioning caused by wireless noises and barometric noises, we introduce the HMM to filter the floor positioning results obtained by the BWFP and the BPFP. As Figure 11 shows, due to the use of historical information, the accuracy has been improved after performing the HMM correction. Moreover, we compare our proposed method with several other floor identification methods mentioned in [17]. From Figure 7a, the average accuracy of our proposed method is 99.2%. Table 5 shows our proposed hybrid floor positioning method outperforms other single sensor methods and fusion methods with the same sample datasets. The parameter k in k-NN [13] test is assigned to 8,9,10,11 respectively and the optimal accuracy is obtained when k is 11. In the ANNs [15] test, we define two layers of 50 neurons per layer and choose sigmoid as the activation function. In FLD [17] test, we calculating corresponding weight vector by combining the two pairs in the sample sets. The initial value of parameter and in [26] is assigned to 0.2 m and 0.1 m.  To correct occasional error of floor positioning caused by wireless noises and barometric noises, we introduce the HMM to filter the floor positioning results obtained by the BWFP and the BPFP. As Figure 11 shows, due to the use of historical information, the accuracy has been improved after performing the HMM correction. To correct occasional error of floor positioning caused by wireless noises and barometric noises, we introduce the HMM to filter the floor positioning results obtained by the BWFP and the BPFP. As Figure 11 shows, due to the use of historical information, the accuracy has been improved after performing the HMM correction. Moreover, we compare our proposed method with several other floor identification methods mentioned in [17]. From Figure 7a, the average accuracy of our proposed method is 99.2%. Table 5 shows our proposed hybrid floor positioning method outperforms other single sensor methods and fusion methods with the same sample datasets. The parameter k in k-NN [13] test is assigned to 8, 9, 10, 11 respectively and the optimal accuracy is obtained when k is 11. In the ANNs [15] test, we define two layers of 50 neurons per layer and choose sigmoid as the activation function. In FLD [17] test, we calculating corresponding weight vector by combining the two pairs in the sample sets. The initial value of parameter and in [26] is assigned to 0.2 m and 0.1 m.  Moreover, we compare our proposed method with several other floor identification methods mentioned in [17]. From Figure 7a, the average accuracy of our proposed method is 99.2%. Table 5 shows our proposed hybrid floor positioning method outperforms other single sensor methods and fusion methods with the same sample datasets. The parameter k in k-NN [13] test is assigned to 8, 9, 10, 11 respectively and the optimal accuracy is obtained when k is 11. In the ANNs [15] test, we define two layers of 50 neurons per layer and choose sigmoid as the activation function. In FLD [17] test, we calculating corresponding weight vector by combining the two pairs in the sample sets. The initial value of parameter S w and S b in [26] is assigned to 0.2 m and 0.1 m.

Motion Detection and Positioning in the Intermediate Areas Between Floor
We conducted several experiments in Building 2 with three floors. During testing, three testers (U1, U2, U3) walking on four paths (F1 → F2, F2 → F3, F3 → F2, F2 → F1). Through multiple groups of tests, it can be seen that cumulative probability of switching delay within 2 s exceeds 90% as Figure 12 shows. The switching delay is defined as the time difference between the time when user arrives at the new floor and the system is updated to the new floor.
Sensors 2020, 20, x FOR PEER REVIEW 16 of 20 of tests, it can be seen that cumulative probability of switching delay within 2 s exceeds 90% as Figure  12 shows. The switching delay is defined as the time difference between the time when user arrives at the new floor and the system is updated to the new floor. We also tested the performance of our proposed method in the intermediate areas between floors. The tester moves from F7 to F8 in Building 3 with holding the phone and stays at one quarter, one-half, three quarters of the intermediate areas for 10 s. We collected 50 sets of data and the cumulative probability of the altitude error estimated by our proposed method in the intermediate areas between floors is shown as Figure 13. The average height estimation error using our proposed method in the intermediate areas is about 0.26 m and the probability of altitude error within 0.5 m exceeds 90%, which confirms that our proposed floor positioning method can provide continuous and accurate vertical coordinates within multi-story buildings.

Caculation Complexity
We compared the training time and testing time using different classification model to evaluate the calculation complexity of our proposed algorithm. Table 6 lists the time cost of different classification models. We also tested the performance of our proposed method in the intermediate areas between floors. The tester moves from F7 to F8 in Building 3 with holding the phone and stays at one quarter, one-half, three quarters of the intermediate areas for 10 s. We collected 50 sets of data and the cumulative probability of the altitude error estimated by our proposed method in the intermediate areas between floors is shown as Figure 13. The average height estimation error using our proposed method in the intermediate areas is about 0.26 m and the probability of altitude error within 0.5 m exceeds 90%, which confirms that our proposed floor positioning method can provide continuous and accurate vertical coordinates within multi-story buildings.
Sensors 2020, 20, x FOR PEER REVIEW 16 of 20 of tests, it can be seen that cumulative probability of switching delay within 2 s exceeds 90% as Figure  12 shows. The switching delay is defined as the time difference between the time when user arrives at the new floor and the system is updated to the new floor. We also tested the performance of our proposed method in the intermediate areas between floors. The tester moves from F7 to F8 in Building 3 with holding the phone and stays at one quarter, one-half, three quarters of the intermediate areas for 10 s. We collected 50 sets of data and the cumulative probability of the altitude error estimated by our proposed method in the intermediate areas between floors is shown as Figure 13. The average height estimation error using our proposed method in the intermediate areas is about 0.26 m and the probability of altitude error within 0.5 m exceeds 90%, which confirms that our proposed floor positioning method can provide continuous and accurate vertical coordinates within multi-story buildings.

Caculation Complexity
We compared the training time and testing time using different classification model to evaluate the calculation complexity of our proposed algorithm. Table 6 lists the time cost of different classification models.

Caculation Complexity
We compared the training time and testing time using different classification model to evaluate the calculation complexity of our proposed algorithm. Table 6 lists the time cost of different classification models. From Table 6 we can see that, although Bayesian model requires less training time than the XGBoost model, its accuracy in actual testing is far less than that of the XGBoost model. On the other hand, longer offline training time cost does not affect the user application online. Therefore, as a trade-off measure, it is more appropriate to choose XGBoost as the BWFP classifier. In actual test, XGBoost takes less time than Bayesian method. By dividing each feature into blocks and sorting the blocks, the XGBoost adopts the parallel computing method to search for the best splitting point, which greatly reduces the testing time [34].

Discussion and Conclusions
In this paper, we have proposed a multi-mode fusion floor positioning architecture, which embraces the BWFP method using XGBoost, BWFP augmentation with BPFP using HMM, and motion detection. Through the integration of multiple methods, the accuracy and delay which affect the floor positioning field have been greatly improved. Furthermore, our proposed method can provide continuous vertical coordinates when users walk up/down stairs or takes an elevator in the intermediate area between floors. By adopting a confidence threshold, we built a bridge between BWFP and BPFP, and used HMM method to filter out the occasional floor positioning errors. The proposed motion detection method makes our floor positioning to a higher level and achieves a precise and robust milestone. We evaluated our proposed algorithm in four complex indoor environments. The evaluation results demonstrate that the floor positioning accuracy can reach 99.2% and the probability of switching delay within 2 s exceeds 90%, which outperforms other existing floor positioning methods and can meet the real-time requirements of floor positioning.
As future work, we have identified some minor problems in our proposed method, especially the extra overhead caused by the selection of many hyperparameters, such as the threshold of switch between BWFP and BPFP, the pre-trained emission probability of HMM, etc. These values require labor-intensive data collection for each new building. We will try crowdsourcing methods to reduce the need for expert work.

Conflicts of Interest:
The authors declare no conflict of interest. Table A1. Motion Detection Feature.

Feature Equation Illustration
Mean 1 n n i=1 x i = x 1 +x 2 +...+x n n Represents trends in a set of data sets A measure that is used to quantify the amount of variation or dispersion of a set of data values. Var Measures how far a set of (random) numbers are spread out from their average value.
The difference between maximum and minimum Iqr Interquartile range The IQR is a measure of variability, based on dividing a data set into quartiles.

Kurtosis
Kurt[X] = E X−µ σ 4 A measure of the "tailedness" of the probability distribution of a real-valued random variable.
Skewness γ = E X−µ σ 3 A measure of the asymmetry of the probability distribution of a real-valued random variable about its mean.

RMS
x rms = 1 n (x 1 2 + x 2 2 + . . . + x n 2 In the evaluation of experimental results, the errors must be positive or negative relative to the average value. RMS can better reflect the discreteness of experimental results errors by eliminating the symbolic effect when the error is squared. Integral In our experiments, the acceleration integral represents the velocity and the angular velocity integral represents the rotation angle.

Double Integral
f (x, y)dy]dx Displacement is expressed by double integral of acceleration