python 中的卡尔曼平滑器

Kalman smoother in python

我的数据

1    14.7
2    14.58
3    14.82
4    14.59
5    14.67
...  ...
150  13.76

我已经画了图和 upper/lower 包络线。 接下来,我想对 u/l 包络线应用卡尔曼平滑器。 卡尔曼平滑器有合适的例子吗??

这是我的内核过滤器实现,在我的数据上运行良好。此代码是基于 https://www.kalmanfilter.net/kalman1d.html 编写的,希望对您有所帮助。

def kalmanfilter(x,p,z,r):
    # p - estimate unceratininty 
    # r - measurement unceratininty ( σ2 )  
    # z - Measured System State

    # Kalman gain calculation
    K =  p/(p+r)
    # estimate current state
    x1 = x + K*(z-x)
    # update current estimate uncertainity
    p1 = (1-K)*p

    return (x1,p1)