A Wi-Fi FTM-Based Indoor Positioning Method with LOS / NLOS Identiﬁcation

: In recent years, many new technologies have been used in indoor positioning. In 2016, IEEE 802.11-2016 created a Wi-Fi ﬁne timing measurement (FTM) protocol, making Wi-Fi ranging more robust and accurate, and providing meter-level positioning accuracy. However, the accuracy of positioning methods based on the new ranging technology is inﬂuenced by non-line-of-sight (NLOS) errors. To enhance the accuracy, a positioning method with LOS (line-of-sight) / NLOS identiﬁcation is proposed in this paper. A Gaussian model has been established to identify NLOS signals. After identifying and discarding NLOS signals, the least square (LS) algorithm is used to calculate the location. The results of the numerical experiments indicate that our algorithm can identify and discard NLOS signals with a precision of 83.01% and a recall of 74.97%. Moreover, compared with the traditional algorithms, by all ranging results, the proposed method features more accurate and stable results for indoor positioning.

Among these methods, methods based on Wi-Fi have attracted much attention due to their wide distribution. They can be defined as fingerprint-based methods [16] and distance-based methods. The former can reach an accuracy of about 2 m and needs to construct a fingerprint database at the offline stage, which costs more labor and time. The latter can calculate the distance between the transceivers according to the received signal strength indicator (RSSI), then use the least square (LS), trilateral positioning, or other algorithms to derive the location. However, the RSSI, when collected at a fixed place, could be influenced by device heterogeneity and non-line-of-sight (NLOS) errors, so it is difficult to use widely.
This phenomenon did not change until 2016. The fine timing measurement (FTM) protocol has been standardized by the Institute of Electrical and Electronics Engineers (IEEE) 802.11-2016 and can provide meter-level positioning accuracy [17] through time of flight (TOF) echo technology [18]. However, just like many other ranging measurements, such as UWB [19,20] and Global Positioning System (GPS) [21,22], one of the major challenges for positioning is the mitigation of NLOS effects.
The remainder of this paper is organized as follows: Section 2 introduces the theoretical framework, including the round-trip time (RTT)-based ranging model and the propagation and attenuation of Wi-Fi signals. Section 3 introduces the proposed method, including the construction of the Gaussian model for identification and the iterative least squares algorithm. Section 4 describes the experimental results by the proposed method. Section 5 presents a conclusion and points out areas for future work.

RTT-Based Ranging Model
Here, TOF echo technology is used in the Wi-Fi FTM protocol and makes the RTT based ranging more convenient [18]. This new technology determines the distance according to the RTT of a Wi-Fi FTM pulse from an MT to an FT. Accordingly, it can eliminate the time synchronization errors in the time of arrival (TOA)/time difference of arrival (TDOA)-based ranging, with no need to synchronize the times of the FT and MT. The whole procedure of ranging is shown in Figure 1. It shows that a mobile phone is used as an MT to send an FTM request to FTs supporting the FTM protocol. After an FT receives the request, an Acknowledgement (ACK) signal is sent from the FT to the MT. After that, several FTM feedback signals are sent from the FT to the MT, where the mean RTT can then be calculated. The time information can be expressed as follows: where t request and t ACK are the times for when the request was sent from the MT and when the ACK signal arrives at MT; p MT is the location of the MT when the FTM request is sent; p FT is the location of the FT when the MT receives the FTM request; t D is standard time deviation between the MT and the FT; e NLOS is the time delay error caused by the NLOS effect; and c is the speed of light. Hence, the distance can be calculated by Equation (2): where d RTT is the ranging result; d D is the ranging error caused by standard time deviation, as shown in Equation (3); and d NLOS is the ranging error caused by the NLOS effect. The ranging error d D not only includes a fixed time delay error, a device error, and a start error, but also is influenced by the distance of pulse propagation and other environmental factors [35], which can be expressed as follows: where e n is the constant error caused by the fixed time delay error, the device error, and the start error; ϕ(s) is the error formed by different ranging results, which can be seen as a polynomial function related to the ranging results; and ε is the system noise. It can be seen that the standard time deviation error of the equipment needs to be determined and calibrated to provide more precise ranging results.
where RTT d is the ranging result; D d is the ranging error caused by standard time deviation, as shown in Equation (3); and NLOS d is the ranging error caused by the NLOS effect. The ranging error D d not only includes a fixed time delay error, a device error, and a start error, but also is influenced by the distance of pulse propagation and other environmental factors [35], which can be expressed as follows: where n e is the constant error caused by the fixed time delay error, the device error, and the start error; φ(s) is the error formed by different ranging results, which can be seen as a polynomial function related to the ranging results; and ε is the system noise. It can be seen that the standard time deviation error of the equipment needs to be determined and calibrated to provide more precise ranging results. ...

Fix Terminal Mobile Terminal
.

