# Indoor Positioning Integrating PDR/Geomagnetic Positioning Based on the Genetic-Particle Filter
## 2 Materials and Methods
### Geomagnetic Positioning Module
#### 2.2.2 Geomagnetic Multi-Features Positioning Algorithm  
The geomagnetic multi-features positioning algorithm includes the offline database construction stage and online positioning stage. During the database construction stage, the experimenter uses mobile phones to collect the geomagnetic data on each selected point for 15 s, then extracts five geomagnetic features data. The fingerprint of a single point can be expressed as  
Figure 5: Comparison of the untransformed and transformed three-axis geomagnetic data. (**a**) Untransformed three-axis geomagnetic data; (**b**) Transformed three-axis geomagnetic data  
by combining the actual geographic coordinates. For the points without data collection, a linear interpolation [42] is used to obtain the geomagnetic data of these points.  
In the online positioning stage, the real-time collected geomagnetic data will be firstly transformed into the geographic coordinate system, and five geomagnetic features data will be extracted. Then the k-nearest neighbor (KNN) method [43] is employed to obtain the positioning results by traversing the geomagnetic database. If one piece of the real-time collected data is \(\left(B_{x}{}^{\prime},B_{y}{}^{\prime},B_{z}{}^{\prime},B_{h}{}^{\prime},B^{ \prime}\right)\), the distance between the measured and fingerprint data can be calculated as:  
\[d=\sqrt{\left(B_{x}-B_{x}{}^{\prime}\right)^{2}+\left(B_{y}-B_{y}{}^{\prime} \right)^{2}+\left(B_{z}-B_{z}{}^{\prime}\right)^{2}+\left(B_{h}-B_{h}{}^{ \prime}\right)^{2}+\left(B-B^{\prime}\right)^{2}} \tag{14}\]  
If there are \(n\) fingerprint data in the database, \(n\) distances can be obtained by traversing the geomagnetic database. We should find the \(k\) minimum distances, in the meantime, the coordinate points corresponding to these \(k\) minimum distances should be recorded. If the current position vector is \(\mathbf{X}_{m}=\left[\begin{array}{cc}x_{mx}&y_{my}\end{array}\right]^{T}\), it can be calculated as:  
\[\mathbf{X}_{m}=\left[\begin{array}{cc}x_{mx}&y_{my}\end{array}\right]^{T}=\left[ \begin{array}{cc}\frac{1}{k}\bullet\sum\limits_{i=1}^{k}x_{i}&\frac{1}{k} \bullet\sum\limits_{i=1}^{k}y_{i}\end{array}\right]^{T} \tag{15}\]  
where \(x_{i}\) and \(y_{i}\) are the coordinate values of the \(k\) nearest points, \(i=1,2,\cdots\ k\).  
In one second, \(m\) pieces of geomagnetic data can be collected. All of the collected geomagnetic data will be involved in the positioning calculation. Thus, there will be \(m\) positioning results in one second. These results are essential for fusion positioning in Section 2.3. In order to better understand the geomagnetic multi-features positioning algorithm, Algorithm 1 gives the detailed process of it.  
```
1:Input: magnetic database MD, Coordinate data CD, measured magnetic data \(\mathbf{B}_{masure}\), positive integer \(k\)
2:\(\mathbf{B}_{masure}\gets normalize(\mathbf{B}_{masure})\)
3:for\(i\gets 1\) to length (\(\mathbf{B}_{masure}\)) do
4:for\(j\gets 1\) to length(\(\mathbf{MD}\)) do
5: calculate the distance \(d_{j}\)
6: add to \(\mathit{Dist}\), \(\mathit{Dist}\gets d_{j}\)
7:end
8: find \(k\) minimum values of the \(\mathit{Dist}\), \(\mathit{mindist}\leftarrow min(\mathit{Dist})\)
9: index\(\leftarrow\)\(\mathit{find}(\mathit{Dist}==\mathit{mindist})\)
10: current\(\_\)coordinate \(\leftarrow\)\(\mathit{sum}(\mathit{CD}(\mathit{index}))/k\)
11: add current\(\_\)coordinate to pos\(\_\)result, pos\(\_\)result \(\leftarrow\) current\(\_\)coordinate
12:end
13: Output: pos\(\_\)result
```  
**Algorithm 1** Geomagnetic multi-features positioning algorithm