## 2 System
### Attitude Estimation
#### 2.3.4 Correction of Attitude Estimates Using a Geomagnetic Sensor  
Using the values obtained from the geomagnetic sensor, the absolute angles of the _Yaw_ axes with respect to the world coordinates can be obtained.  
By rotating the geomagnetic sensor values based on the attitude calculated from the acceleration and angular velocity, we can obtain the same values \(I=(l_{x},l_{y},l_{z})\) when the sensor is horizontal.  
\[I=R(\mathbf{q^{\prime}_{t}})\mathbf{m} \tag{31}\]  
Considering \(l_{x},l_{y}\), we can calculate the error concerning the direction at the beginning of the process. If the sensor was facing north at the beginning of the process, then the error concerning north can be obtained. As in the case of the accelerometer, the corrected quaternion \(\mathbf{q_{m}}\) from the geomagnetic sensor can be obtained as in Equation (32).  
\[\mathbf{q_{m}}=\left[\begin{array}{c}\sqrt{\frac{(l_{2}+l_{g}^{2})+l_{x}\sqrt{l_ {2}^{2}+l_{y}^{2}}}{2(l_{2}^{2}+l_{y}^{2})}}\\ 0\\ 0\\ \frac{l_{y}}{\sqrt{2\left\{(l_{2}^{2}+l_{y}^{2})+l_{x}\sqrt{l_{2}^{2}+l_{y}^{ 2}}\right\}}}\end{array}\right] \tag{32}\]  
If the obtained correction quaternion \(\mathbf{q_{m}}\) is used as it is, it will be affected by all the effects of the noise from the geomagnetic sensor. Thus, it is necessary to use linear interpolation with the non-rotating quaternion \(\mathbf{q_{I}}=(1,0,0,0)\). We define \(\beta\) as the value of the correction strength of the correction quaternion and set a new correction quaternion \(\mathbf{q^{\prime}_{m}}\).  
\[\mathbf{q^{\prime}_{m}}=\left[\begin{array}{c}\beta q_{m,0}+(1-\beta)\\ \beta q_{m,1}\\ \beta q_{m,2}\\ \beta q_{m,3}\end{array}\right] \tag{33}\]  
From the above, the quaternion representing the attitude corrected by the geomagnetic sensor can be calculated as in Equation (34):  
\[\mathbf{q^{\prime\prime}_{t}}=\mathbf{q^{\prime}_{m}}\mathbf{q^{\prime}_{t}} \tag{34}\]  
where \(\mathbf{q^{\prime\prime}_{t}}\) is the quaternion representing the corrected attitude in all axes, i.e., _Pitch_, _Roll_, and _Yaw_.  
2.3.5. Dealing with Geomagnetic Sensor Disturbances  
The value of the geomagnetic sensor is affected by magnets or other magnetizing objects contained in other devices or worn on the body. While disturbances are often not considered in conventional studies, they must be taken into account in practical applications. Because the geomagnetic sensor is the only sensor that can obtain the direction in world coordinates, it is important to deal with disturbances to estimate the direction of motion.  
In this study, the value of \(\beta\) in Equation (33) is changed according to the magnitude of the error of the value obtained from the geomagnetic sensor compared with the normal condition. In addition, to accommodate changes in offset values caused by variations in surrounding structures, updates to the offset adjustment described in the geomagnetic sensor section (Section 2.2.3) are also performed. However, this update is not calculated when the value of \(\beta\) in Equation (35) is 0, as it is then affected by other devices.  
We redefine the correction strength \(\beta\) as follows:  
\[\beta=\beta_{0}\cdot f(e_{m}) \tag{35}\]  
where \(\beta_{0}\) is the fixed correction intensity and \(f(e_{m})\) is a function of the error concerning the geomagnetic sensor value \(M_{a}\) under normal conditions. We define \(e_{m}\) and \(f(x)\) as follows.  
\[e_{m}=\sqrt{\frac{1_{x}^{2}+l_{y}^{2}+l_{z}^{2}}{-M_{a}}} \tag{36}\]  
\[f(x)=e^{-c_{1}x^{2}} \tag{37}\]  
It is necessary to conduct experiments to obtain appropriate values for \(\beta_{0}\) and \(c_{1}\).