Propagation of Wi-Fi Signals
With wave-particle duality, electromagnetic waves are the method of Wi-Fi propagation, which exhibit both particle properties and wave properties during propagation [36,37]. In a wide space, electromagnetic waves are only transmitted directly without obstacles. While in an indoor environment, the propagation characteristics will change due to the existence of various objects, causing reflection and diffraction, etc. In addition, electromagnetic waves have a certain penetration ability and can spread across walls. As a result, the actual propagation process of electromagnetic waves is varied and complex.
The propagation of electromagnetic waves follows the 'skin effect' [38]. That is, when there is an alternating current or alternating electromagnetic field in a conductor, the current distributes unevenly and concentrates in the 'skin' part of the conductor, that is, the current is concentrated on the thin layer of the outer surface of the conductor. As a result, the resistance of the conductor is increased, and its power loss is also increased. When an electromagnetic wave carrying a signal passes through some media, it is restricted by the skin effect, such that a part of the electromagnetic wave stays on the surface of the media and cannot completely pass through the media. The better the conductivity of the medium, the more obvious the effect of blocking in the electromagnetic wave is, and the more obvious the attenuation of the signal intensity is. Table 1 presents the signal attenuation of electromagnetic waves with a frequency of 2.4 GHz when crossing various common obstacles in indoor buildings. It can be obtained through observation that the better the conductivity of an obstacle is, the more obvious signal attenuation will be. Electromagnetic waves will wear out when propagating in air. The loss in free space is mainly caused by the air's own propagation and the scattering and refraction of fine dust particles. In the case of no obstacles in the air, the propagation of electromagnetic waves can be expressed as per Equation (4) [39], where d is the distance from the MT to the FT; d 0 is the reference distance; L(d) is the received power of the MT when the distance from the FT is d; L(d 0 ) is the received power when the distance from the FT to the MT is 1 m; η is the attenuation coefficient; and k is the shadowing factor, obeying a Gaussian distribution with a mean of 0. Since the model is in the case of LOS, k is 0. Figure 2 shows the procedures of the proposed positioning method. The ranging results and RSSIs are collected from the FTs and then input into the LOS/NLOS identification model. Then, the model identifies NLOS signals and only outputs the LOS ranging results. If the number of LOS ranging results is greater than the minimum number required for positioning, the LOS ranging results are used as the input of the single point positioning to calculate the location of the MT. If the number of LOS ranging results is less than the minimum number, all the ranging results, including LOS and NLOS, will be used as the input of the single point positioning to derive the location.   Figure 3 shows the ranging results (the red solid line and the dotted line) and RSSIs (the blue solid line and the dotted line) collected at different distances from FTs under both NLOS and LOS conditions. Here, we have placed Wi-Fi devices in an open corridor and in a closed room, then collected RSSIs and ranging results at 1 m intervals in the corridor. The sampling time was 30 s, the sampling frequency was 5 Hz, and the sampling device was a Pixel 3 mobile phone. The solid line denotes the results from a corridor and the dotted line denotes the results from a closed room. It can be seen that the LOS and NLOS ranging results are similar at any distance, but the RSSIs are quite different. This is due to the principle of electromagnetic wave propagation. RSSIs mainly reflect the amplitude of the electromagnetic wave. When electromagnetic waves travel through walls, some particles will not pass through walls, and the amplitude will significantly reduce, such that the RSSI will also be reduced [38]. The ranging results mainly reflect the time of propagation. When the electromagnetic waves pass through the wall, their speed will decrease. However, due to the small thickness of the wall and the high electromagnetic velocity, the impact on the time of propagation and ranging result is small. Under such conditions, the ranging results are not obvious when compared with those of an RSSI. The LOS/NLOS identification model was designed based on this phenomenon. According to Section 2.2, the attenuation of the RSSIs was greatly affected by the conductivity of obstacles. In the complex indoor environment, it is difficult to model the relationship between the  Here, we have placed Wi-Fi devices in an open corridor and in a closed room, then collected RSSIs and ranging results at 1 m intervals in the corridor. The sampling time was 30 s, the sampling frequency was 5 Hz, and the sampling device was a Pixel 3 mobile phone. The solid line denotes the results from a corridor and the dotted line denotes the results from a closed room. It can be seen that the LOS and NLOS ranging results are similar at any distance, but the RSSIs are quite different. This is due to the principle of electromagnetic wave propagation. RSSIs mainly reflect the amplitude of the electromagnetic wave. When electromagnetic waves travel through walls, some particles will not pass through walls, and the amplitude will significantly reduce, such that the RSSI will also be reduced [38]. The ranging results mainly reflect the time of propagation. When the electromagnetic waves pass through the wall, their speed will decrease. However, due to the small thickness of the wall and the high electromagnetic velocity, the impact on the time of propagation and ranging result is small. Under such conditions, the ranging results are not obvious when compared with those of an RSSI. The LOS/NLOS identification model was designed based on this phenomenon.  Figure 3 shows the ranging results (the red solid line and the dotted line) and RSSIs (the blue solid line and the dotted line) collected at different distances from FTs under both NLOS and LOS conditions. Here, we have placed Wi-Fi devices in an open corridor and in a closed room, then collected RSSIs and ranging results at 1 m intervals in the corridor. The sampling time was 30 s, the sampling frequency was 5 Hz, and the sampling device was a Pixel 3 mobile phone. The solid line denotes the results from a corridor and the dotted line denotes the results from a closed room. It can be seen that the LOS and NLOS ranging results are similar at any distance, but the RSSIs are quite different. This is due to the principle of electromagnetic wave propagation. RSSIs mainly reflect the amplitude of the electromagnetic wave. When electromagnetic waves travel through walls, some particles will not pass through walls, and the amplitude will significantly reduce, such that the RSSI will also be reduced [38]. The ranging results mainly reflect the time of propagation. When the electromagnetic waves pass through the wall, their speed will decrease. However, due to the small thickness of the wall and the high electromagnetic velocity, the impact on the time of propagation and ranging result is small. Under such conditions, the ranging results are not obvious when compared with those of an RSSI. The LOS/NLOS identification model was designed based on this phenomenon. According to Section 2.2, the attenuation of the RSSIs was greatly affected by the conductivity of obstacles. In the complex indoor environment, it is difficult to model the relationship between the According to Section 2.2, the attenuation of the RSSIs was greatly affected by the conductivity of obstacles. In the complex indoor environment, it is difficult to model the relationship between the distance and RSSI. Therefore, differing from the literature [24,25,40], where two models have been built under LOS and NLOS conditions, respectively, this paper's identification model was built in the line-of-sight condition, which could output probability with a large difference according to the condition of the signal.

