# Indoor Positioning Integrating PDR/Geomagnetic Positioning Based on the Genetic-Particle Filter
## 2 Materials and Methods
### Geomagnetic Positioning Module  
#### 2.2.1 Geomagnetic Multi-Features Data Extraction  
It will be better to describe the distribution of the magnetic field at a single point by utilizing more geomagnetic features data. In addition to the three-axis components \(\left(\begin{array}{cc}B_{x}&B_{y}&B_{z}\end{array}\right)\), the horizontal intensity \(B_{h}\) and the total intensity \(B\) represent the magnitude of the magnetic field in the horizontal plane and the 3-dimensional space. If these two components are utilized for geomagnetic matching positioning, they can provide additional distance information for the matching process. Therefore, we extracted these two features and their calculation methods are as follows:  
\[\left\{\begin{array}{l}B_{h}=\sqrt{B_{x}^{2}+B_{y}^{2}}\\ B=\sqrt{B_{x}^{2}+B_{y}^{2}+B_{z}^{2}}\end{array}\right. \tag{10}\]  
However, the three-axis components of the magnetic field measured by smartphones are in the carrier coordinate system (CCS), whose \(x\), \(y\) and \(z\) axes point to the right, front and top of the device as shown in Figure 4a. These three components vary with the attitudes of smartphones and it is meaningless to directly use the untransformed three-axis magnetic data. Therefore, it is necessary for us to transform the three-axis geomagnetic data to the geographic coordinate system (GCS) because they are stable in the GCS.  
Figure 4: (**a**) The carrier coordinate system (CCS); (**b**) roll; (**c**) pitch; (**d**) yaw.  
The GCS and the CCS can be rotated into each other through attitude angles, which contain yaw, pitch, and roll. Their calculation methods have been described particularly in Section 2.1.1. The rotation matrix \(\mathbf{C}_{n}^{b}\) between the two systems can be defined as:  
\[\mathbf{C}_{n}^{b}=\mathbf{C}_{n}^{3}\mathbf{C}_{n}^{2}\mathbf{C}_{n}^{1}=\left[\begin{array}{ ccc}\cos\gamma&0&-\sin\gamma\\ 0&1&0\\ \sin\gamma&0&\cos\gamma\end{array}\right]\left[\begin{array}{ccc}1&0&0\\ 0&\cos\theta&\sin\theta\\ 0&-\sin\theta&\cos\theta\end{array}\right]\left[\begin{array}{ccc}\cos \psi&-\sin\psi&0\\ \sin\psi&\cos\psi&0\\ 0&0&1\end{array}\right] \tag{11}\]  
where \(\mathbf{C}_{n}^{1}\), \(\mathbf{C}_{n}^{2}\) and \(\mathbf{C}_{n}^{3}\) are the corresponding matrices for yaw, pitch, and roll. Yaw, pitch, and roll respectively represent rotation around the \(z\), \(x\), and \(y\) axes as shown in Figure 4. The rotation matrix \(\mathbf{C}_{b}^{t}\) from the CCS to the GCS can be calculated as:  
\[\mathbf{C}_{b}^{t}=\left(\mathbf{C}_{n}^{b}\right)^{-1}=\left(\mathbf{C}_{n}^{b}\right)^{T} \tag{12}\]  
where \(\left(\mathbf{C}_{n}^{b}\right)^{-1}\) and \(\left(\mathbf{C}_{n}^{b}\right)^{T}\) are the inverse matrix and transposed matrix of \(\mathbf{C}_{n}^{b}\). Supposing that the three-axis components vector of magnetic data in the CCS is \(\mathbf{B}_{M}=\left[\begin{array}{cc}B_{x}&B_{y}&B_{z}\end{array}\right]^{T}\) and \(\mathbf{B}_{S}=\left[\begin{array}{cc}B_{x^{\prime}}&B_{y^{\prime}}&B_{z^{ \prime}}\end{array}\right]^{T}\) is the magnetic data vector in the GCS, the relationship between them is defined as:  
\[\mathbf{B}_{S}=\left(\mathbf{C}_{n}^{b}\right)^{T}\mathbf{B}_{M}=\left[\begin{array}{ ccc}\cos\gamma\cos\psi+\sin\gamma\sin\psi\sin\theta&\sin\psi\cos\theta&\sin \gamma\cos\psi-\cos\gamma\sin\psi\sin\theta\\ -\cos\gamma\sin\psi+\sin\gamma\cos\psi\sin\theta&\cos\psi\cos\theta&-\sin \gamma\sin\psi-\cos\gamma\cos\psi\sin\theta\\ -\sin\gamma\cos\theta&\sin\theta&\cos\gamma\cos\theta\end{array}\right] \tag{13}\]  
We can obtain three-axis stable geomagnetic data by using Equation (13). As shown in Figure 5, the transformed data are stable and the \(x\)-axis components data are close to zero, which are consistent with theoretical results. However, we found that the \(x\)-axis components data of some experimental areas were not close to zero in our research. Therefore, we retain the \(x\)-axis component in this paper. Eventually, we can extract five geomagnetic features data as the fingerprint data by using the above method.