# Nanosatellite Autonomous Navigation via Extreme Learning Machine Using Magnetometer Measurements
## 2 Methodology
### Extended Kalman Filter  
The Extended Kalman Filter (EKF) [12; 13] is a model-based, non-linear algorithm developed in the early 1960s [5]. The quality of its performance is strictly linked to the knowledge of the underlying dynamics and to the goodness of model assumptions. Here, the state vector \(\mathbf{x}_{k}\) in the \(k\)-th time step is represented by the position and the velocity of the spacecraft in an Earth-Centered Inertial (ECI) reference frame,  
\[\mathbf{x}_{k}=[x,y,z,v_{x},v_{y},v_{z}], \tag{1}\]  
while the observation vector \(\mathbf{o}_{k}\) is either given by the components of the geomagnetic field \(B_{x}\), \(B_{y}\), \(B_{z}\),  
\[\mathbf{o}_{k}^{B}=[B_{x},B_{y},B_{z}], \tag{2}\]  
or by the GPS signal received by the spacecraft \(GPS_{x}\), \(GPS_{y}\), \(GPS_{z}\),  
\[\mathbf{o}_{k}^{GPS}=[GPS_{x},GPS_{y},GPS_{z}]. \tag{3}\]  
On the other hand, the observation vector is taken as a non-linear function, \(z\), of the state plus a zero-mean random process, \(\mathbf{v}\):  
\[\mathbf{o}=z(\mathbf{x})+\mathbf{v} \tag{4}\]  
The time evolution of the state, instead, is a non-linear function, \(f\), of the state plus another zero-mean random process, \(\mathbf{u}\):  
\[\dot{\mathbf{x}}=f(\mathbf{x})+\mathbf{u}. \tag{5}\]  
The new state estimate \(\hat{\mathbf{x}}_{k}\) is given by the following equation according to the EKF theory:  
\[\hat{\mathbf{x}}_{k}=\bar{\mathbf{x}}_{k}+\mathbf{K}_{k}[\mathbf{o}_{k}-z(\bar{\mathbf{x}}_{k} )], \tag{6}\]  
where \(\bar{\mathbf{x}}_{k}\) is the state prediction, \(\mathbf{K}\) indicates the _Kalman gain_ matrix [18], and \([\mathbf{o}_{k}-z(\bar{\mathbf{x}}_{k})]\) is the residual: the difference between the actual measurement and the non-linear measurement prediction. In the case of discrete measurements, Equation (4) can be rewritten as  
\[\mathbf{o}_{k}=z(\mathbf{x}_{k})+\mathbf{v}_{k}. \tag{7}\]  
To compute the Kalman gain matrix \(\mathbf{K}\), a first-order approximation is used for the system dynamics matrix \(\mathbf{F}\) and the measurement matrix \(\mathbf{Z}\) since Equations (4) and (5) are non-linear. The relations between these matrices and the previous equations are  
\[\mathbf{F}_{k}=\frac{\partial f(\mathbf{x})}{\partial\mathbf{x}}\Big{|}_{\mathbf{x}=\hat {\mathbf{x}}_{k}} \tag{8}\]  
and  
\[\mathbf{Z}_{k}=\frac{\partial z(\mathbf{x})}{\partial\mathbf{x}}\Big{|}_{\mathbf{x}=\hat {\mathbf{x}}_{k}} \tag{9}\]  
The Kalman gain matrix can be computed from the Riccati equations, a set of recursive matrix equations given by [18]:\[\mathbf{M}_{k}=\Phi_{k-1}\mathbf{P}_{k-1}\Phi_{k-1}^{T}+\mathbf{Q}_{k} \tag{10}\] \[\mathbf{o}_{k}^{B}=[B_{x},B_{y},B_{z}], \tag{2}\]0 (11) \[\mathbf{o}_{k}^{B}=[B_{x},B_{y},B_{z}], \tag{2}\]1  
where \(\Phi_{k-1}\) is the _fundamental matrix_ and can be approximated by the first two terms of the Taylor-series expansion of \(e^{\mathbf{F}_{k-1}T_{s}}\): \(\mathbf{\Phi}_{k}\simeq I+\mathbf{F}_{k-1}\mathbf{T}_{s}\), with \(T_{s}\) being the sampling time interval. The discrete process-noise matrix \(\mathbf{Q}_{k}\) can be computed as  
\[\mathbf{o}_{k}^{B}=[B_{x},B_{y},B_{z}], \tag{2}\]2  
where \(\mathbf{\Phi}_{k-1}(\tau)=\simeq I+\mathbf{F}_{k-1}\tau\). Finally, the state prediction is given by  
\[\mathbf{o}_{k}^{B}=[B_{x},B_{y},B_{z}], \tag{2}\]3  
However, in the EKF, the state can be directly propagated forward by integrating the actual nonlinear differential equations in each sampling interval. In this work, \(f(x)\) is the state-dynamics function, including the \(J_{2}\) perturbation, and \(z(x)\) is the implemented pyIGRF [17] module to evaluate the magnetic field as a function of the position and time for the magnetometer-based EKFs, from which the matrix \(\mathbf{Z}_{B}\) is computed numerically. On the other hand, the matrix \(\mathbf{F}\) is obtained by deriving \(f(x)\) analytically. For the GPS-based EKF, the measurement function is  
\[\mathbf{Z}_{GPS}= \begin{bmatrix}1&0&0&0&0\\ 0&1&0&0&0\\ 0&0&1&0&0\end{bmatrix}