The identification model of LOS/NLOS
Most existing works [41][42][43] use a Gaussian distribution to model the randomness of RSSI, and consequently, in this paper, a Gaussian model was established to calculate the probability of LOS by Equation (5), as shown in Figure 4. The parameters of the model were determined by ranging results, and the inputs of the model were the RSSIs of the FTs. According to the maximum likelihood method, µ is the mean of the RSSI and σ is the variance of the RSSI in Equations (6) and (7), where RSSI i d is the RSSI collected at the distance d; N is the number of RSSI collected. The determination of µ and σ is described below in detail. After the parameters were determined, the probability could be determined by inputting the RSSI into the Gaussian model. Then, the probability was compared with the threshold θ. If the probability is greater than the threshold, the current signal is a LOS signal, and if it is less than, it is not.
Appl. Sci. 2020, 10, x 6 of 18 distance and RSSI. Therefore, differing from the literature [24,25,40], where two models have been built under LOS and NLOS conditions, respectively, this paper's identification model was built in the line-of-sight condition, which could output probability with a large difference according to the condition of the signal. Most existing works [41][42][43] use a Gaussian distribution to model the randomness of RSSI, and consequently, in this paper, a Gaussian model was established to calculate the probability of LOS by Equation Error! Reference source not found., as shown in Figure 4. The parameters of the model were determined by ranging results, and the inputs of the model were the RSSIs of the FTs. According to the maximum likelihood method, μ is the mean of the RSSI and σ is the variance of the RSSI in Equations Error! Reference source not found. and Error! Reference source not found., where i d RSSI is the RSSI collected at the distance d; N is the number of RSSI collected. The determination of μ and σ is described below in detail. After the parameters were determined, the probability could be determined by inputting the RSSI into the Gaussian model. Then, the probability was compared with the threshold θ . If the probability is greater than the threshold, the current signal is a LOS signal, and if it is less than, it is not.

The Determination of d
In the paper, it was assumed that the ranging results could reflect the true distance to a certain extent. Therefore, we needed to evaluate the accuracy of the ranging results based on Wi-Fi RTT.
As shown in Figure 5, a tester collected the ranging results of the FTs at each grid point. Here, the grid side length was 1 m, the sampling time was 30 s, and the sampling frequency was 5 Hz. The MT and FTs were basically at the same height during sampling. The ranging accuracy is shown in Figure 6. The red and blue solid lines are the ranging errors of the LOS signals and NLOS signals, respectively. Through calculation, the average ranging error of LOS signals was 0.87 m and the variance was 0.36 m. The average ranging error of the NLOS signals was 1.16 m and the variance was 0.54m. It can be seen that RTT-based ranging results can accurately reflect the true distance between the transceivers. At the same time, the ranging accuracy and stability of the LOS signals were better than those of the NLOS signals.
Appl. Sci. 2020, 10, x 7 of 18 In the paper, it was assumed that the ranging results could reflect the true distance to a certain extent. Therefore, we needed to evaluate the accuracy of the ranging results based on Wi-Fi RTT. As shown in Figure 5, a tester collected the ranging results of the FTs at each grid point. Here, the grid side length was 1 m, the sampling time was 30 s, and the sampling frequency was 5 Hz. The MT and FTs were basically at the same height during sampling. The ranging accuracy is shown in Figure 6. The red and blue solid lines are the ranging errors of the LOS signals and NLOS signals, respectively. Through calculation, the average ranging error of LOS signals was 0.87 m and the variance was 0.36 m. The average ranging error of the NLOS signals was 1.16 m and the variance was 0.54m. It can be seen that RTT-based ranging results can accurately reflect the true distance between the transceivers. At the same time, the ranging accuracy and stability of the LOS signals were better than those of the NLOS signals.

