# Magnetic Field-Based Vehicle Positioning System in Long Tunnel Environment
## 3 Proposed System Explanation
### Device Calibration  
The smartphone must be calibrated for position estimation using the magnetic sensor. We created the magnetic field DB using a magnetic sensor embedded in the smartphone. The output of the magnetic sensor included various error factors such as sensor alignment error and bias, which were included for constructing the magnetic field DB. In the localization phase, the calibration was performed by assuming that the magnetic sensor value for a particular position of the smartphone was equal to that stored in the DB. The experimental results conducted in the tunnel using two independent smartphones are presented in Figure 6, which depict a similar pattern including a bias between the two values. Figure 4: Magnetic field value in the tunnel. Figure 5: Magnetic field values of repeated experiments in the tunnel. (**a**) high repeatability, (**b**) recurrence of a specific pattern. As the vehicle position before entering the tunnel is known from the GNSS, the magnetic sensor of the user smartphone can be calibrated based on the corresponding DB value. The magnetic sensor values recorded using the two smartphones in indoor conditions are presented in Figure 7, wherein the blue and red lines represent the y axis values of the magnetic sensor of the first and second smartphones, respectively. The experimenter walked with the two smartphones side-by-side. The experimenter held two smartphones in the same direction and walked up to 1000 samples. Thereafter, the experimenter altered the attitude of the second smartphone and walked further. Up to 1000 samples, the two smartphones exhibited similar patterns due to their identical orientation. However, the absolute values of the magnetic sensors varied due to the bias of the two magnetic sensors. Subsequently, the y axis value varied as the axis of the second smartphone was altered after 1000 samples. The orange line denotes the results of altering the axis of the second smartphone with respect to the DB frame with the sensor calibration. Finally, the y axis values of the two smartphones were observed to be highly similar. Notably, the body frame of the user's smartphone must be converted into the DB frame for accurate position estimation. When collecting the magnetic field DB, the pitch angle of the smartphone is 90 degrees, and its negative z axis is the same as the vehicle's moving direction. In other words, the smartphone was vertically attached on the dashboard during the creation of the magnetic field DB, and this frame was defined as the DB frame. The magnetic DB is represented as follows:  
\[\Phi=\left[ \begin{array}{ccc}\vdots&\vdots\\ p_{k}^{d,\rho}&\phi_{k}^{d,\rho}\\ \phi_{k+1}^{d,\rho}&\phi_{k}^{d,\rho}\\ \vdots&\vdots\\ p_{1}^{d}&\phi_{1}^{d}\\ p_{2}^{d}&\phi_{2}^{d}\\ \vdots&\vdots\\ p_{N}^{d}&\phi_{N}^{d}\\ \end{array} \right]=\left[ \begin{array}{cccc}\vdots&\vdots&\vdots&\vdots\\ p_{k}^{o}&x_{k}^{d,o}&y_{k}^{d,o}&z_{k}^{d,o}\\ p_{k+1}^{o}&x_{k+1}^{d,o}&y_{k+1}^{d,o}&z_{k+1}^{d,o}\\ \vdots&\vdots&\vdots&\vdots\\ p_{1}&x_{1}^{d}&y_{1}^{d}&z_{1}^{d}\\ p_{2}&x_{2}^{d}&y_{2}^{d}&z_{2}^{d}\\ \vdots&\vdots&\vdots&\vdots\\ p_{N}&x_{N}^{d}&y_{N}^{d}&z_{N}^{d}\\ \end{array} \right] \tag{1}\]  
where \(p_{k}^{O}\) indicates the position of the fingerprint for outdoor and \(p_{k}\) stands for indoor fingerprint position. \(\phi_{k}^{O}\) denotes the magnetic field value of fingerprint DB at \(k\)-th RP  
Figure 6: Magnetic field values of two distinct smartphones in the tunnel. outdoors. \(x_{K}^{d,O}\) is the magnetic field value of x axis of fingerprint DB at \(k\)-th RP outdoors and \(x_{1}^{d}\) is the magnetic field value of x axis of fingerprint DB at first RP in the tunnel. The fingerprint DB for outdoors is used in the calibration process of the user smartphone, and the fingerprint DB stored indoors is used for vehicle localization. In this study, we proposed a very simple calibration method and the process is as follows. The measured magnetic field value from the user smartphone can be expressed as:  
\[