Skip to content
DeepForgeby svx
All problems
EasyTime Seriests-047

Kalman Filter 1D Update

Problem

Perform the measurement update of a one-dimensional Kalman filter. Given the prior mean and variance, an observation, and the observation noise variance r, compute K = p / (p + r), then the posterior mean prior + K * (obs - prior) and posterior variance (1 - K) * p.

Return [posterior_mean, posterior_variance].

Hint

The posterior variance is always smaller than the prior variance.

Test cases

case 1
in: [10,2,12,2]
expected: [11,1]
case 2
in: [0,1,1,1]
expected: [0.5,0.5]
case 3
in: [5,2,5,3]
expected: [5,1.2]
case 4
in: [0,0,10,1]
expected: [0,0]
Starter codePython
def kalman_update(prior, p_prior, obs, r):
    # Your code here
    pass

4 test cases · run your code against them in the editor