iBeacon Indoor Positioning Method Combined with Real-Time Anomaly Rate to Determine Weight Matrix

This paper proposes an indoor positioning method based on iBeacon technology that combines anomaly detection and a weighted Levenberg-Marquadt (LM) algorithm. The proposed solution uses the isolation forest algorithm for anomaly detection on the collected Received Signal Strength Indicator (RSSI) data from different iBeacon base stations, and calculates the anomaly rate of each signal source while eliminating abnormal signals. Then, a weight matrix is set by using each anomaly ratio and the RSSI value after eliminating the abnormal signal. Finally, the constructed weight matrix and the weighted LM algorithm are combined to solve the positioning coordinates. An Android smartphone was used to verify the positioning method proposed in this paper in an indoor scene. This experimental scenario revealed an average positioning error of 1.540 m and a root mean square error (RMSE) of 1.748 m. A large majority (85.71%) of the positioning point errors were less than 3 m. Furthermore, the RMSE of the method proposed in this paper was, respectively, 38.69%, 36.60%, and 29.52% lower than the RMSE of three other methods used for comparison. The experimental results show that the iBeacon-based indoor positioning method proposed in this paper can improve the precision of indoor positioning and has strong practicability.


Introduction
Nowadays, Global Navigation Satellite System (GNSS) technology, navigation, and positioning services have become an indispensable service in people's lives, especially for travel-related services. Such location services cannot be provided indoors, however, due to difficulties in receiving signals from GNSS satellites [1]. How to achieve fast, cheap, stable, and high-precision positioning and navigation in indoor contexts where satellite signals are missing has therefore become an urgent problem to be solved. At present, positioning and navigation services for indoor uses mainly rely on technologies such as Wireless Local Area Network (WLAN), Ultra-Wide Band (UWB), iBeacon, etc. [2][3][4]. Of these, iBeacon has been favored by many scholars due to its low cost, ease of operation, and signal stability [5]. In addition, indoor positioning and navigation services based on this technology have already been commercialized in many large shopping malls, parking lots, and other such venues [6].
Target positioning based on iBeacon technology mainly depends on the RSSI (Received Signal Strength Indication) value of the iBeacon base station broadcast signal [7]. Specifically, the current methods for solving positioning coordinates based on iBeacon technology are mainly divided into two types: fingerprinting technology and trilateration model. A comparison of these two main techniques is shown in Table 1 [8][9][10][11]. Fingerprinting technology has become a hot topic in current research due to its high stability and precision. The basic theory of Fingerprinting technology is to match the RSSI with the values in the database. It is not necessary to convert the RSSI value through a multi-mathematic model into a distance for positioning calculation. Therefore, this method does not require a distance estimation model and is more stable. This approach, however, requires a complete and detailed fingerprint database to be collected and constructed in the locations where it is used, alongside the installation of base stations. This in turn raises costs and increases the complexity of the positioning process, meaning that the technology cannot be easily applied in any location [12]. In contrast, the only preliminary work needed in the trilateration approach is the deployment of iBeacon base stations at fixed locations and determination of the ranging model parameters, meaning that it is simple and economical to implement.
On the other hand, the trilateration method cannot deliver highly precise positioning, with an absolute positioning error of about five meters [3]. How to improve the positioning precision and stability of the trilateration method has therefore become a problem worthy of research. The relative imprecision of the trilateration method arises partly from its reliance on a nonlinear positioning model, which seeks the best the optimal solution algorithm, and partly from the fact that environmental influences make the RSSI value of the iBeacon base station signal unstable. In addition, the particular trilateration model used also affects the positioning precision. At present, the most commonly used method is to perform differential linearization and then apply the least squares method to solve, or iteratively solve, the positioning coordinates [13,14].
In the above approach, as the RSSI is prone to fluctuations, it is often necessary to do some preprocessing of the original signal before positioning. At present, the main methods used for the preprocessing of abnormal RSSI signal values are filtering algorithms, such as Kalman filtering, particle filtering, mean filtering, etc. [15][16][17]. While these methods can often achieve good results when there is a large amount of RSSI signal data available, in practice it is often necessary to perform coordinate calculations within just a few seconds, which requires a signal anomaly detection method that can be applied effectively even when the amount of data is small. At the same time, most of the current preprocessing methods for RSSI signals only reduce noise and eliminate abnormal signals, and thus do not make full use of the abnormal characteristics of the signal source.
This paper therefore proposes the use of the isolation forest algorithm [18] to detect and eliminate signal anomalies even with a small sample size. It then calculates the anomaly rate of each signal source while removing abnormal signals, and sets the weight matrix using each anomaly rate and the RSSI after removing abnormal signals. Finally, using the most common trilateration model solution method-i.e., the least squares methoda weighted Levenberg-Marquardt (LM) algorithm [19] is constructed to achieve highprecision positioning indoors, based on iBeacon technology.

