For people new to Kalman filters, they're well explained here https://www.youtube.com/watch?v=IFeCIbljreY (credit for the above image)
Maintained by George Pearse, Lead MLE at Visia
This is the fork of the original and excellent filterpy (https://github.com/rlabbe/filterpy), only forked because of the pull requests left without response for essential upgrades to packaging to support python 3.12+ and the coming deprecation in setuptools. etc. 99% of the functionality remains identical, but I'm adding testing and typing etc. so that the repo is ready for lower cost upgrades.
This library provides Kalman filtering and various related optimal and non-optimal filtering software written in Python. It contains Kalman filters, Extended Kalman filters, Unscented Kalman filters, Kalman smoothers, Least Squares filters, fading memory filters, g-h filters, discrete Bayes, and more.
This is a comprehensive implementation of Kalman filters and related estimation algorithms in Python.
All computations use NumPy and SciPy.
Documentation is available at https://georgepearse.github.io/bayesian_filters
uv pip install bayesian-filtersimport numpy as np
import bayesian_filters as bf
# Or import specific modules
from bayesian_filters.kalman import KalmanFilter
from bayesian_filters.common import Q_discrete_white_noisemy_filter = KalmanFilter(dim_x=2, dim_z=1)my_filter.x = np.array([[2.],
[0.]]) # initial state (location and velocity)
my_filter.F = np.array([[1.,1.],
[0.,1.]]) # state transition matrix
my_filter.H = np.array([[1.,0.]]) # Measurement function
my_filter.P *= 1000. # covariance matrix
my_filter.R = 5 # state uncertainty
my_filter.Q = Q_discrete_white_noise(dim=2, dt=0.1, var=0.1) # process uncertaintywhile True:
my_filter.predict()
my_filter.update(get_some_measurement())
# do something with the output
x = my_filter.x
do_something_amazing(x)The library is broken up into subdirectories:
gh- g-h filterskalman- Kalman filters (KF, EKF, UKF, etc.)memory- fading memory filtersleastsq- least squares filtersdiscrete_bayes- discrete Bayes filtersstats- statistical functionscommon- common helper functions
Each subdirectory contains Python files relating to that form of filter. The functions and methods contain comprehensive docstrings.
This library requires:
- Python 3.10+
- NumPy
- SciPy
- Matplotlib
All tests are written to work with pytest. Just run:
pytestThe tests include both unit tests and visual verification. Visual plots are often the best way to see how filters are working, as it's easy for a filter to perform within theoretical limits yet be 'off' in some way.
The original author uses three main reference texts:
-
Paul Zarchan's 'Fundamentals of Kalman Filtering: A Practical Approach' - Excellent for practical applications rather than theoretical thesis work.
-
Eli Brookner's 'Tracking and Kalman Filtering Made Easy' - An astonishingly good book with its first chapter readable by laypeople. Brookner starts from the g-h filter and shows how all other filters derive from it, including Kalman filters, least squares, and fading memory filters. Also focuses on practical issues like track initialization, noise detection, and tracking multiple objects.
-
Bar-Shalom's 'Estimation with Applications to Tracking and Navigation' - More mathematical than the previous two. Recommended after gaining some background in control theory or optimal estimation. Every sentence is crystal clear with precise language, and abstract mathematical statements are followed with practical explanations.
- Kalman Filter Background - Comprehensive background and theory on Kalman filtering
- Gavin-Furtado/Kalman-Filter-Simulator - Python project simulating sensor tracking with state estimation
- sparshgarg23/object-detection-and-tracking - Object detection pipeline with OpenCV and FilterPy-based Kalman filters
- Norfair - Lightweight Python library for real-time multi-object tracking using Kalman filters
- GitHub Topic: filterpy - Projects tagged with "filterpy" covering robotics, tracking, and sensor fusion applications
- mintisan/awesome-kalman-filter - Curated list of Kalman filter implementations, tutorials, and resources
The MIT License (MIT)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
