#### 3.2.1. Separate Signal-Attenuation Models in the Offline Phase

The distance can be estimated by measuring the instant RSS and using a prebuilt radio propagation model that reveals the one-to-one corresponding relationship between distance and RSS. Actually, the log-distance path loss model was most frequently used in previous works because the channel fading characteristic contains a log-normal distribution [

23,

32,

33]. Therefore, our study chooses this model as well to train the signal-attention models, as shown below:

where

$RSS$ is a dependent variable,

$d$ is an independent variable,

${d}_{ref}$ is the reference distance, and

$RSS\left({d}_{ref}\right)$ is the RSS at the reference point.

$\alpha $ is the parameter representing the path-loss exponent, and

${X}_{\sigma}$ follows a Gaussian distribution, with zero mean [

33].

It is apparent that three sets of signal-attenuation models are needed because the information of three BLE channels is utilized in our design. Therefore, we establish three signal-attenuation models ($\mathrm{denoted}\text{}\mathrm{as}\text{}{M}_{37}$,$\text{}{M}_{38}$ and ${M}_{39}$) with respect to CH 37, CH 38 and CH 39, respectively, in the offline training phase. However, only one model was trained for the aggregated RSS in the conventional method. It is apparent that three separate models can better reveal the feature of each channel information. This offline training phase normally includes two steps: (1) collection of the RSS during a given time period at a fixed position, and use of the mean value of the RSS measurements as the “observation” of this position; (2) the recording of a set of “observations” and the distances between the receivers (smartphones) and senders (BLE beacons). In this way, a least-square method can be utilized to find the optimal value of parameter $\alpha $ in Equation (1) in the offline phase. Under the framework of the least-square method, the three parameters can be obtained. ${\alpha}_{37}$ represents the path-loss exponent in CH 37. CH 38 and CH 39 each may have a different parameter as ${\alpha}_{38}$ or ${\alpha}_{39}$.

To test the separate signal-attenuation models, a long corridor is selected as our experimental environment, with the Google Pixel 3 L being used. Sixteen positions are chosen, and the distance between each pair of adjacent positions is 1.2 m. Collection of the RSS for 5 minutes at every fixed position to a distance of 19.2 m is carried out, and the mean value of the collection is regarded as the raw RSS. The raw RSS values are recorded with the true distance at every fixed position. In the offline phase, the record is trained to fit the signal-attenuation models (see

Figure 4). The dotted line represents the mean value of the collected RSS at every fixed position, and the symbol ’*’ represents the signal-attenuation models.

${R}^{2}$, called the goodness of fit, is employed to evaluate the established model. It is apparent from

Figure 4 that the separate signal-attenuation models have a higher

${R}^{2}$ values than those of the aggregate signal-attenuation models. In the offline phase, the separate signal-attenuation models represent the relatively optimal models.

In the online phase, the distance should then be estimated from each signal-attenuation model (

${M}_{37}$,

${M}_{38}$ and

${M}_{39}$). To verify the separate models in practice, another test in the same long corridor using the Google Pixel 3 L is carried out. In this phase, the RSS is collected for 10 s at every fixed point, as in the offline phase. Every received RSS is input into the separate signal-attenuation models to obtain an estimate distance. By recording the true distance and the estimated distance inferred from the models, we can output the CDF (cumulative distribution function) map of the errors, as shown in

Table 1.

The implication of the results shown in

Table 1 is that all three signal-attenuation models can estimate a distance from the smartphones to the beacons. The 90 percentile distance errors are no less than 4.0 m, which is not sufficient for precise indoor positioning. For this, a distance decision algorithm with data filtering is proposed to achieve adaptable and robust indoor positioning.

#### 3.2.2. Data Filtering

In this study, three beacons (each of them is coded in the level of firmware to broadcast only one channel) are combined as a station to achieve the broadcast of separate channel information. It is worth mentioning that some of the past works directly modified the hardware of a single beacon to achieve the broadcast of three channels of information at the same time. Unlike previous works, we bypass the technical difficulty of modifying the hardware and manage to obtain the three channels of information by simply combining three beacons as a station (each of them is coded in the level of firmware to broadcast only one channel). Despite this convenience, our method may introduce a new problem, that is, the packet loss of some channels during one round of a scanning. We have assumed that the RSSs from the three channels are completely synchronized, which is contrary to reality. Hence, we develop a “lost detection” method to tag the channel that is unavailable for one round of a scanning. In addition, outliers that make great jumps should be detected and removed/smoothed at this stage, which can be achieved by the median filter algorithm [

34]. The details are expanded in the following.

During a given time period, the received package has a different number of detected beacons. If one beacon is not detected, the RSS of this beacon in this round of scanning is an empty one, that is, it is lost. The “lost” RSS is critical for the later distance decision, so we have to distinguish which beacon is “lost”. To this end, we carry out loss detection as follows (see Equation (2)), which is actually a process of tagging. When

${R}_{i}$ is empty,

${T}_{i}$ is equal to 0. In contrast,