Overview
The goal of this paper is to verify an indoor high-precision fast positioning method based on iBeacon technology. The basic theory of this paper is trilateration, applying the isolation forest algorithm and the weighted LM algorithm. The basic idea of this paper is to first collect the RSSI values of all iBeacon base stations deployed in the indoor scene, and Sensors 2021, 21, 120 3 of 16 then use the isolation forest algorithm to perform anomaly detection on the RSSI values of each signal source in a short period of time. After detecting abnormal signals, the anomaly rate of the signal broadcast by each iBeacon base station is calculated, and the average value of each group of signals, after removing the abnormal RSSI signal, is adopted as the final RSSI at the current point. Finally, a weight matrix is generated by combining the signal anomaly rate of each iBeacon base station with the RSSI value. Under the constraints of this weight matrix, the LM algorithm is used to solve the coordinates. The method flowchart of this paper is shown in Figure 1.
Sensors 2020, 20, x FOR PEER REVIEW 3 of 17 to first collect the RSSI values of all iBeacon base stations deployed in the indoor scene, and then use the isolation forest algorithm to perform anomaly detection on the RSSI values of each signal source in a short period of time. After detecting abnormal signals, the anomaly rate of the signal broadcast by each iBeacon base station is calculated, and the average value of each group of signals, after removing the abnormal RSSI signal, is adopted as the final RSSI at the current point. Finally, a weight matrix is generated by combining the signal anomaly rate of each iBeacon base station with the RSSI value. Under the constraints of this weight matrix, the LM algorithm is used to solve the coordinates. The method flowchart of this paper is shown in Figure 1.

BLE-Based and Trilateration
The trilateration method (see Figure 2) for indoor positioning based on Bluetooth low-energy devices is a fast and cheap positioning method. It determines the current point coordinates mainly by receiving the RSSI value broadcast by iBeacon base stations deployed in a fixed position in an indoor scene and applying a 2D plane coordinate solution model such as in Equation (1)

BLE-Based and Trilateration
The trilateration method (see Figure 2) for indoor positioning based on Bluetooth low-energy devices is a fast and cheap positioning method. It determines the current point coordinates mainly by receiving the RSSI value broadcast by iBeacon base stations deployed in a fixed position in an indoor scene and applying a 2D plane coordinate solution model such as in Equation (1) below [20], where (x i , y i ) is the unknown coordinate of the current point, (x n , y n ) is the fixed coordinate of each iBeacon base station, and D n is the distance between the current unknown point and each iBeacon base station. This distance can be calculated by an attenuation factor model between the RSSI value and D, as in Equation (2) [21]: Equation (1) only discusses the 2D situation, because the plane coordinates already satisfy most situations when used in daily life; however, Equation (1) can also be extended to 3D coordinates. At this time, where P is the RSSI value of the fixed iBeacon base station received at the current unknown point, P(d 0 ) is the RSSI value from the iBeacon base station at a certain distance, generally d 0 = 1m, and n is the signal attenuation factor in the current scene. In different environments, its value is also not always the same, and thus the relationship between the RSSI value and D (Distance between receiving signal point and base station) has to be obtained, as in Equation (3).
Sensors 2020, 20, x FOR PEER REVIEW 5 of 17 Although it is relatively simple to use Equation (5) to calculate the coordinates, because the RSSI signal is affected by various environmental factors, there will be large signal fluctuations and thus low positioning reliability regardless of the distance from the iBeacon signal source. The weighting method in Equation (5) cannot reduce the error caused by this low credibility of the short-distance signal source. This paper therefore constructs a new weight matrix in Equation (5) according to the signal anomaly rates, and uses the nonlinear least squares LM algorithm to solve the positioning coordinates under the constraints of this weight matrix.

