# A Real-Time BLE/PDR Integrated System by Using an Improved Robust Filter for Indoor Position
## 3 Materials and Methods  
### BLE Position Technology  
The fingerprint position is mainly based on the similarity of the received signal strength (RSS) and the fingerprint database to obtain the position result. The RADAR system was the first RSS-based fingerprint system developed by [PERSON] et al. [29] for indoor localization by utilizing a KNN algorithm. Like any other fingerprint method, the BLE fingerprint position method consists of two stages: the offline data training stage and the online positioning stage. During the offline data training stage: people stand at the reference points (RPs) whose coordinates are known in advance to collect the RSS from the access points (APs) for some time. Then, the fingerprint database as shown in Equation (1)is constructed after computing the distribution of collected data. Suppose that there are \(n\) RPs and \(m\) APs in the position scenario. \[\text{Fingerprint database}=\left[ \begin{array}{cc}(x_{1},y_{1})&\left\langle rssi _{1}^{1},rssi_{2}^{1},rssi_{3}^{1},\ldots,rssi_{m}^{1}\right\rangle\\ (x_{2},y_{2})&\left\langle rssi_{1}^{1},rssi_{2}^{1},rssi_{3}^{1},\ldots,rssi_{m }^{1}\right\rangle\\ \vdots&\vdots\\ (x_{n},y_{n})&\left\langle rssi_{1}^{1},rssi_{2}^{1},rssi_{3}^{1},\ldots,rssi_{m }^{1}\right\rangle\end{array} \right] \tag{1}\]  
During the online positioning stage, the position of the target is obtained by matching the real-time fingerprint to the database on certain algorithms. There are many matching algorithms. Considering the efficiency of real-time positioning and the simplicity of implementation, the classic matching method is K-nearest Neighbor (KNN). The basic idea of the KNN algorithm is to classify the target into the nearest sample class in the feature space. For the BLE fingerprint position method, the feature space is the fingerprint database. The process of BLE fingerprint KNN algorithms is shown as follows:  
Step 1: When online positioning is carried out, a real-time fingerprint is collected by smartphone. The real-time fingerprint is expressed as Equation (2). \[\text{Real time fingerprint}=[\left\langle rssi_{1},rssi_{2},\ldots,rssi_{m} \right\rangle] \tag{2}\]  
Step 2: Then the Euclidean distance between the real-time fingerprint and fingerprint database can be calculated by the following Equation (3). \[d_{i}=\sqrt{\left(rssi_{1}-rssi_{1}^{i}\right)^{2}+\left(rssi_{2}-rssi_{2}^{i} \right)^{2}+\cdots+\left(rssi_{m}-rssi_{m}^{i}\right)^{2}} \tag{3}\]  
Step 3: Then we sort the \(n\) distance \(d_{i}\) in ascending order and choose the first K items to calculate the target position by averaging the \(K\) corresponding coordinates as shown in Equation (4). \[(x,y)=\frac{1}{K}\sum_{i}^{K}(x_{i},y_{i}) \tag{4}\]  
The process of the fingerprint position method is shown in Figure 1.  
Figure 1: The process of the BLE fingerprint position method. In addition to the general fingerprint position process described above, BLE real-time fingerprint also has its features. When we carry out a real-time BLE fingerprint position, the BLE module broadcasts data at a certain frequency. The broadcast data include the identity number, module name, mac address, received signal strength indicator (RSSI), and other information. The broadcast frequency is usually from 10 nanoseconds to 10 s, and the default broadcast frequency is 500 milliseconds. The common android devices such as smartphones provide a function to scanning the BLE signal for real-time fingerprint position. Generally, the continuous positioning with a time interval of 1 s is regarded as the real-time position. Due to the influence of the scanning mechanism, the number of the scanning BLE RSSI is often different in 1 s. In addition to the impact of signal fluctuations, the number of the scanning BLE RSSI will also cause errors in fingerprint position. Here are the real-time RSSIs from 54 BLE APs in one position scenario at certain RP collected by smartphone HUAWEI P20 in 60 s. The collected data per second correspond to a real-time fingerprint data, totaling 60 fingerprint data.