${T}_{i}$ is equal to 1 if

${R}_{i}$ is not empty. Loss detection provides the tags needed for median filtering:

where

${T}_{i}$ is the tag in time period

$i$ and

${R}_{i}$ represents the received RSS in time period

$i$.

After loss detection, median filtering is carried out to address the data with tags sequentially. Here, we take CH 37 as an example to illustrate the process of median filtering.

$\{RS{S}_{37,1},RS{S}_{37,2},RS{S}_{37,3},\text{}\dots ,\text{}RS{S}_{37,i}\}$, which denotes the RSS sequence of CH 37 (different smartphones have different sampling frequencies) during the sampling period, has a matched tag sequence

$\{ta{g}_{37,1},ta{g}_{37,2},ta{g}_{37,3},\text{}\dots ,\text{}ta{g}_{37,i}\}$, found by Equation (2). A sliding window of

$W{L}_{1}$ in length is adopted to sample the median value. For

$i=1,2\dots ,t-W{L}_{1}+1$, we have:

where

$W{L}_{1}$ is the length of the sliding window,

$R{F}_{i}$ is the selected RSS and

${R}_{i}$ represents the RSS of CH 37 in time period

$i$; when the total count is

$t$, the max of

$i$ is

$t-W{L}_{1}+1$.

In other words, the purpose of median filtering is to remove the outlier, which behaves as a sudden jumping point. Mainly, ${T}_{i}$, the tag of the last point in the sliding window, is deemed the decisive point. If the value of the decisive point is zero, the whole sliding window should be thrown out. Correspondingly, some fixed points, the median values of the sliding window, should be inserted.

To test the approach of median filtering and loss detection, in the same long corridor, RSS values are collected at every fixed position for 10 s, as in the online phase. For example, the set of RSS values for the Huawei P20 at a fixed position 3 m away before and after the methodology is shown in

Figure 5. When the value of

$W{L}_{1}$is 5, the probability of the outlier being here is 15%. In fact, the probability of outliers mainly depends on the environment, which we cannot improve.

Figure 5a shows the plot of raw data, while the reprocessed data are shown in

Figure 5b. The number of outliers in

Figure 5a has been considerably reduced in

Figure 5b. After median filtering, the sharp noise was deleted fully. Meanwhile, the process of loss detection is shown in

Figure 5b. The fixed point has been inserted. On the whole, the process of data filtering makes the RSS values more gathered and smooth. The combination of loss detection and median filtering can output a reprocessed and clean sequence of RSSs for later use in the distance decision strategy.

#### 3.2.3. Distance Decision

After data filtering, the three sets of RSS values correspond with a series of distances in separate channels. For example, the ${i}_{\mathrm{th}}$ point of the filtered RSS in CH 37 can output a distance result called ${D}_{37}$, as well as ${D}_{38}$ and ${D}_{39}$. However, it should be noted that one can never expect to acquire ${D}_{37}$, ${D}_{38}$ and ${D}_{39}$ every time, as some of these parameters might be lost, as depicted before. To synthesize the final distance, the distance decision algorithm is implemented to analyze and optimally combine the three estimated distances derived from the separate signal-attenuation models. With the hypothesis that three beacons in three channels can be used to output the final distance, our distance decision strategy is illustrated as follows according to the number of valid distances.

2-Channel is used when the number of valid distances (valid channel information) is two. In this case, the possible combinations are presumably ${D}_{37}$ and ${D}_{38}$, ${D}_{37}$ and ${D}_{39}$, or ${D}_{38}$ and ${D}_{39}$. Two steps are followed: (1) detecting the variance of a single channel and (2) detecting the difference between the two channels.

For instance,

${D}_{\mathrm{Q}}$ and

${D}_{\mathrm{P}}$ (

$Q,P$ = 37, 38, 39) are valid here. In the first step, there is a threshold and a sliding window for variance detection. The variance detection requires that

$\sigma <Th{r}_{1}$(where

$\sigma $ is the variance of a single channel and

$Th{r}_{1}$ represents the threshold of variance in step one). Only if the two specific channels meet the requirement of variance detection does step two, called difference detection, commence. The process of difference detection in 2-Channel can be described mathematically as shown in Equation (4):

where

$W{L}_{2}$ is the length of the sliding window,

$Th{r}_{2}$ represents the threshold of variance in difference detection in time period

$i$,

$\text{}{D}_{\mathrm{Q},i}$ is the value of the distance in channel Q and

${D}_{\mathrm{P},i}$ is the value of the distance in channel P.

As a consequence, the ultimate output distance

${\mathit{D}}_{i}$ is the weighted average of

${D}_{\mathrm{Q}}$ and

${D}_{\mathrm{P}}$:

where

${m}_{1}$ and

${m}_{2}$ are the weights for channel Q and channel P, respectively,

${\sigma}_{\mathrm{Q}}$ is the variance of channel Q, and

${\sigma}_{\mathrm{P}}$ is the variance of channel P. High variance in variance detection means more interference and lower weight.

