The science
Constant-velocity Kalman filter (Kalman 1960). State x = [v, a] with v the road-segment mean speed and a its trend; F = [[1,T],[0,1]], H = [1 0]. Process noise is the white-noise-acceleration model Q = q·[[T³/3, T²/2],[T²/2, T]], so ten 0.1 s predictions compose exactly into one 1 s prediction. The covariance update uses the Joseph form, which stays symmetric and positive semi-definite.
Simplifications: the hidden road speed here is a mean-reverting process pushed by congestion pulses, not a CV system, so the filter is deliberately slightly mismatched (as in real life): NIS runs above 1 during jams. Cars are drawn denser when the true speed drops (flow = density × speed) but their count is a visual proxy, not a car-following model. Sensor noise is Gaussian and unbiased; real loop/radar data have outliers and bias.
State x = [speed, trend]. Every tick runs the real predict step x⁻=Fx, P⁻=FPFᵀ+Q. Each sensor reading runs the real update step: K=P⁻Hᵀ(HP⁻Hᵀ+R)⁻¹, x=x⁻+K(z−Hx⁻), P=(I−KH)P⁻(I−KH)ᵀ+KRKᵀ (Joseph form). Watch P₀₀ shrink on every update and grow during the predict-only gaps, especially during a sensor dropout.