Anomaly Detection and Isolation Forest
The RSSI value of iBeacon's Bluetooth signal is susceptible to fluctuations due to For the purposes of this paper, we set P(d 0 ) to A n , and rewrite P to the collected RSSI value to get Equation (4). This means that there are then only two unknown parameters in the formula A n , n. These can be obtained by doing fixed distance experiments and fitting in the experimental data.
As for the solution of Equation (1), it is currently more common to linearize it first and then solve it by least squares, giving the final solution formula as Equation (5): where X is the current unknown point coordinates. B, l can be obtained by linearizing the Equation (1), and the weight matrix W is usually set 1 RSSI 2 . When only the data broadcast by three iBeacons are used to calculate the current unknown point coordinates, the schematic diagram is shown in Figure 2.
Although it is relatively simple to use Equation (5) to calculate the coordinates, because the RSSI signal is affected by various environmental factors, there will be large signal fluctuations and thus low positioning reliability regardless of the distance from the iBeacon signal source. The weighting method in Equation (5) cannot reduce the error caused by this low credibility of the short-distance signal source. This paper therefore constructs a new weight matrix in Equation (5) according to the signal anomaly rates, and uses the nonlinear least squares LM algorithm to solve the positioning coordinates under the constraints of this weight matrix.

Anomaly Detection and Isolation Forest
The RSSI value of iBeacon's Bluetooth signal is susceptible to fluctuations due to environmental interference during the collection process. To obtain high-precision positioning results, it is necessary to discover and eliminate abnormal RSSI in time. In other words, it is often necessary to eliminate outliers within a few seconds when performing indoor positioning and navigation. The relatively small amount of data available in these timescales makes the conventional robust estimation, Gaussian filtering, and other methods less effective [22]. This paper uses the isolation forest algorithm proposed by Zhou Zhihua et al. (2008) [18] for abnormal signal detection. This algorithm can achieve better anomaly detection results even with a small amount of data.
The basic idea of the isolation forest algorithm is to use several random planes to cut the data space repeatedly until there is only one data point in each data space. The specific process of anomaly detection is as follows [18].
(I) Randomly select ψ samples from all the data as the training subsample, and put it into the root node of the tree.
(II) Specify a dimension and randomly generate a plane cutting point Q within the range of the current node data. The range of the cutting point is between the maximum and minimum values of the training subsample.
(III) A plane is generated at the cutting point Q, and the data space of the current node is divided into two subspaces: put the points less than Q in the currently selected dimension on the left branch of the current node, and put the points greater than or equal to Q in the branch to the right of the current node.
(IV) Repeat steps II and III on the left and right branch nodes of the node, and continue to construct new leaf nodes until there is only one datum on the leaf node, or the tree has grown to the set maximum height.
(V) After constructing T isolation trees with the training subsamples, for each RSSI value in the entire data that needs anomaly detection, make it traverse the generated T isolation trees, and calculate the results in the T isolation trees. The average depth of each RSSI value is used to calculate the outlier of each RSSI value, where the outlier is defined as in Equation (6): where E(h(RSSI)) is the average depth of a certain RSSI value in T isolation trees, and c(ψ) is the average value of the path length of the isolation tree generated by the training sample ψ.
(VI) Using Equation (6) and the isolation trees generated by training, calculate the S(RSSI) of the RSSI values broadcast by different iBeacons in turn. If the S(RSSI) is closer to 1, it is considered to be a signal outlier.
As shown in Figure 3, taking the RSSI value 0.2 m away from an iBeacon base station in the experimental scene as an example, RSSI 1 only needs one plane cut to make it the only datum in the space, whereas RSSI 2 needs to be cut six times to make it the only datum in the space. RSSI 1 is therefore considered to be the abnormal signal value within that group Sensors 2021, 21, 120 6 of 16 of data. According to this principle, and combined with Equation (6), anomaly detection can be performed on all the collected RSSI signals. Of course this is just an ideal situation. Only one segmentation strategy was used to detect abnormal signals. In fact, a variety of segmentation strategies needs to be used in the experimental part, and finally the score is calculated according to Equation (6), which is used to determine whether a signal value should be defined as an outlier.

