Quaternion UKF (Kraft)
Quaternion UKF (Kraft)
E. Kraft, "A Quaternion-based Unscented Kalman Filter for Orientation Tracking," Proc. 6th Int. Conf. on Information Fusion, 2003.
The problem
The state contains a unit quaternion. You can't:
- add a Gaussian offset to it (it leaves the unit sphere),
- average it as a vector (Quaternion Averaging),
- subtract two of them to get an error.
The fix: 7-D state, 6-D uncertainty
| Dim | Lives in | |
|---|---|---|
| State | 7 | |
| Error / covariance | 6 | (rotation vector + ω error) |
| Sigma points | 2·6 = 12 | state space |
| Measurement | 6 |
Every place a vector filter would use or on the quaternion uses ⊞ / ⊟ instead. → Exponential and Log Maps
| Vector UKF | Quaternion UKF |
|---|---|
| gradient-descent mean | |
Models
Process (constant angular velocity over Δt):
Left vs right errors
There are two consistent conventions. Pick one for all of sigma points, error vectors and update:
| Left (global / world-frame) | Right (local / body-frame) | |
|---|---|---|
| ⊞ | ||
| ⊟ | ||
| Yaw error is | always the world-z component | depends on attitude |
With left errors, yaw (rotation about gravity) is always the 3rd component, so the filter can keep a large, growing yaw variance while roll/pitch stay tight — exactly what the covariance plot in Results › Dataset 1 shows.
One step
flowchart TD A["q, ω, P"] --> B["S = chol(n·(P+Q))<br/>W = [S, −S]"] B --> C["X_i = [exp(W_i^rot) ⊗ q, ω + W_i^ω]"] C --> D["Y_i = [X_i^q ⊗ exp(X_i^ω Δt), X_i^ω]"] D --> E["q̄ by gradient descent, ω̄ = mean<br/>W'_i = [log(Y_i^q ⊗ q̄⁻¹), Y_i^ω − ω̄]<br/>P̄ = W'W'ᵀ/2n"] E --> F["Z_i = [Y_i^q⁻¹ ⊗ g ⊗ Y_i^q, Y_i^ω]<br/>z̄, P_vv = P_zz + R, P_xz"] F --> G["K = P_xz P_vv⁻¹<br/>δ = K(z − z̄)"] G --> H["q ← exp(δ^rot) ⊗ q̄<br/>ω ← ω̄ + δ^ω<br/>P ← P̄ − K P_vv Kᵀ"] H --> A
Code: Filter Pipeline (Code Walkthrough).
Known limitations of this formulation
- No bias states: gyro bias must be calibrated beforehand. Adding to the state (9-D error) would let the filter track slow drift.
- Accelerometer = gravity: linear acceleration is treated as noise. Fast manoeuvres → raise
r_accelor gate on . - Yaw unobservable: needs a magnetometer or vision. → IMU Sensor Models › Observability
- Q per step: depends on IMU rate;
scale_q_by_dtmakes it a per-second rate.
Related: Unscented Kalman Filter · Quaternion Averaging · Tuning Guide