Everything here has been updated from the previous garbage code that I had for several months and never updated. Bulk of this ReadMe will be a brief summary of setting up the program and a little conceptual understanding of the ESKF. For following me on the thought process of the program archietecture and a deeper conceptual undestanding of the ESKF, it will be at the top and all around of each .cpp file in /Final_Implementation. Currently the .cpp files are being refurbished but if you wanna see the fully functional python implementation you can check /Draft_Implementation. Enjoy the work done so far.
![]() |
![]() |
![]() |
![]() |
This ESKF implementation uses quaternion representation for orientation estimation, avoiding gimbal lock issues associated with Euler angles. The filter predicts state using gyroscope and accelerometer data, then corrects the estimates using GPS data. Intuitive explanation is in filter.py comments.
State Vector (16 elements):
- Position (3D):
[x, y, z] - Orientation (quaternion):
[qw, qx, qy, qz] - Velocity (3D):
[vx, vy, vz] - Accelerometer bias:
[bax, bay, baz] - Gyroscope bias:
[bwx, bwy, bwz]
Error State (15 elements):
- Position error (3D)
- Orientation error (3D rotation vector)
- Velocity error (3D)
- Accelerometer bias error (3D)
- Gyroscope bias error (3D)
This project could not have been done without these resources (The first link is absolutely goated on general KF). The second link is for implementation. Also check out chapter 6 for implementing update step. ThreeBlueOneBrown does an absolutely amazing explanation on quaternions visualzed and somehow gives us 3d people a somewhat grasp of a 4d concept.
- Basic Kalman Filter Intuition: How a Kalman Filter Works (in Pictures)
- ESKF with Quaternions (Sections 5.1-5.4.3): Quaternion kinematics for the error-state Kalman filter
- ESKF Generalized Formulas: IEEE Paper on ESKF
- Quaternion Intuition: Visualizing Quaternions
- Jacobian Matrix Intuition: Jacobian Matrix Explained
- Extended Kalman Filter Visualization: Extended Kalman Filter Visualized
- Clone the repository:
git clone https://github.com/hyunlee8/ErrorStateKalmanFilter.git
cd ErrorStateKalmanFilter- Install required dependencies:
pip install numpy pandas pyquaternion
### Running the Filter
1. Prepare your sensor data files in the `src/` directory:
- `IMU_data.csv` - IMU sensor measurements
- `motion_data.csv` - Position/velocity measurements (optional for updates)
2. Run the filter:
```bash
cd src
python main.pyParameter Guidelines:
sig_a_noise: Set based on your accelerometer datasheet noise densitysig_w_noise: Set based on your gyroscope datasheet noise densitysig_a_walk: Accelerometer bias instability (how fast bias drifts)sig_w_walk: Gyroscope bias instability (how fast bias drifts)gravity: Local gravitational acceleration (typically 9.81 m/s²)
**One important caveat for gravity is that typically in most papers you will see that gravity is included in the error states however when computing it almost never affects the kalman gain or any other values when applied. Also it only adds unecessary complexity thus is not inluded in delta X.
- Remove biases from IMU measurements
- Transform acceleration to global frame using current orientation
- Integrate position and velocity using kinematic equations
- Update orientation via quaternion multiplication
- Propagate covariance using linearized error-state dynamics
- Compute innovation (measurement - prediction)
- Calculate Kalman gain using current covariance and measurement noise
- Update error state with innovation
- Inject error state into nominal state:
- Position: direct addition
- Orientation: quaternion multiplication
- Velocity and biases: direct addition
- Update covariance using Joseph form (numerically stable)
- Reset error state to zero