LM Optimization with Weighted Anomaly Rate
When using Equation (5) to solve the coordinates, if the equation is directly linearized, a certain error will be generated in the model. We therefore used the LM algorithm to solve the coordinates iteratively. From Equation (1), the plane coordinate solution model (8) and (9) can be obtained: Furthermore, Equation (9) can be written as solving Equation (10): The LM algorithm is an improved Gauss-Newton method [23], and its iterative solution equation is as in Equation (11): are the plane coordinates from every iBeacon base station involved in the coordinate solution, and i D is the spatial distance between the coordinate position to be solved and the iBeacon base station, which can be calculated by Equation (4). Furthermore, in order to find the opti- Compared with other methods, using the isolation forest algorithm to perform anomaly detection on the received RSSI has the following advantages. (1) The ability to perform anomaly detection unsupervised, thereby detecting anomalies in continuous data without prior data. (2) The amount of calculation is small, and distributed training and calculation can be realized well. (3) It has good effect and stability for data sets with small data volume and low data dimensions. This algorithm is therefore suitable for rapidly (i.e., within a few seconds) detecting abnormalities within the RSSI signals received from each iBeacon base station in an indoor location. Abnormally fluctuating signals can be detected in a relatively short time, and the abnormal rate of each signal source in that time period can be calculated. The equation for calculating the abnormal rate is as in Equation (7): Abnormal signals All signals (7)

LM Optimization with Weighted Anomaly Rate
When using Equation (5) to solve the coordinates, if the equation is directly linearized, a certain error will be generated in the model. We therefore used the LM algorithm to solve the coordinates iteratively. From Equation (1), the plane coordinate solution model (8) and (9) can be obtained: Furthermore, Equation (9) can be written as solving Equation (10): The LM algorithm is an improved Gauss-Newton method [23], and its iterative solution equation is as in Equation (11): where x s is the plane coordinate vector [Y, X] T to be solved, (x i , y i ) are the plane coordinates from every iBeacon base station involved in the coordinate solution, and D i is the spatial distance between the coordinate position to be solved and the iBeacon base station, which can be calculated by Equation (4). Furthermore, in order to find the optimal solution coordinates, the sum of squares should be minimized, as shown in Equation (12).
The LM approach then performs a Taylor expansion of Equation (10) at (Y, X) = (Y k , X k ), and omits terms of the second order and above so as to get the iterative formula of Equation (13): where J f is the Jacobian matrix of the function. For the i iBeacon base station signal sources, J f can be expressed as in Equation (14), I is the identity matrix of the coordinate vector to be solved, and ε f is the residual vector matrix of each iteration, which can be calculated as in Equation (15): The µ in Equation (13), meanwhile, is the damping coefficient. When µ is small, the iteration process becomes the Gauss-Newton method of iteration, which has secondorder convergence. When µ is large, on the other hand, the iteration process follows the gradient descent method, and the iteration converges quickly, the damping coefficient can be controlled by the Equation (16): where h is the iteration step size, and L(0) − L(h) is as in Equation (17).
In the iterative process, the damping coefficient µ is adjusted through ρ, then the current iterative solution process is selected. When the iteration terminates at x s+1 − x s < λ, the coordinate solution is completed, and λ is a minimal value. The method for determining the initial damping coefficient of the iteration is µ 0 = max{(J f T J f ) ii }. It can be seen that the iterative solution of Equation (13) is not weighted, that is, the weight of the signal data of each iBeacon base station participating in the coordinate calculation is the same. In reality, however, the signal quality of different iBeacon base stations is different and thus the overall precision of the positioning can be improved by assigning different weights to iBeacon base stations. Accordingly, we add a weight matrix based on Equation (13) in combination with the anomaly detection results described in Section 2.3 to obtain Equation (18): where the weight matrix is constructed by Equation (19): (19) where RSSI i is the mean value of the i-th iBeacon base station after removing the abnormal values within a period of time, and β i can be expressed by Equation (20): α i can be obtained through Equation (7). According to Equation (20), the non-abnormal rate of each signal source is normalized. In other words, the iBeacon base stations at the location are sorted according to the fluctuations within a given period of time, and weights are assigned according to their abnormal rates. The optimal coordinates of the current point can be solved iteratively through Equations (11), (16) and (19) using the RSSI values of each iBeacon base station collected over that same period of time.

