Estimating orientation (attitude) is one of the most common Kalman filter applications: IMUs in drones, vehicles and phones, star trackers on spacecraft, AR/VR headsets. It is also one of the easiest to get wrong, because an attitude is not a vector. The multiplicative extended Kalman filter (MEKF), also known as the error-state Kalman filter for attitude, is the standard solution [1, 2].

Why the standard EKF struggles with attitude

The space of rotations has three degrees of freedom, but no three-parameter representation is globally nonsingular: Euler angles have gimbal lock, rotation vectors and Rodrigues parameters have singularities or discontinuities. The unit quaternion (four parameters) is nonsingular, but it is redundant:

  • The quaternion must satisfy \( \Vert\mathbf{q}\Vert = 1 \). An additive EKF update \( \hat{\mathbf{q}} + \mathbf{K}\boldsymbol{\nu} \) violates this constraint, and renormalizing afterwards is an ad hoc correction the covariance does not know about.
  • The \( 4\times 4 \) covariance of a unit quaternion is (to first order) singular, because there is no uncertainty along the constraint direction. Rounding errors then easily destroy positive definiteness, see failure modes.

The idea: global quaternion, local three-component error

The MEKF combines both representations:

  • the global attitude estimate is a unit quaternion \( \hat{\mathbf{q}} \) (or the attitude matrix \( \hat{\mathbf{A}} \)), which is never part of the Kalman state;
  • the Kalman filter estimates a local three-component attitude error \( \delta\boldsymbol{\theta} \), small by design, together with the other states (for example a gyro bias).

The true attitude is the product of the error and the estimate, hence “multiplicative”. Here the attitude matrix \( \mathbf{A} \) maps vectors from the reference frame to the body frame, and the error is defined as

\[ \mathbf{A} = \mathbf{A}(\delta\boldsymbol{\theta})\,\hat{\mathbf{A}}, \qquad \mathbf{A}(\delta\boldsymbol{\theta}) \approx \mathbf{I} - [\delta\boldsymbol{\theta}\times] \]

where \( [\mathbf{a}\times] \) is the cross-product matrix. The equivalent error quaternion is \( \delta\mathbf{q} \approx [1, \tfrac{1}{2}\delta\boldsymbol{\theta}^T]^T \) (scalar first). Because \( \delta\boldsymbol{\theta} \) stays small, its three-parameter representation never reaches a singularity, and its \( 3\times 3 \) covariance is full rank.

Error-state model with gyro bias

A typical state is the attitude error plus the gyro bias error, \( \delta\mathbf{x} = [\delta\boldsymbol{\theta}^T, \Delta\mathbf{b}^T]^T \). The gyro measures \( \boldsymbol{\omega}_m = \boldsymbol{\omega} + \mathbf{b} + \boldsymbol{\eta}_v \) and the bias performs a random walk, \( \dot{\mathbf{b}} = \boldsymbol{\eta}_u \).

Prediction of the global estimate. With the bias-corrected rate \( \hat{\boldsymbol{\omega}} = \boldsymbol{\omega}_m - \hat{\mathbf{b}} \) and sample time \( T \):

\[ \hat{\mathbf{A}}(k\vert k-1) = \exp\left(-[\hat{\boldsymbol{\omega}}T\times]\right)\hat{\mathbf{A}}(k-1), \qquad \hat{\mathbf{b}}(k\vert k-1) = \hat{\mathbf{b}}(k-1) \]

In quaternion form this is a multiplication with the rotation quaternion of the angle \( \Vert\hat{\boldsymbol{\omega}}\Vert T \), which preserves the unit norm.

Prediction of the error covariance. The linearized error dynamics are

\[ \delta\dot{\boldsymbol{\theta}} = -[\hat{\boldsymbol{\omega}}\times]\,\delta\boldsymbol{\theta} - \Delta\mathbf{b} - \boldsymbol{\eta}_v, \qquad \Delta\dot{\mathbf{b}} = \boldsymbol{\eta}_u , \]

i.e. \( \mathbf{F} = \begin{bmatrix} -[\hat{\boldsymbol{\omega}}\times] & -\mathbf{I} \\ \mathbf{0} & \mathbf{0} \end{bmatrix} \). After discretization, \( \mathbf{P} \) is propagated as in the EKF. The error state itself stays zero during prediction.

Measurement update with a vector observation

Many attitude sensors measure a known reference direction \( \mathbf{r} \) (gravity, magnetic field, sun or star direction) in body coordinates: \( \mathbf{y} = \mathbf{A}\mathbf{r} + \mathbf{v} \). With the predicted measurement \( \hat{\mathbf{y}} = \hat{\mathbf{A}}(k\vert k-1)\mathbf{r} \), inserting the error definition gives