3-Channel is used when the number of valid distances is three. In addition, 3-Channel is more precise and persuasive than 2-Channel in practice because of the greater availability of measurements. Similarly, two steps are also followed: (1) detecting the variance of each of the three channels separately and (2) detecting the difference between every two channels. The differences between any two of the three distances (${D}_{37}$, ${D}_{38}$, and ${D}_{39}$) should be taken into account.

In the first step, there is a threshold and a sliding window for variance detection. The variance detection requires that

$\sigma <Th{r}_{1}$, as demanded by 2-Channel (where

$\sigma $ is the variance of a single channel and

$Th{r}_{1}$ represents the threshold of variance in step one). Only if all three separate channels fulfill the requirement of variance detection is step two, called difference detection, commenced. The process of difference detection in 3-Channel can be described mathematically as shown in Equation (6):

where

$W{L}_{3}$ is the length of the sliding window,

$Th{r}_{3}$ represents the threshold of variance in difference detection in time period

$i$,

${D}_{37,i}$ is the value of the distance in CH 37,

${D}_{38,i}$ is the value of the distance in CH 38 and

${D}_{39,i}$ is the value of the distance in CH 39.

Accordingly, the ultimate output distance

${\mathit{D}}_{i}$ is the weighted average of distance 37, distance 38 and distance 39:

where

${m}_{1}$,

${m}_{2}$ and

${m}_{3}$ are the weights for CH 37, CH 38 and CH 39, respectively,

${\sigma}_{37}$ is the variance of CH 37,

${\sigma}_{38}$ is the variance of CH 38 and

${\sigma}_{39}$ is the variance of CH 39.

In conclusion, the quality of broadcasting signal is affected by many reasons like walking people, fixed obstacle (desk, chair, cupboard…) and state of transmitter/receiver, etc. Because of these complicate factors in indoor environment, the quality of broadcasting is varying time to time, and there should be thus no fixed relation between the quality and the real distance. However, a direct quality evaluation is possible in our method, by step (1) detecting the variance of each channel separately and step (2) detecting the difference between every two channels. In this way, our method only employs the RSS of “good quality”, resulting in a better distance estimation in theory.

The basic rationale behind our distance decision strategy is that: the interruptions caused by unpredictable factor like walking people on the three channels are different. In another word, the three channels will consistently reflect a same distance estimate if no interruption, however, a large interruption will lead to a large discrepancy of distance estimates between the three channels. By detecting how large is the discrepancy between channels, our distance decision strategy can tell if this is a good or bad measure, and avoid to output result in bad quality. However, the traditional method will adopt all channel outputs without any particular treatment with the error.

In particular, a validation is set up to test our distance decision strategy, as

Figure 6 illustrates. The distance between the station and the smartphone (Google Pixel 3 L) is 5 m. The test is set up as real as possible by (1) distributing some desks and cupboards as obstacles and (2) rotating the smartphones. Although the real case is usually more complicated than our setup, we suggest that the experimental results under our setup still make sense. In addition, three locations (A, B, C) are tested in the experiment: case A in

Figure 6 represents the status of inherent influence. The case of a smartphone backing away from the station is marked as case C (blocked). In this case, the line of sight is blocked. The case in which a smartphone is positioned vertically with straight lines between the station and smartphones is considered case B (not blocked). The three cases provide powerful evidence that the direction of the smartphone makes a difference.

Table 2 shows the results of the different cases when

$Th{r}_{1}$ is 3

${m}^{2}$ in the first step of the distance decision strategy, and

$Th{r}_{2}$ in Equation (4),

$Th{r}_{3}$ in Equation (6) are both 5

$m$.

In fact, NLOS is one of the main factors that may deteriorate distance estimation from RF signals (WiFi/BLE), and many papers in previous dedicate to minimize the NLOS effect [

35], while none of them claims to completely solve the NLOS problem as far as we know. Unlike the previous work that try to calibrate the RSS measures even in NLOS case, this study prefers to avoid result output (usually in bad quality) in NLOS case (or other cases, not limited to NLOS) so as to stabilize the positioning. As

Table 2 demonstrates, in this trial, no results are output when the line of sight is blocked in case C. Because of the tails of the separate signal-attenuation models, a small jitter will result in a large change. When the line of sight is blocked, the value of the RSS becomes very small, which will cause a large error in terms of the distance. Hence, the case will not meet the requirement of the distance decision. In other words, the probability of no output in case C is 100%. In case B, the direction of the smartphones does not improve stability compared with that in case A, being marked as an inherent influence. Thus, the number of times no output occurs in case B is higher than that in case A. The rationale behind our distance decision strategy is that a more precise distance can be obtained with more consistent channel information among the three advertising channels. In brief, the distance result is convincing when the three channels output similar distances.

By combining the use of separate channel information and the distance decision strategy, we suggest that the result should have more adaptability and more robustness to signal interruption caused by, for example, body blockage. Our distance decision strategy based on a relatively long sequence can achieve greater positioning accuracy, which is the major objective of this study.