https://github.com/s4k10503/kalmanfilterimplementations
An open-source collection of Kalman Filter implementations in various programming languages.
https://github.com/s4k10503/kalmanfilterimplementations
cpp csharp python3
Last synced: 2 months ago
JSON representation
An open-source collection of Kalman Filter implementations in various programming languages.
- Host: GitHub
- URL: https://github.com/s4k10503/kalmanfilterimplementations
- Owner: s4k10503
- License: mit
- Created: 2023-07-13T17:29:26.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-14T05:53:09.000Z (over 2 years ago)
- Last Synced: 2025-07-26T11:41:55.141Z (12 months ago)
- Topics: cpp, csharp, python3
- Language: C#
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Multi-Language Kalman Filter Implementations
This repository contains implementations of a Kalman filter in multiple programming languages. Currently, the following languages are supported:
- C#
- Python
- C++
Each implementation can be found in the respective directory under `src/`.
## C# Implementation
The C# implementation can be found in the `src/csharp` directory. This implementation uses the MathNet.Numerics library.
### Dependencies
The C# implementation uses the following libraries:
- [MathNet.Numerics](https://github.com/mathnet/mathnet-numerics) (MIT License)
### Usage
```csharp
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.Distributions;
// Initialize model parameters
Matrix F = ...; // State transition matrix
Matrix H = ...; // Observation matrix
Matrix B = ...; // Control matrix
Matrix x = ...; // Initial state estimate
Matrix P = ...; // Initial error covariance estimate
Matrix Q = ...; // Estimated error in process
Matrix R = ...; // Estimated error in measurements
// Create an instance of the KalmanFilter class
var kf = new KalmanFilter(F, H, B, x, P, Q, R);
// Control vector
Matrix u = ...;
// Perform the prediction step
kf.Predict(u);
// Measurement vector
Matrix z = ...;
// Perform the update step
kf.Update(z);
// Get the current state estimate
var currentState = kf.GetCurrentState();
```
Please replace the ... with appropriate data.
## Python Implementation
The Python implementation can be found in the `src/python` directory.
### Dependencies
The Python implementation uses the following libraries:
- [numpy](https://numpy.org/) (BSD License)
- [scipy](https://www.scipy.org/) (BSD License)
### Usage
```python
import numpy as np
from kalman_filter import KalmanFilter
# Initialize the Kalman Filter
F = np.array([[...]]) # State transition matrix
H = np.array([[...]]) # Observation matrix
B = np.array([[...]]) # Control matrix
x = np.array([[...]]) # Initial state estimate
P = np.array([[...]]) # Initial error covariance estimate
Q = np.array([[...]]) # Estimated error in process
R = np.array([[...]]) # Estimated error in measurement
kf = KalmanFilter(F, H, B, x, P, Q, R)
# Update the state transition matrix
dt = ... # Time step
kf.update_state_transition_matrix(dt)
# Predict the next state
u = np.array([[...]]) # Control input
kf.predict(u)
# Update the state with the observation
z = np.array([[...]]) # Observation
kf.update(z)
# Get the current state estimate
x = kf.get_current_state()
```
Please replace the ... with appropriate data.
## C++ Implementation
The C++ implementation can be found in the `src/cpp` directory.
### Dependencies
The C++ implementation uses the following libraries:
- [Eigen](http://eigen.tuxfamily.org/index.php?title=Main_Page) (MPL2 License)
- [Boost](https://www.boost.org/) (Boost Software License)
### Usage
```cpp
#include "KalmanFilter.h"
#include
#include
// Initialize model parameters
Eigen::MatrixXd F = ...; // State transition matrix
Eigen::MatrixXd B = ...; // Control matrix
Eigen::MatrixXd H = ...; // Observation matrix
Eigen::MatrixXd x = ...; // Initial state estimate
Eigen::MatrixXd P = ...; // Initial error covariance estimate
Eigen::MatrixXd Q = ...; // Estimated error in process
Eigen::MatrixXd R = ...; // Estimated error in measurements
// Create an instance of the KalmanFilter class
KalmanFilter kf(F, B, H, x, P, Q, R);
// Time step
double dt = ...;
// Update the state transition matrix
kf.update_state_transition_matrix(dt);
// Control vector
Eigen::MatrixXd u = ...;
// Perform the prediction step
kf.predict(u);
// Measurement vector
Eigen::MatrixXd z = ...;
// Perform the update step
kf.update(z);
// Get the current state estimate
Eigen::MatrixXd currentState = kf.get_current_state();
```
Please replace the ... with appropriate data.