The Determination of μ
 is the mean of RSSIs collected when the distance between an MT and FT is determined.
According to the propagation model of electromagnetic waves, in Equation Error! Reference source not found., the true distance is exponential with RSSI, so the exponential model was used to fit the ranging results and RSSIs.
A Wi-Fi device was arranged at a fixed point as the FT. The experimenter walked in a straight line with the mobile phone within 23 m from the FT. One thousand, eight hundred groups of ranging results and RSSIs were collected and used as training data. The collected ranging results and RSSIs were used as training data. The fitting of the single exponential model is shown in Figure  7a. It can be seen that fitting over 15 m performs poorly. Here, the mean square error (MSE) was used to evaluate the fitting, calculated as per Equation Error! Reference source not found., where N is the number of RSSI used for the fitting; (i) RSSI is the i-th RSSI for the fitting; and is the i-th fitting result. By calculating the MSE of the fitting from 0 m to a different distance, as shown in Figure 7b, it was found that within 0-15 m, as the distance increases, the training data increase, and Appl. Sci. 2020, 10, x 7 of 18 In the paper, it was assumed that the ranging results could reflect the true distance to a certain extent. Therefore, we needed to evaluate the accuracy of the ranging results based on Wi-Fi RTT. As shown in Figure 5, a tester collected the ranging results of the FTs at each grid point. Here, the grid side length was 1 m, the sampling time was 30 s, and the sampling frequency was 5 Hz. The MT and FTs were basically at the same height during sampling. The ranging accuracy is shown in Figure 6. The red and blue solid lines are the ranging errors of the LOS signals and NLOS signals, respectively. Through calculation, the average ranging error of LOS signals was 0.87 m and the variance was 0.36 m. The average ranging error of the NLOS signals was 1.16 m and the variance was 0.54m. It can be seen that RTT-based ranging results can accurately reflect the true distance between the transceivers. At the same time, the ranging accuracy and stability of the LOS signals were better than those of the NLOS signals.

The Determination of μ
 is the mean of RSSIs collected when the distance between an MT and FT is determined.
According to the propagation model of electromagnetic waves, in Equation Error! Reference source not found., the true distance is exponential with RSSI, so the exponential model was used to fit the ranging results and RSSIs.
A Wi-Fi device was arranged at a fixed point as the FT. The experimenter walked in a straight line with the mobile phone within 23 m from the FT. One thousand, eight hundred groups of ranging results and RSSIs were collected and used as training data. The collected ranging results and RSSIs were used as training data. The fitting of the single exponential model is shown in Figure  7a. It can be seen that fitting over 15 m performs poorly. Here, the mean square error (MSE) was used to evaluate the fitting, calculated as per Equation Error! Reference source not found., where N is the number of RSSI used for the fitting; (i) RSSI is the i-th RSSI for the fitting; and is the i-th fitting result. By calculating the MSE of the fitting from 0 m to a different distance, as shown in Figure 7b, it was found that within 0-15 m, as the distance increases, the training data increase, and

The Determination of µ
µ is the mean of RSSIs collected when the distance between an MT and FT is determined. According to the propagation model of electromagnetic waves, in Equation (5), the true distance is exponential with RSSI, so the exponential model was used to fit the ranging results and RSSIs.
A Wi-Fi device was arranged at a fixed point as the FT. The experimenter walked in a straight line with the mobile phone within 23 m from the FT. One thousand, eight hundred groups of ranging results and RSSIs were collected and used as training data. The collected ranging results and RSSIs were used as training data. The fitting of the single exponential model is shown in Figure 7a. It can be seen that fitting over 15 m performs poorly. Here, the mean square error (MSE) was used to evaluate the fitting, calculated as per Equation (8), where N is the number of RSSI used for the fitting; RSSI (i) is the i-th RSSI for the fitting; and RSSI (i) f it is the i-th fitting result. By calculating the MSE of the fitting from 0 m to a different distance, as shown in Figure 7b, it was found that within 0-15 m, as the distance increases, the training data increase, and the MSE decreases. Between 15 and 20 m, the MSE becomes larger, and the fitting effect is not good. Over 20 m, the MSE tends to be stable. It can be concluded that the RSSIs collected at the distance over 15 m have a different tendency from those collected within 15 m. Therefore, the ranging result RSSI model was changed into a double exponential model to calculate µ, as shown in Equation (9). The data in the range of 0-15 m and 15-25 m were fitted, respectively. The result of fitting using the double exponential model is shown in Figure 7c. The MSE of the fitting, using the double exponential from 0 m to different distances, is shown in Figure 7d. It can be seen that the MSE at different distances is lower than that of the single exponential, except at a distance of 4 m. The average MSE of the single exponential model was 4.85 dBm 2 , and that of the improved double exponential model was 4.15 dBm 2 . Therefore, the double exponential model is more in line with the ranging result-RSSI relationship.
Appl. Sci. 2020, 10,  Figure 7c. The MSE of the fitting, using the double exponential from 0 m to different distances, is shown in Figure  7d. It can be seen that the MSE at different distances is lower than that of the single exponential, except at a distance of 4 m. The average MSE of the single exponential model was 4.85 dBm 2 , and that of the improved double exponential model was 4.15 dBm 2 . Therefore, the double exponential model is more in line with the ranging result-RSSI relationship.

