Calibration Method of Magnetometer Based on BP Neural Network

Due to the influence of processing technology and environmental factors, there are errors in attitude measurement with the three-axis magnetometer, and the change of parameters during the operation of the magnetometer in orbit will have a great impact on the measurement accuracy. This paper studies the calibration method of magnetometer based on BP neural network, which reduces the influence of model error on calibration accuracy. Firstly, the error model of the magnetometer and the structural characteristics of the BP neural network are analyzed. Secondly, the number of hidden layers and hidden nodes is optimized. To avoid the problem of slow convergence and low accuracy of basic BP algorithm, this paper uses the Levenberg Marquardt backpropagation training method to improve the training speed and prediction accuracy and realizes the on-orbit calibration of magnetometer through online training of the neural network. Finally, the effectiveness of the method is verified by numerical simulation. The results show that the neural network designed in this paper can effectively reduce the measurement error of magnetometer, while the online training can effectively reduce the error caused by the change of magnetometer parameters, and reduce the measurement error of magnetometer to less than 10 nT.


Introduction
Three-axis magnetometer has the advantages of small size, lightweight and low power consumption, which is often used to determine the attitude of the earth observation satellite. However, there are many problems in the application of magnetometer, such as the three axes are not orthogonal, the sensitivity of the three axes is not consistent, the constant value drift and the internal remanence, leading to a large error between the measured value and the actual value [1]. Therefore, it is necessary to calibrate the magnetometer to reduce the measurement error. At the same time, due to the influence of emission vibration, temperature alternation, particle radiation, and device aging and other factors, the magnetometer will drift or change the installation matrix when it is in orbit, resulting in time-varying error. If the model parameters calibrated by the ground are still used, the measurement error will be large, and the on-orbit training method can eliminate the influence of time-varying factors on the measurement accuracy.
At present, the calibration methods of magnetometer mainly include the least square method [1] [2], pseudo-inverse method [3], LM algorithm [4], neural network method [5], etc. At present, the calibration method of the magnetometer is to establish an error model first, and then identify model parameters [1] [2] [3] [6]. This method cannot eliminate the influence of unknown factors, there are model errors. The algorithm based on the neural network [5] does not introduce model error and has high accuracy.
BP neural network has good model learning ability, a three-layer BP neural network can fit any continuous function [7]. In orbit calibration of the magnetometer needs to improve the online performance of the network, so the network training speed is the main factor affecting the online performance. At present, the commonly used training methods include momentum method, gradient descent method, adaptive learning rate method, Levenberg Marquardt (LM) method, etc. for the network with small structure, the LM algorithm can obtain the fastest training speed [8].
In reference [5], a neural network is designed based on the stochastic gradient descent training method, and the magnetometer is calibrated by on-orbit data. However, the stochastic gradient descent algorithm is inefficient, slow in convergence, and easy to converge to the local optimal solution. Compared with the stochastic gradient descent algorithm, the Levenberg Marquardt backpropagation (LMBP) training algorithm has faster convergence speed. To improve the training speed and convergence of neural networks, LMBP neural network is designed to calibrate the magnetometer.
The rest of this paper is organized as follows. Firstly, the structure of the BP neural network is designed according to the error characteristics of the magnetometer. Then the LM method is used to improve the speed of network training, and the convergence is verified by simulation. After that, the periodic training method is proposed to calibrate the magnetometer and the effectiveness of the proposed method is verified by numerical simulation. Finally, the concluding remarks of the present investigation are noted.

Error Correction Model of Magnetometer
The measurement errors of magnetometer mainly include the nonorthogonal errors caused by the three-axis nonorthogonal, the nonorthogonal errors caused by the inconsistent sensitivity, the drift, and noise caused by the circuit characteristics. The magnetometer error model can be expressed by the following formula.
where m B is the output data of magnetometer, B is the constant drift, B ∆ is the measurement noise, A is the coefficient matrix generated by nonorthogonal error, and B is the actual magnetic field data.

BP Neural Network
According to Kolmogorov's theorem [7], there exist three-layer BP neural network which can realize the mapping from any n-dimension to m-dimension. Thus, BP neural network usually adopts the structure of single hidden layer as it can approach any continuous function. And the number of hidden nodes is the main parameter of BP network structure optimization.