Experiment
The location for the experiment was an indoor venue with a size of around 92 m × 23 m. The experiment was mainly carried out in a corridor area, which had a minimum width of 2.4 m. We used a Xiao MI mi6 smartphone and its sensors for positioning. During our experiments, we held the smartphone horizontally in both steady and swaying states. The parameters and settings for the iBeacon base stations are shown in Table 2. First, in order to obtain the specific values of A and n in the trilateration model, we set up an iBeacon base station at a fixed location in the test scene, and collected the RSSI values for a period of time at a fixed distance from the base station. Data were collected between 0.3 m and 10.2 m away from the base station, with an interval of 0.3 m. After using the isolation forest algorithm to detect anomalies and eliminate the abnormal signals, the signal strength values collected at each fixed distance were averaged in order to obtain the RSSI corresponding to the current distance. Then, the distance measurement model was fitted under the optimization of the nonlinear least squares algorithm (Figure 4). After identifying and eliminating the abnormal RSSI data at each fixed point, model fitting was performed, and the parameters A n and n in the ranging model were obtained by fitting with A n = −71.58 dBm, n = 2.647. It is worth noting that the fitting method used in this article is the least squares method. More specifically, it is the same as the method used in positioning solution: LM algorithm. As shown in Figure 4, this paper has achieved a good fitting effect based on Equation (4). Obviously, there are no data over fitting phenomenon. Besides, the anomaly detection results at 0.3 m and 9 m from the iBeacon station are shown in Figure 5. It can be clearly seen from Figure 5 that the signal anomaly rate at 9 m was significantly (1.54 times) higher than that at 0.3 m (the abnormal rate at 0.3 m is 13.11%, and that at 9 m is 20.23%). It was therefore necessary to perform real-time anomaly detection for each signal source in the process of positioning and solving. has achieved a good fitting effect based on Equation (4). Obviously, there are no data over fitting phenomenon. Besides, the anomaly detection results at 0.3 m and 9 m from the iBeacon station are shown in Figure 5. It can be clearly seen from Figure 5 that the signal anomaly rate at 9 m was significantly (1.54 times) higher than that at 0.3 m (the abnormal rate at 0.3 m is 13.11%, and that at 9 m is 20.23%). It was therefore necessary to perform real-time anomaly detection for each signal source in the process of positioning and solving. After obtaining the specific A and n parameters required by the ranging model, we set up iBeacon base stations with the same parameters in 15 fixed locations on the experimental floor. At the same time, we planned the path of the experimental data collection ( Figure 6). In the subsequent coordinate calculation process, we performed coordinate calculations at intervals of 0.6 m, and used this to calculate and compare positioning errors. over fitting phenomenon. Besides, the anomaly detection results at 0.3 m and 9 m from the iBeacon station are shown in Figure 5. It can be clearly seen from Figure 5 that the signal anomaly rate at 9 m was significantly (1.54 times) higher than that at 0.3 m (the abnormal rate at 0.3 m is 13.11%, and that at 9 m is 20.23%). It was therefore necessary to perform real-time anomaly detection for each signal source in the process of positioning and solving. After obtaining the specific A and n parameters required by the ranging model, we set up iBeacon base stations with the same parameters in 15 fixed locations on the experimental floor. At the same time, we planned the path of the experimental data collection ( Figure 6). In the subsequent coordinate calculation process, we performed coordinate calculations at intervals of 0.6 m, and used this to calculate and compare positioning errors. After completing the iBeacon layout and data collection path planning, we carried out data collection experiments along the route shown in Figure 6. Then, the collected RSSI was matched with the MAC address, so that each corresponded to its signal source iBeacon base station. A custom coordinate system was used, the origin point for the coordinates is shown in Figure 6, and the MAC address and coordinates of each iBeacon base station are shown in Table 3. Table 3. iBeacons' MAC and Coordinates.