The Determination of σ
σ is the variance of RSSIs collected at a fixed point. In the literature [24,25], the variances of RSSIs collected at different distances have traditionally been set as a fixed value. According to the analysis in the second section, we assumed that the variances of RSSIs at different distances were different. For this reason, the variances were calculated, as shown in Table 2. It can be seen that the variance decreased by about 1 dBm 2 from 0 to 6 m, while it nearly did not change from 6 to 18 m. According to the trend of change, the exponential function was used to fit the variances and ranging results. To verify if the function was suitable, the sum of squares due to error (SSE) and coefficient of determination (R-square) of the fitting result was compared with that found by other functions, including the Fourier, Gaussian, linear fitting, polynomial, rational, and sum of sine functions, shown in the Table 3. SSE and R-square can be calculated by Equation (10) and Equation (11), where RSSI is the average of RSSI. The smaller the SSE or the bigger the R-square, the better the fitting results will be. It can be seen that from both the SSE and R-square that the exponential function is more suitable. For the fitting, a large amount of RSSIs with the same ranging results should be obtained. However, due to different ranging results, a credible variance was hard to achieve. The ranging results were divided into several 0.5 m-long ranges. Next, all the training data were put into the corresponding range according to the ranging results. Then, the average of the ranging results and the variances of RSSIs in each range were calculated and used as the input of the fitting. The variances were calculated by the following two methods: (a) The variances of RSSIs were directly calculated, according to Equation (7). (b) All the RSSIs were counted in a certain interval and the probabilities of each RSSI were calculated.
Then, the Gaussian regression was performed on the probability and the corresponding RSSI. σ of the Gaussian model was taken as the σ of the current distance.
After the σ values were determined, the ranging results and σ values were fitted to generate a ranging result-based σ model. Figure 8 shows the fitting results of methods A and B. The red dot is the variance calculated by method A, while the blue point is the variance calculated by the other method. The fitting results and raw data are shown in Figure 8a, and the residuals of the two methods are shown in Figure 8b. It can be seen that variances calculated by method B fluctuate largely, which might be caused by over-fitting. In the range of 0-4 m, the variance of method B is higher than 15. Table 1 shows that the attenuation of RSSI caused by the reinforced concrete is about 15 dBm, so that when the variance is higher than 15, the output probability of LOS and NLOS is similar, which may make the set of threshold and identification difficult. Furthermore, as shown in Figure 8b, the fitting result of method A is better than method B, as the sum of square due to error (SSE) of method A is much smaller than that of method B. Hence, method A was used to calculate the variance used for the later fitting.
Appl. Sci. 2020, 10, x 10 of 18 method. The fitting results and raw data are shown in Figure 8a, and the residuals of the two methods are shown in Figure 8b. It can be seen that variances calculated by method B fluctuate largely, which might be caused by over-fitting. In the range of 0-4 m, the variance of method B is higher than 15. Table 1 shows that the attenuation of RSSI caused by the reinforced concrete is about 15 dBm, so that when the variance is higher than 15, the output probability of LOS and NLOS is similar, which may make the set of threshold and identification difficult. Furthermore, as shown in Figure 8b, the fitting result of method A is better than method B, as the sum of square due to error (SSE) of method A is much smaller than that of method B. Hence, method A was used to calculate the variance used for the later fitting.

Single Point Positioning
If the number of the ranging results was more than 2 after filtering, the LS algorithm was used for the single point positioning. The observation equation for the ranging results can be expressed as follows: In the equation, Assuming that the approximate coordinate of MT is X = (X0, Y0) and that the Euclidean distance from the coordinate of the i-th FT to the approximate coordinate of MT is ρ0, the Taylor series of the above formula is: If we set the following: Then the equation could be changed as follows:

Single Point Positioning
If the number of the ranging results was more than 2 after filtering, the LS algorithm was used for the single point positioning. The observation equation for the ranging results can be expressed as follows: In the equation, d i RTT is the ranging result collected from the i-th FT, ρ i is the Euclidean distance between the i-th FT and the MT, d i NLOS is the ranging error caused by the NLOS error from the i-th FT; and d is the ranging error caused by the standard time deviation. According to Equation (12), we can derive the error observation as follows: Assuming that the approximate coordinate of MT is X = (X 0 , Y 0 ) and that the Euclidean distance from the coordinate of the i-th FT to the approximate coordinate of MT is ρ0, the Taylor series of the above formula is: If we set the following: Then the equation could be changed as follows: where dX and dY are the corrections of the approximate coordinates of MT, and X i FT and Y i FT are the two coordinate values of the i-th FT. Thus, Equation (14) can be expressed in a matrix form as follows: (17) where m is the number of ranging results after filtering; V is the vector of the correction of ranging results; L is observation error constant matrix; ∆ is an unknown parameter in Equation (15); and A is the cosine coefficient matrix in Equation (19).
The error observation equation can be established using the ranging results from different FTs, and then the parameters of the coordinate can be obtained by solving the equation with the least square method, as shown in Equation (20).
The pseudocode of single point positioning is shown in Figure 9. The observation equation was constructed using the inputs to calculate ∆. Through iteration, ∆ gradually approached 0, where the approximate coordinate of MT was gradually steady. When ∆ was smaller than a threshold or the iteration number was more than a threshold, the iteration could meet the condition of stopping.  (17) where m is the number of ranging results after filtering; V is the vector of the correction of ranging results; L is observation error constant matrix; Δ is an unknown parameter in Equation (15); and A is the cosine coefficient matrix in Equation Error! Reference source not found..
The error observation equation can be established using the ranging results from different FTs, and then the parameters of the coordinate can be obtained by solving the equation with the least square method, as shown in Equation Error! Reference source not found..

× ×
The pseudocode of single point positioning is shown in Figure 9. The observation equation was constructed using the inputs to calculate Δ . Through iteration, Δ gradually approached 0, where the approximate coordinate of MT was gradually steady. When Δ was smaller than a threshold or the iteration number was more than a threshold, the iteration could meet the condition of stopping.

Evaluation of the Identification Model
The performance of the identification model was evaluated. A Wi-Fi device was set in the corridor, and the experimenter walked at a constant speed in the corridor and room separately with a mobile phone to collect the RSSIs and ranging results. The data collected in the corridor were seen as LOS data, while those collected in the room were seen as NLOS data. A group of data consisted of an RSSI and a ranging result. A total of 8360 groups of data were collected, among which 1800 groups were used for training and 6560 groups were used for testing. The training data acquisition time was only one day away from that of the testing data, and the training data did not participate in the test.

Input :
Process :  1  2  3  4  5  6  7  8  9 Output : Distance matrix , whose elements is ranging results from MT to FTs Coordinates matrix , whose elements is the coordinates of FTs Initial approximate coordinate repeat for all construct the approximate distance matrix , ; construct the constant matrix L, according to the equation (4); construct the cosine coefficient matrix A , according to the equation (6) ; end for calculate the unknown parameter , according to the equation (7); update the approximate coordinare ; until meet the condition of stop x, the final approximate coordinate of MT

Evaluation of the Identification Model
The performance of the identification model was evaluated. A Wi-Fi device was set in the corridor, and the experimenter walked at a constant speed in the corridor and room separately with a mobile phone to collect the RSSIs and ranging results. The data collected in the corridor were seen as LOS data, while those collected in the room were seen as NLOS data. A group of data consisted of an RSSI and a ranging result. A total of 8360 groups of data were collected, among which 1800 groups were used for training and 6560 groups were used for testing. The training data acquisition time was only one day away from that of the testing data, and the training data did not participate in the test.
The identification of NLOS/LOS was a binary problem, so precision and recall were utilized to evaluate the model. They were calculated by Equations (21) and (22), respectively, where the TP (true positive) is the number of LOS signals that were accurately identified, FP (false positive) refers to the number of NLOS signals identified as LOS signals, and FN (false negative) points to the number of LOS signals identified as NLOS signals. All the data were divided into different ranges according to the ranging results in order to evaluate the precision and recall at different distances. Here, 3280 groups of LOS data and 3280 groups of NLOS data were used to test the precision, while 3280 groups of LOS data were used to test the recall. The model output the LOS/NLOS recognition results, then TP, FP, and FN were counted to calculate the precision and recall of each interval. In this experiment, the threshold θ of the model was set as 0.7. Figure 10 shows the precision at different ranges. Through calculation, the average precision was 97.08% and the MSE was 0.07. Figure 11 shows the cumulative distribution of precision. All precisions were higher than 70%, 9.09% of which were lower than 85%, and 15.15% of which were lower than 95%. It can be seen that the precision of the model is poor at some ranges, which might be caused by the poor fitting of the ranging result and RSSI.
Appl. Sci. 2020, 10, x 12 of 18 The identification of NLOS/LOS was a binary problem, so precision and recall were utilized to evaluate the model. They were calculated by Equations Error! Reference source not found. and Error! Reference source not found., respectively, where the TP (true positive) is the number of LOS signals that were accurately identified, FP (false positive) refers to the number of NLOS signals identified as LOS signals, and FN (false negative) points to the number of LOS signals identified as NLOS signals. All the data were divided into different ranges according to the ranging results in order to evaluate the precision and recall at different distances. Here, 3280 groups of LOS data and 3280 groups of NLOS data were used to test the precision, while 3280 groups of LOS data were used to test the recall. The model output the LOS/NLOS recognition results, then TP, FP, and FN were counted to calculate the precision and recall of each interval. In this experiment, the threshold θ of the model was set as 0.7.