Structure Design of BP Neural Network
The structure of the BP neural network is one of the main factors affecting its performance. Too many hidden nodes in the network might cause over fitting, while too few hidden nodes in the network might affect the prediction ability of the network [9]. The number of hidden nodes of the BP neural network should be as small as possible under the condition of satisfying the requirements of network accuracy. The number of hidden nodes of the BP neural network is usually designed based on empirical formula [10] [11], so it is difficult to ensure the optimal network structure. In this paper, the network structure is optimized by the pruning method. Firstly, a network with 7 hidden nodes is established. Then, if the network accuracy meets the requirements, the hidden nodes will be deleted. For magnetometer calibration using BP neural network, the regression coefficients of neural networks with different hidden nodes are shown in the table below.
The data in Table 1 shows that the three hidden nodes are the most compact structure to meet the accuracy requirements. When the number of hidden nodes is less than 3, the network will diverge. Therefore, this paper adopts the BP neural network with three hidden nodes in a single hidden layer. The network structure is shown in Figure 1.

Levenberg Marquardt Algorithm
The basic BP algorithm has the problems of long training time, difficult to determine the network structure and easy to fall into the local optimal solution. To avoid these problems, some improved BP algorithm were proposed. Compared with the basic BP algorithm, the LMBP training method has higher accuracy and stability and has a better training effect under the same network structure [8] [12] [13]. Therefore, LMBP algorithm is adopted in this paper. Set network input vector is ( ) 1 2 , , , where i O is the expected output of sample i , i y is the network output, and i e is the error of sample i . Neglecting the higher-order infinitesimal, the second-order Taylor expansion of the error function is carried out at the minimum point.
where E ∇ is gradient vector and 2 E ∇ is Hessian matrix.
According to the necessary conditions of extreme value: Therefore: where 2 k H = E ∇ is Hessian matrix and k g E = ∇ is gradient vector. The weight updating formula of Newton method can be obtained when k H is nonsingular.
When the solution is near the extreme point ( ) 0 The weight updating formula of Newton method is as follows: Newton's method needs to inverse the Hessian matrix k H in every iteration, but in practice, k H might be irreversible while LMBP algorithm can avoid this problem. Let: where 0 µ > , I is the unit matrix.
It can be proved that G and k H have the same eigenvector, and the eigenvalue of G is i λ µ + . Properly choosing the value of µ makes the matrix G invertible.
The weight updating formula of LMBP algorithm is as follows.

Simulation
According to the error model of Formula (1), this paper uses the BP neural network to calibrate magnetometer. The random error is the random noise with the mean value of 0 and the standard deviation of 2. The parameters of ground error model are set as follows.
The actual magnetic field is as follows: sin( ) 4000 100 cos( ) sin( ) Figure 2 shows that the maximum error of magnetometer before calibration is greater than 1000 nT.

Magnetometer Calibration Simulation
The trained BP neural network can predict the real magnetic field data according to the measured value of magnetometer. The training process is shown in Figure 3.
The structure of the BP neural network is determined as three neurons in a single hidden layer. LMBP algorithm is used to train the network. After 26 times of training, the network error is reduced to less than 0.001. The mean square error is shown in Figure 4.
The calibration results are shown in Figure 5. The results in Figure 5 show that the output error of the magnetometer can be effectively corrected by the BP neural network, and the accuracy of the magnetometer can be significantly improved.
The trained BP neural network can predict the real magnetic field data according to the measured value of the magnetometer by calibrating the ground model. The maximum error of the neural network calibrated by the ground model is less than 10 nT.

On Orbit Calibration Simulation
In the process of satellite on-orbit operation, due to the influence of environ- As shown in Figure 6, if the ground training model is still used for measurement, there will be errors between the real and measured data.
And the calibration error of the ground error model will reach 30 nT (as shown in Figure 6(b)). In order to reduce the influence of hourly variation on the measurement accuracy, the BP neural network is trained on-orbit by using the periodic training method. The training period of the BP neural network is set to 10 seconds, that is, BP neural network is trained every 10 seconds, and the magnetometer is recalibrated. The training process is shown in Figure 7. Figure 8(b) shows that the calibration error increases due to the change of magnetometer performance, and the on-orbit calibration using BP neural network can effectively reduce the calibration error in a training period. The error after calibration is less than 10 nT, which can significantly increase the accuracy compared to ground calibration parameters.

Conclusion
In this paper, LMBP neural network is designed for magnetometer calibration to avoid calibration error caused by the model error. The structure of the neural network is designed, and the LMBP algorithm is used to improve the training speed and convergence of the network. A periodic training method is designed to calibrate the magnetometer in orbit by collecting online data. The calibration effect of the LMBP neural network is verified by simulation. The results show that the BP neural network can improve the measurement accuracy of the magnetometer when the error model of the magnetometer is unknown. And it can effectively reduce the error caused by the change of magnetometer parameters caused by the change of space environment, and the measurement error of magnetometer can be less than 10 nT.