Skip to content
Tactiverge

✦ Estimation · recursive estimation

A one-dimensional Kalman filter

Fuse noisy thermometer readings into a steadier estimate that knows how uncertain it is.

  • Level 5 · Research Engineer
  • 4 tests
  • technically checked

Your task

A Kalman filter keeps an estimate x and its uncertainty (variance) p. For a quantity that should stay roughly constant, each new reading z updates them:

  1. predict: p = p + q (the true value may drift a little; q is process noise)
  2. gain: k = p / (p + r) (r is the sensor's noise variance)
  3. update: x = x + k × (z − x), then p = (1 − k) × p

Write kalman(readings, q, r, x0, p0) returning the estimate after each reading.

Hints (0 of 2 shown)

    What gets checked

    • kalman([1, 2, 3], 0.01, 1, 0, 1) → [0.5024875622, 1.00990099, 1.524582128]

    Plus 3 hidden tests for edge cases. They run in the sandbox like the others; only the result is shown.

    Tab indents · Esc then Tab leaves the editor · Ctrl/⌘ Enter runs · Ctrl/⌘ Shift Enter checks · Ctrl/⌘ / comments

    Starting the sandbox…

    Press Run to see what your program prints.

    Your code runs only in this browser, inside an isolated sandbox with no network access, and stops after 3 s. Nothing you type is sent to Tactiverge; drafts and progress are saved in this browser only.