TP P=
TP + FP (21) TP R= TP + FN (22) Figure 10 shows the precision at different ranges. Through calculation, the average precision was 97.08% and the MSE was 0.07. Figure 11 shows the cumulative distribution of precision. All precisions were higher than 70%, 9.09% of which were lower than 85%, and 15.15% of which were lower than 95%. It can be seen that the precision of the model is poor at some ranges, which might be caused by the poor fitting of the ranging result and RSSI.  The identification of NLOS/LOS was a binary problem, so precision and recall were utilized to evaluate the model. They were calculated by Equations Error! Reference source not found. and Error! Reference source not found., respectively, where the TP (true positive) is the number of LOS signals that were accurately identified, FP (false positive) refers to the number of NLOS signals identified as LOS signals, and FN (false negative) points to the number of LOS signals identified as NLOS signals. All the data were divided into different ranges according to the ranging results in order to evaluate the precision and recall at different distances. Here, 3280 groups of LOS data and 3280 groups of NLOS data were used to test the precision, while 3280 groups of LOS data were used to test the recall. The model output the LOS/NLOS recognition results, then TP, FP, and FN were counted to calculate the precision and recall of each interval. In this experiment, the threshold θ of the model was set as 0.7.

TP P=
TP + FP (21) TP R= TP + FN (22) Figure 10 shows the precision at different ranges. Through calculation, the average precision was 97.08% and the MSE was 0.07. Figure 11 shows the cumulative distribution of precision. All precisions were higher than 70%, 9.09% of which were lower than 85%, and 15.15% of which were lower than 95%. It can be seen that the precision of the model is poor at some ranges, which might be caused by the poor fitting of the ranging result and RSSI.  The recalls and mean probabilities at different ranges are shown in Figure 12, where the value of the blue column is roughly the same as that of the red line. It can be seen that the set of θ could distinguish LOS signals and NLOS signals. However, through calculation, the average recall was only 74.97% and the MSE was 0.2. Figure 13 shows the cumulative distribution of recalls. Here, 24.24% of the recalls were lower than 60%, and 51.52% of them were lower than 80%, indicating that the model often misjudges some LOS signals.
The recalls and mean probabilities at different ranges are shown in Figure 12, where the value of the blue column is roughly the same as that of the red line. It can be seen that the set of θ could distinguish LOS signals and NLOS signals. However, through calculation, the average recall was only 74.97% and the MSE was 0.2. Figure 13 shows the cumulative distribution of recalls. Here, 24.24% of the recalls were lower than 60%, and 51.52% of them were lower than 80%, indicating that the model often misjudges some LOS signals.

Evaluation of Proposed Positioning Method
The experimental environment is shown in Figure 14  The recalls and mean probabilities at different ranges are shown in Figure 12, where the value of the blue column is roughly the same as that of the red line. It can be seen that the set of θ could distinguish LOS signals and NLOS signals. However, through calculation, the average recall was only 74.97% and the MSE was 0.2. Figure 13 shows the cumulative distribution of recalls. Here, 24.24% of the recalls were lower than 60%, and 51.52% of them were lower than 80%, indicating that the model often misjudges some LOS signals.

Evaluation of Proposed Positioning Method
The experimental environment is shown in Figure 14

