{"id":2949,"library":"filterpy","title":"FilterPy: Kalman Filtering and Optimal Estimation","description":"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.","status":"active","version":"1.4.5","language":"en","source_language":"en","source_url":"https://github.com/rlabbe/filterpy","tags":["kalman filter","state estimation","control systems","sensor fusion","optimal estimation"],"install":[{"cmd":"pip install filterpy","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Essential for numerical operations and matrix algebra.","package":"numpy","optional":false},{"reason":"Required for certain advanced scientific computing functions, though primarily relies on NumPy.","package":"scipy","optional":false}],"imports":[{"symbol":"KalmanFilter","correct":"from filterpy.kalman import KalmanFilter"},{"symbol":"ExtendedKalmanFilter","correct":"from filterpy.kalman import ExtendedKalmanFilter"},{"symbol":"UnscentedKalmanFilter","correct":"from filterpy.kalman import UnscentedKalmanFilter"},{"note":"A helper function for common process noise covariance matrices.","symbol":"Q_discrete_white_noise","correct":"from filterpy.common import Q_discrete_white_noise"}],"quickstart":{"code":"import numpy as np\nfrom filterpy.kalman import KalmanFilter\n\n# Create a KalmanFilter object\nkf = KalmanFilter(dim_x=2, dim_z=1)\n\n# Initialize state vector x (position, velocity)\nkf.x = np.array([[0.], [0.]])\n\n# State transition matrix F\nkf.F = np.array([[1., 1.],\n                 [0., 1.]])\n\n# Measurement function H\nkf.H = np.array([[1., 0.]])\n\n# State covariance matrix P\nkf.P *= 1000.\n\n# Measurement noise covariance R\nkf.R = 5 # Measurement noise\n\n# Process noise covariance Q\nkf.Q = np.diag([0.01, 0.01]) # Simple process noise\n\n# Simulate some measurements\nz = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])\n\n# Run the filter\nestimates = []\nfor measurement in z:\n    kf.predict()\n    kf.update(measurement)\n    estimates.append(kf.x.T[0].tolist())\n\n# print(estimates)\n# Expected output for first few: [[...], [...]]\n","lang":"python","description":"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()`."},"warnings":[{"fix":"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.","message":"Incorrect matrix dimensions or initialization for state vector (x), covariance matrices (P, Q, R) are very common. This leads to `ValueError` during matrix operations or, more subtly, poor filter performance and divergence. Ensure `dim_x`, `dim_z` match your matrix shapes.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"Defining the process noise covariance matrix (Q) is often challenging and misunderstood. An inappropriate `Q` can lead to filter divergence or sluggish response. While the library provides `Q_discrete_white_noise`, users often use overly simplistic or incorrect `Q` matrices.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"FilterPy version 1.4.5 has not been updated since 2017. While functional and stable, it is not actively maintained. This means no new features, bug fixes for new Python versions/dependencies, or performance improvements are expected. Users should be aware of this for long-term project planning.","severity":"gotcha","affected_versions":"1.4.5+"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}