FilterPy is a Python library for Kalman filtering and optimal estimation, including Kalman Filters, Extended Kalman Filters, and Unscented Kalman Filters. It provides a robust and well-documented framework for state estimation. The current version is 1.4.5, which has been stable since 2017, indicating a very mature but not actively developed codebase.
pip install filterpyVerified import paths — ran on the pinned version, not inferred.
Initializes a simple 1D Kalman Filter to track position and velocity based on position measurements. It demonstrates the setup of the KalmanFilter object, defining its core matrices (F, H, P, R, Q), and iterating through measurements using `predict()` and `update()`.
Carefully review the documentation for each matrix's required dimensions. Use `np.array` with correct shapes (e.g., `[[value]]` for 1D vectors). Ensure initial `P` is large enough to reflect uncertainty, and `Q`, `R` reflect expected noise levels.
Consult `filterpy`'s documentation on 'Choosing Q and R' and 'System Modeling'. Start with `Q_discrete_white_noise` for common scenarios and tune it based on system dynamics and expected process variation. Remember `Q` should reflect uncertainty added by the system model per time step.
Factor in the lack of ongoing maintenance when integrating into new projects or using with very recent Python versions. Test thoroughly for compatibility with your environment. Consider alternative libraries if active development, modern features, or specific performance optimizations are critical.
Install `filterpy` using pip: `pip install filterpy`. If this fails with `subprocess-exited-with-error`, try installing a known working fork: `pip install git+https://github.com/rodjjo/filterpy.git` or `python_embeded\python.exe -m pip install git+https://github.com/rodjjo/filterpy.git` for embedded environments.
Review your filter's process noise covariance (Q) and measurement noise covariance (R) matrices, ensuring they are correctly defined and positive definite. Increasing the process noise or adjusting the filter's update logic can sometimes help stabilize the covariance matrix.
Carefully check the dimensions of all matrices and vectors involved in your Kalman filter equations (e.g., `x`, `P`, `F`, `H`, `Q`, `R`, `z`). Ensure they align according to the filter's mathematical requirements, especially when initializing the filter or performing predictions and updates.