Evaluation of Proposed Positioning Method
The experimental environment is shown in Figure 14   In the first experiment, the performance of the method was evaluated when a different number of FTs were set in the NLOS condition. A different number of FTs, from 0 to 7, were set outside the eastern room in turn. The ranging results and RSSIs from all FTs were collected at 67 test points in the eastern room. Then, the data were imported into MATLAB. The location was calculated using single point positioning with identification and discarding (SPP-IAD) NLOS, and that of single point positioning (SPP). Figure 15 shows the accuracy of the two methods. In the absence of NLOS FTs, the error of SPP-IAD is greater than that of SPP. This is because the identification model discards some ranging results from LOS FTs. However, when adding NLOS FTs, the error of SPP-IAD is smaller than SPP. As the number of NLOS FTs increases, the accuracy of SPP-IAD is basically unchanged, and the error of SPP increases. Hence, the accuracy of SPP-IAD is better than SPP when NLOS FTs are present. In the second experiment, the ranging results and RSSIs at all the test points were collected and the proposed method was used to carry out the positioning. Here, the maximum error (ME), error mean (EM), and root mean square error (RMSE) were used as indicators of the method. In the first experiment, the performance of the method was evaluated when a different number of FTs were set in the NLOS condition. A different number of FTs, from 0 to 7, were set outside the eastern room in turn. The ranging results and RSSIs from all FTs were collected at 67 test points in the eastern room. Then, the data were imported into MATLAB. The location was calculated using single point positioning with identification and discarding (SPP-IAD) NLOS, and that of single point positioning (SPP). Figure 15 shows the accuracy of the two methods. In the absence of NLOS FTs, the error of SPP-IAD is greater than that of SPP. This is because the identification model discards some ranging results from LOS FTs. However, when adding NLOS FTs, the error of SPP-IAD is smaller than SPP. As the number of NLOS FTs increases, the accuracy of SPP-IAD is basically unchanged, and the error of SPP increases. Hence, the accuracy of SPP-IAD is better than SPP when NLOS FTs are present.  Figure 14. Experimental area.
In the first experiment, the performance of the method was evaluated when a different number of FTs were set in the NLOS condition. A different number of FTs, from 0 to 7, were set outside the eastern room in turn. The ranging results and RSSIs from all FTs were collected at 67 test points in the eastern room. Then, the data were imported into MATLAB. The location was calculated using single point positioning with identification and discarding (SPP-IAD) NLOS, and that of single point positioning (SPP). Figure 15 shows the accuracy of the two methods. In the absence of NLOS FTs, the error of SPP-IAD is greater than that of SPP. This is because the identification model discards some ranging results from LOS FTs. However, when adding NLOS FTs, the error of SPP-IAD is smaller than SPP. As the number of NLOS FTs increases, the accuracy of SPP-IAD is basically unchanged, and the error of SPP increases. Hence, the accuracy of SPP-IAD is better than SPP when NLOS FTs are present. In the second experiment, the ranging results and RSSIs at all the test points were collected and the proposed method was used to carry out the positioning. Here, the maximum error (ME), error mean (EM), and root mean square error (RMSE) were used as indicators of the method. In the second experiment, the ranging results and RSSIs at all the test points were collected and the proposed method was used to carry out the positioning. Here, the maximum error (ME), error mean (EM), and root mean square error (RMSE) were used as indicators of the method. Figure 16 shows the EM of the SPP-IAD and SPP at each test point. Among them, 18 EMs of SPP-IAD are larger than that of the SPP, and the maximum difference is 0.3 m.   As shown in Table 4, the SPP-IAD was implemented with a ME of 6.862 m, an EM of 0.932 m, and an RMSE of 0.712 m, while the other has greater error than the proposed method. Compared with SPP, it achieves a ME improvement of 1.041 m (13.17%), an EM improvement of 0.337 m (36.04%), and an RMSE improvement of 0.456 m (64.04%).   Table 4, the SPP-IAD was implemented with a ME of 6.862 m, an EM of 0.932 m, and an RMSE of 0.712 m, while the other has greater error than the proposed method. Compared with SPP, it achieves a ME improvement of 1.041 m (13.17%), an EM improvement of 0.337 m (36.04%), and an RMSE improvement of 0.456 m (64.04%). The Cumulative Distribution Functions (CDFs) of the positioning errors of SPP-IAD and SPP are shown in Figure 17. Obviously, the positioning errors of SPP-IAD are smaller than those of SPP with different y-values.   As shown in Table 4, the SPP-IAD was implemented with a ME of 6.862 m, an EM of 0.932 m, and an RMSE of 0.712 m, while the other has greater error than the proposed method. Compared with SPP, it achieves a ME improvement of 1.041 m (13.17%), an EM improvement of 0.337 m (36.04%), and an RMSE improvement of 0.456 m (64.04%).  From the two experiments, it can be concluded that the performance of SPP-IAD is better than that of SPP, both in the positioning accuracy and stability, under the condition NLOS FTs.

Discussion
In order to reduce the positioning errors caused by NLOS, this paper has proposed a LOS/NLOS identification model which is suitable for complex indoor environments, and the parameters of the model have been adaptively determined. After identifying and discarding NLOS ranging results, the LS-based single point positioning algorithm was used. It has been deduced that the average precision of the model was 97.08% and the average recall was 74.97%. The average error of the positioning results was 0.935 m. The accuracy found here is better than that found without identification and discarded in the case of a different number of NLOS FTs. In conclusion, the proposed method can eliminate some NLOS ranging results and effectively improve the positioning accuracy. However, the recall of the model is not high, which may cause some LOS ranging results to be eliminated during positioning and affect the positioning accuracy. In order to solve this problem, map matching [44,45] can be added to the proposed method to reduce misjudgment.