\[ \mathbf{y} \approx \hat{\mathbf{y}} + [\hat{\mathbf{y}}\times]\,\delta\boldsymbol{\theta} + \mathbf{v}, \qquad \mathbf{H} = \begin{bmatrix} [\hat{\mathbf{y}}\times] & \mathbf{0}_{3\times3} \end{bmatrix} . \]

The update then follows the usual equations with the innovation \( \boldsymbol{\nu} = \mathbf{y} - \hat{\mathbf{y}} \):

\[ \mathbf{K} = \mathbf{P}(k\vert k-1)\mathbf{H}^T\left(\mathbf{H}\mathbf{P}(k\vert k-1)\mathbf{H}^T + \mathbf{R}\right)^{-1}, \qquad \delta\hat{\mathbf{x}} = \mathbf{K}\boldsymbol{\nu} \]

and the covariance update in the Joseph form. A single vector observation leaves the rotation about that vector unobservable; at least two non-parallel references (e.g. gravity and magnetic field) are needed for full attitude.

The reset step

After the update, the estimated error is moved into the global estimate and set back to zero:

\[ \hat{\mathbf{A}}(k) = \mathbf{A}(\delta\hat{\boldsymbol{\theta}})\,\hat{\mathbf{A}}(k\vert k-1), \qquad \hat{\mathbf{b}}(k) = \hat{\mathbf{b}}(k\vert k-1) + \Delta\hat{\mathbf{b}}, \qquad \delta\hat{\boldsymbol{\theta}} \leftarrow \mathbf{0} \]

In quaternion form, \( \hat{\mathbf{q}} \) is multiplied by the error quaternion of \( \delta\hat{\boldsymbol{\theta}} \) and normalized. The reset adds no information, but it changes the reference attitude in which the error, and therefore its covariance, is expressed.

Post-reset covariance. The classical MEKF keeps \( \mathbf{P} \) unchanged at the reset, which is correct to first order. Mueller, Hehn and D’Andrea [3] derived a correction that transforms the covariance into the new reference attitude. For the error convention used here, the attitude block is transformed with

\[ \mathbf{G} = \mathbf{I} - \tfrac{1}{2}[\delta\hat{\boldsymbol{\theta}}\times], \qquad \mathbf{P}_{\theta\theta} \leftarrow \mathbf{G}\,\mathbf{P}_{\theta\theta}\,\mathbf{G}^T, \qquad \mathbf{P}_{\theta b} \leftarrow \mathbf{G}\,\mathbf{P}_{\theta b} \]

and the bias block is unchanged. The correction matters when the update produces large attitude corrections, for example after initialization or long measurement outages. Later work studies the full-order reset and its effect in detail [4].

Practical tips

  • Prefer the MEKF over an additive quaternion EKF. It needs no normalization hacks and has a full-rank covariance.
  • Process vector measurements sequentially to save computation; reset once after all of them.
  • Accelerometer as gravity reference is valid only without significant linear acceleration. Gate the update with the NIS or inflate \( \mathbf{R} \) when the measured norm deviates from 1 g.
  • Sigma-point variant. The same error-state idea combined with an unscented or cubature filter gives the unscented quaternion estimator (USQUE).
  • Verify with Monte Carlo runs and the NEES of the attitude error, computed from the rotation between true and estimated attitude.

References

[1] E. J. Lefferts, F. L. Markley and M. D. Shuster (1982). “Kalman Filtering for Spacecraft Attitude Estimation”. Journal of Guidance, Control, and Dynamics, 5(5), 417–429. doi:10.2514/3.56190

[2] F. L. Markley (2003). “Attitude Error Representations for Kalman Filtering”. Journal of Guidance, Control, and Dynamics, 26(2), 311–317. doi:10.2514/2.5048

[3] M. W. Mueller, M. Hehn and R. D’Andrea (2017). “Covariance Correction Step for Kalman Filtering with an Attitude”. Journal of Guidance, Control, and Dynamics. PDF

[4] “Error-Covariance Reset in the Multiplicative Extended Kalman Filter for Attitude Estimation” (2023). Journal of Guidance, Control, and Dynamics.

[5] F. L. Markley and J. L. Crassidis (2014). Fundamentals of Spacecraft Attitude Determination and Control. Springer.

[6] J. Solà (2017). “Quaternion kinematics for the error-state Kalman filter”. arXiv:1711.02508.

Newsletter