Number
MAC Y X After completing the iBeacon layout and data collection path planning, we carried out data collection experiments along the route shown in Figure 6. Then, the collected RSSI was matched with the MAC address, so that each corresponded to its signal source iBeacon base station. A custom coordinate system was used, the origin point for the coordinates is shown in Figure 6, and the MAC address and coordinates of each iBeacon base station are shown in Table 3. After preprocessing the collected data, i.e., performing the MAC and coordinate matching, we carried out anomaly detection on each group of data from different signal sources at 0.6 m steps according to the isolation forest algorithm described in Section 2.3. The anomaly rate of each group of data was calculated after eliminating the abnormal RSSI. For example, Figure 7 shows the original RSSI anomaly detection results received at the starting point from the iBeacon station B1 and the parallel data after the abnormal RSSI was eliminated.
Using the isolation forest algorithm for anomaly detection and calculating the anomaly ratio, the non-anomaly rate (trusted signal rate) was normalized and combined with the received RSSI to generate a weight matrix. Then, the weighted LM nonlinear least squares algorithm was used to calculate the coordinates of each point to be measured. The positioning results for an example point are shown in Figure 8. The valuation range in the figure refers to the coordinate area included in the 95% confidence interval. The coordinates at the center of that valuation range are chosen as the final positioning solution. As shown in Figure 8, the blue scale on the right represents the distance (m), and from small to high means an increase in distance.
According to the above method, the solutions for the 119 sets of data that were collected are shown in Figure 9. The error statistics are shown in Table 4. Sensors 2020, 20, x FOR PEER REVIEW 12 of 17 Using the isolation forest algorithm for anomaly detection and calculating the anomaly ratio, the non-anomaly rate (trusted signal rate) was normalized and combined with the received RSSI to generate a weight matrix. Then, the weighted LM nonlinear least squares algorithm was used to calculate the coordinates of each point to be measured. The positioning results for an example point are shown in Figure 8. The valuation range in the figure refers to the coordinate area included in the 95% confidence interval. The coordinates at the center of that valuation range are chosen as the final positioning solution. As shown in Figure 8, the blue scale on the right represents the distance (m), and from small to high means an increase in distance. According to the above method, the solutions for the 119 sets of data that were collected are shown in Figure 9. The error statistics are shown in Table 4.  Using the isolation forest algorithm for anomaly detection and calculating the anomaly ratio, the non-anomaly rate (trusted signal rate) was normalized and combined with the received RSSI to generate a weight matrix. Then, the weighted LM nonlinear least squares algorithm was used to calculate the coordinates of each point to be measured. The positioning results for an example point are shown in Figure 8. The valuation range in the figure refers to the coordinate area included in the 95% confidence interval. The coordinates at the center of that valuation range are chosen as the final positioning solution. As shown in Figure 8, the blue scale on the right represents the distance (m), and from small to high means an increase in distance. According to the above method, the solutions for the 119 sets of data that were collected are shown in Figure 9. The error statistics are shown in Table 4.     It can be seen from the table that the maximum point position error is 3.527 m, the average value is 1.540 m, and the RMSE is 1.748 m. Among them, X, Y are the errors of the positioning results in the two vertical directions of the plane. About X, the Y direction as shown in Figure 6. The positioning accuracy obtained by the method proposed in this article is consistent with the current research status based on BLE technology (meter-level accuracy) [2], and is sufficient to meet the needs of indoor navigation and positioning. It is beneficial that the method proposed in this paper greatly improves the stability of positioning accuracy, which will be discussed in more detail in Part 4.

