# Secure Indoor Localization Based on Extracting Trusted Fingerprint
## 4 Secure WiFi Fingerprint Localization
### Online Phase  
Because the environment is dynamic and the equipment in the environment has safety hazards, in the offline phase, it may be able to receive the RSSI of APs, and in the online phase, it cannot receive the RSSI of APs; as shown in Table 2. Originally, the location that is closest to the online location is location \((x_{1},y_{1})\). However, due to the instability of \(AP_{5}\), the RSSI of the \(AP_{5}\) is not received by the location to be positioned. If you think that the position to be located is too far from \(AP_{5}\) when the fingerprint is matched, it will be matched to the wrong position. As shown in Table 2, if \(AP_{5}\) participates in localization, it can be concluded that the position to be located is closest to position \((x_{2},y_{2})\). In order to avoid the impact of the problem on the localization results, we need to filter out the AP that has theproblem. When we calculate the distance, we only calculate the fingerprint value that is not zero in both the online phase and the offline phase. For a newly-introduced AP, if there is no RSSI information of the new AP in the fingerprint database, you cannot locate using the AP, and this method can filter the newly-introduced APs. The reference anchor node cannot receive the RSSI of broken APs during the online phase, but the RSSI of the APs exist in the database; the broken APs can be filtered by this method, as well.  
In the online stage, first obtain the RSSI matrix to be positioned \(\varphi=[s_{1},s_{2},\cdots,s_{n}]\) and then calculate the European distance of the fingerprint to be positioned and the fingerprint at each sampling point; if the position to be located is identified that cannot accept the information from AP\({}_{j}\), then make \(s_{j}=0\). The distance formula of the \(\varphi\) vector and the RSSI of the reference point in the fingerprint database \(\Psi\) are shown as follows:  
\[l_{i}=\frac{\left(\sum\limits_{j=1}^{M}w_{j}|s_{j}-\varphi_{i,j}|^{p}\right)^{ 1/p}}{M}. \tag{8}\]  
where \(s_{j}\) is the RSSI of AP\({}_{j}\) received by the position to be located, \(w_{j}\) is the trust value obtained by the number of votes, the \(p\) is two and \(M\) represents the number of APs for which the RSSI is not zero in either the online phase or the offline phase. The smaller the value of \(l_{i}\), the higher the matching degree of fingerprints. According to this principle, we sort \(l_{i}\), in ascending order, and the weight is calculated as follows:  
\[w^{\prime}_{K-i+1}=l_{i}\Bigg{/}\sum\limits_{j=1}^{K}l_{j} \tag{9}\]  
In order to reduce the influence of interference factors on the localization results, the algorithm records the best matching K fingerprint records, obtains the position information of the corresponding reference points and then uses the RKNN algorithm to calculate the coordinates of the position to be located. The equation is as follows:  
\[\left(\overset{\cdot}{x},\overset{\cdot}{y}\right)=\sum\limits_{i=1}^{K}w^{ \prime}_{i}\left(x_{i},y_{i}\right). \tag{10}\]  
where \(\left(x_{i},y_{i}\right)\) is the position corresponding to the \(i\)-th reference point in the kreference points and \(\left(\overset{\cdot}{x},\overset{\cdot}{y}\right)\) is the estimated location of the location to be positioned.  
When calculating the euclidean distance, the algorithm adds the weight information of trusted APs. If there are impaired APs in the environment, the false fingerprint information of impaired APs will seriously affect the fingerprint matching. The addition of the AP trust weight can reduce the impact of impaired APs on fingerprint matching and find the fingerprint with higher similarity to the location to be positioned.  
\begin{table}
\begin{tabular}{c c c c c c c} \hline \hline
**Location** & **AP\({}_{1}\)** & **AP\({}_{2}\)** & **AP\({}_{3}\)** & **AP\({}_{4}\)** & **AP\({}_{5}\)** & **AP\({}_{6}\)** \\ \hline \(\left(x_{1},y_{1}\right)\) & \(-68\) & \(-57\) & \(-53\) & \(-41\) & \(-74\) & \(-68\) \\ \(\left(x_{2},y_{2}\right)\) & \(-73\) & \(-59\) & \(-54