Python通过卡尔曼滤波器实现预测
程序员文章站
2022-03-05 16:20:48
...
def update(mean1,var1,mean2,var2):
mean=(mean1*var2+mean2*var1)/(var1+var2)
var=1/(1/var1+1/var2)
return(mean,var)
def predict(mean1,var1,mean2,var2):
mean=mean1+mean2
var=var1+var2
return(mean,var)
measurements=[5.,6.,7.,9.,10.]
motion=[1.,1.,2.,1.,1.]
measurements_sig=4
motion_sig=2
mu=0.
sig=1000
for i in range(len(measurements)):
[mu,sig]=update(mu,sig,measurements[i],measurements_sig)
print("current=", [mu,sig])
[mu,sig]=predict(mu,sig,motion[i],motion_sig)
print("predict=",[mu,sig])
部分运行结果如下
上一篇: SQL
下一篇: ros学习之topic实例5