Discussion
In order to better verify the effect of this method in reducing positioning errors, we also designed three comparison algorithms: (A) no anomaly detection together with a weightless LM algorithm to generate the solution [24]; (B) anomaly detection of signals to remove outliers together with a weightless LM algorithm to generate the solution; and (C) no anomaly detection, only the RSSI value used to set the weight matrix and then a weighted LM algorithm used generate the solution [25]. The respective errors of these three positioning methods are shown in Table 5. The experimental positioning results of the three algorithms are shown in Figure 10. Table 5. Errors of comparative methods. Except for Method C, the error in the X direction is worse than the error in the Y direction. This is because Method C only uses RSSI values for weighting; this will cause a certain degree of change in the direction of error distribution when solving. In fact, it is not difficult to see from Table 5. The error difference of the method proposed in this article in the two directions is also smaller than that of methods A and B. However, this does not affect the requirements for actual use. From Figure 10, it can be seen that the result obtained by using the positioning method proposed in this paper is the closest to the real planned path. By comparing Tables 4 and 5, it can be clearly seen that, compared to the three comparator positioning solution methods, the weighted LM algorithm combined with anomaly detection proposed in this paper can reduce errors and improve positioning precision, in both the X or Y direction, or on the plane. Compared with the A, B, and C comparator methods, the method proposed in this paper reduces the Mean YX error by 36.42%, 33.88%, and 26.60% respectively, and the RMSE by 38.69%, 36.60%, and 29.52%, respectively. In addition, the algorithm proposed in this paper reduces the maximum error by 46.64%, 46.50%, and 38.71% in respect to methods A, B, and C, respectively. This shows that the use of isolation forest algorithm for anomaly detection can effectively and quickly detect the abnormal fluctuations of the received signal. Eliminating these abnormal signals can reduce the positioning error and improve the positioning precision. What is more, weighting according to the abnormal ratio of each different signal source can further reduce the error in coordinate calculation.

Mthod in This Paper (m) Error of A (m) Error of B (m) Error of C (m)
In order further to illustrate the superiority of the positioning method proposed in this paper, the error distribution histogram ( Figure 11) and the cumulative distribution curves (Figure 12) of the four positioning algorithms are shown. Comparing Figures 9 and 10, it is obvious that the settlement results for individual positioning points have large fluctuations in all the comparator methods. This phenomenon will inevitably affect the user's experience during the navigation phase, especially the excessive errors in the calculated coordinate values.
Except for Method C, the error in the X direction is worse than the error in the Y direction. This is because Method C only uses RSSI values for weighting; this will cause a certain degree of change in the direction of error distribution when solving. In fact, it is not difficult to see from Table 5. The error difference of the method proposed in this article in the two directions is also smaller than that of methods A and B. However, this does not affect the requirements for actual use.
From Figure 10, it can be seen that the result obtained by using the positioning method proposed in this paper is the closest to the real planned path. By comparing Tables 4 and 5, it can be clearly seen that, compared to the three comparator positioning solution methods, the weighted LM algorithm combined with anomaly detection proposed in this paper can reduce errors and improve positioning precision, in both the X or Y direction, or on the plane. Compared with the A, B, and C comparator methods, the method proposed in this paper reduces the Mean YX error by 36.42%, 33.88%, and 26.60% respectively, and the RMSE by 38.69%, 36.60%, and 29.52%, respectively. In addition, the algorithm proposed in this paper reduces the maximum error by 46.64%, 46.50%, and 38.71% in respect to methods A, B, and C, respectively. This shows that the use of isolation forest algorithm for anomaly detection can effectively and quickly detect the abnormal fluctuations of the received signal. Eliminating these abnormal signals can reduce the positioning error and improve the positioning precision. What is more, weighting according to the abnormal ratio of each different signal source can further reduce the error in coordinate calculation.
In order further to illustrate the superiority of the positioning method proposed in this paper, the error distribution histogram ( Figure 11) and the cumulative distribution curves (Figure 12) of the four positioning algorithms are shown.
From Figure 11, it can be easily seen that the error of the method in this paper is relatively concentrated and the dispersion is small. Seventy percent of the errors are distributed between 0.5 m and 2 m, and 85.71% of the points can ensure that the plane error is less than 3 m, which is obviously better than any of the other three comparative algorithms. It can be seen from Figure 12 that the method proposed in this paper has a very high degree of improvement compared with method A. Among them, compared with the intermediate methods B and C, eliminating the abnormal RSSI value also played a role to a certain extent; however, it is not obvious. The greatest improvement comes from weighting based on the real-time status of each signal source. This shows that using only the RSSI value for weighting is indeed easy to ignore the real-time signal fluctuations of the iBeacon station at a close distance. The method proposed in this paper can improve this phenomenon well. It can be seen from Figure 12b, meanwhile, that the cumulative distribution curve of this method is basically above the other curves, indicating that the error value aggregation is better than with the other methods. With the method proposed in this paper, the probability of an error being within 3.6 m is 1, that is, all errors are less than 3.6 m, which is obviously smaller than with any of the other three methods. From Figure 11, it can be easily seen that the error of the method in this paper is relatively concentrated and the dispersion is small. Seventy percent of the errors are distributed between 0.5 m and 2 m, and 85.71% of the points can ensure that the plane error is less than 3 m, which is obviously better than any of the other three comparative algorithms. It can be seen from Figure 12 that the method proposed in this paper has a very high degree of improvement compared with method A. Among them, compared with the intermediate methods B and C, eliminating the abnormal RSSI value also played a role to a certain extent; however, it is not obvious. The greatest improvement comes from  From Figure 11, it can be easily seen that the error of the method in this paper is relatively concentrated and the dispersion is small. Seventy percent of the errors are distributed between 0.5 m and 2 m, and 85.71% of the points can ensure that the plane error is less than 3 m, which is obviously better than any of the other three comparative algorithms. It can be seen from Figure 12 that the method proposed in this paper has a very high degree of improvement compared with method A. Among them, compared with the intermediate methods B and C, eliminating the abnormal RSSI value also played a role to a certain extent; however, it is not obvious. The greatest improvement comes from

