Calculator
Example data table
A small 1D example showing measurements and filtered estimates.
| Step | Measurement z | Suggested Q | Suggested R | Comment |
|---|---|---|---|---|
| 1 | 0.70 | 0.01 | 0.09 | Start with moderate uncertainty. |
| 2 | 0.90 | 0.01 | 0.09 | Filter begins to track trend. |
| 3 | 1.10 | 0.01 | 0.09 | Residual shrinks as P updates. |
| 4 | 0.95 | 0.01 | 0.09 | Update balances model and sensor. |
Load the example inputs using the Load example button above.
Formula used
This estimator assumes a linear, discrete-time model:
- xₖ = A xₖ₋₁ + B uₖ + wₖ, with process noise covariance Q
- zₖ = H xₖ + vₖ, with measurement noise covariance R
Prediction:
- x⁻ₖ = A xₖ₋₁ + B uₖ
- P⁻ₖ = A Pₖ₋₁ Aᵀ + Q
Update:
- yₖ = zₖ − H x⁻ₖ (innovation / residual)
- Sₖ = H P⁻ₖ Hᵀ + R (innovation covariance)
- Kₖ = P⁻ₖ Hᵀ Sₖ⁻¹ (Kalman gain)
- xₖ = x⁻ₖ + Kₖ yₖ
- Pₖ = (I − Kₖ H) P⁻ₖ
How to use this calculator
- Choose Matrix for multi-variable systems, or Scalar for 1D.
- Enter A, H, and noise covariances Q, R.
- Provide x0 and P0 to set initial uncertainty.
- Add one measurement vector per line in z.
- Optionally add control vectors in u and matrix B.
- Press Estimate to view stepwise results and download files.
Technical notes for laboratory tracking
1) What this estimator is designed to do
This tool implements a discrete, linear estimator that blends a predictive model with noisy observations. In physics labs, it is commonly used to recover position, velocity, or slowly drifting parameters from sensors that fluctuate around the true signal. The output includes prediction, residual, gain, and covariance at every step.
2) Typical measurement noise magnitudes
A practical way to initialize R is to start from known sensor statistics. For example, a benchtop optical encoder might show a standard deviation near 0.02–0.10 mm, while a low-cost ultrasonic range sensor can wander by 5–20 mm. If R is too small, the estimate will chase noise and the residual will oscillate.
3) Process noise is not “error,” it is uncertainty
The Q matrix represents unmodeled physics: friction changes, unmeasured forces, temperature drift, or discretization mismatch. As a rule of thumb, increasing Q by 10× often makes the filter respond faster, while decreasing it by 10× makes the output smoother but slower to adapt. Use units consistent with the state definition.
4) Time step and model scaling
If you are modeling constant velocity in 1D, a common two-state form uses A = [[1, Δt],[0,1]]. When Δt changes from 0.01 s (100 Hz) to 0.10 s (10 Hz), both the dynamics and the implied uncertainty scale. Recompute A and consider scaling Q with Δt to avoid overconfidence.
5) Reading the Kalman gain like a dial
The gain K controls how strongly the estimator moves toward the new measurement. Values near 0 mean the prediction dominates; values near 1 (in 1D) mean the observation dominates. In multi-state systems, large gain entries typically appear where H directly observes that state or a strongly coupled combination.
6) Covariance provides a built-in quality metric
Track the diagonal of P to see uncertainty shrink during good measurements and grow during poor observability. If P collapses unrealistically, Q is often too small. If it grows without bound, the model or H may be inconsistent with the data stream.
7) Using multiple sensors
To fuse two sensors in the same time step, stack them into a single measurement vector and expand H and R accordingly. Example: position from a camera (σ≈0.5 mm) and from an encoder (σ≈0.05 mm) can be combined by setting a diagonal R with variances 0.25 and 0.0025 (in mm²).
8) A tuning workflow that converges quickly
Start with a realistic R from sensor repeatability. Set P0 large enough to admit uncertainty, then increase Q until the residual becomes approximately white (no obvious correlation). Use the step table and downloads to compare runs across different noise settings and sampling rates.
FAQs
1) What should I enter for Q and R if I do not know them?
Start with R from sensor repeatability (variance), then set Q one to two orders smaller. Increase Q if the estimate lags, or increase R if it follows noise.
2) Why does the estimate jump on the first few steps?
Early updates often correct an uncertain initial state. If P0 is large, the gain becomes larger and the estimator trusts measurements more strongly. After several steps, P stabilizes and the jumps usually reduce.
3) My matrix input fails. What format is required?
Use one row per line and separate values by spaces or commas. Example: a 2×2 matrix can be written as “1 0.1” on the first line and “0 1” on the second line. Vectors must be n×1.
4) What does the residual mean physically?
The residual is z − Hx⁻, the difference between what you measured and what the model predicted you would measure. Large residuals indicate unexpected motion, transient disturbances, or under-modeled dynamics that may require a larger Q.
5) When should I use the control input term Bu?
Use it when you have a known actuation or forcing signal, such as applied voltage, commanded acceleration, or known impulses. If you do not have a reliable input, leave B blank and the estimator will rely on the state dynamics and measurements.
6) The gain looks “too small.” Is that bad?
Not necessarily. Small gain means the model is trusted more than the measurement, commonly because R is large or P is small. If you still track real changes well, small gain can be desirable for noise suppression.
7) What is the fastest way to validate my model?
Run a short dataset and inspect whether residuals stay centered near zero without long trends. If residuals drift, A or H may be wrong. If residuals spike frequently, reassess R or increase Q.