Conclusions
In this paper, we propose an indoor positioning method that detects anomalies in the RSSI of iBeacon signals, eliminates the detected RSSI anomaly, and then sets a weight matrix based on the detected anomaly rate and the RSSI. Under the constraints of this weight matrix, the LM algorithm is used for coordinate calculation. Using this method eliminates the need to establish a fingerprint database before application, and it can ensure lower error and higher positioning precision. Experiments prove that the average point error of the method proposed in this paper is 1.540 m and the RMSE is 1.748 m. Furthermore, in all coordinate points of the solution, the error can be controlled within 3.6 m, and in 85.71% of cases the point error is less than 3 m.
At the same time, in order to better compare the effects of the method proposed in this paper on error control and precision improvement, we have calculated the coordinate error of three other methods. Compared with using the LM algorithm to solve the coordinates without anomaly detection and without setting the weight matrix, the RMSE is reduced by 38.69%. Compared with only using the isolation forest algorithm to detect and eliminate the error, it is reduced by 36.60%, and compared to eliminating outliers but only using RSSI to construct the weight matrix, RMSE reduced by 29.52%. The mean error by the method proposed in this paper is also the lowest. This proves that the algorithm in this paper has the following advantages.
(1) Abnormal signal fluctuations can be detected in a short time, and the positioning coordinates can be solved in time according to the state of different signal sources, with good positioning precision.
(2) While ensuring the overall positioning precision, the loss of positioning accuracy caused by signal fluctuations is greatly improved.
Author Contributions: All authors conceived and designed the study. Y.G. is a Master student that performed all development work. J.Z. is thesis supervisor and organized all work in the computer science subject, W.Z., G.X., and S.D. participated in scene setting, data acquisition, data processing and analysis. All authors contributed to the result analysis and discussions. All authors have read and agreed to the published version of the manuscript.
Funding: This research received no external funding.

Institutional Review Board Statement: Not applicable.
Informed Consent Statement: Not applicable.

Data Availability Statement:
The data presented in this study are available on request from the corresponding author. The data are not publicly available due to privacy.