Kalman卡尔曼滤波

步骤:
1、计算y=20e0.24x计算出x 在0.1~4区间内的y值作为真值:Y

2、在 Y 的基础上加入一个高斯分布的误差作为观测量,观测量:Y_OBS;

3、初始化P、Q、R矩阵,P代表初始状态精度,Q代表预测精度,R观测精度;

4、初始化状态值 state、结果存储空间 Y_reselt ,协方差存储空间 P_reselt.

# step 1
X = np.arange(0.1,4,0.01)
Y = 20 * np.exp(0.24*X)
# step  2
rand_error = 2
Y_obs = Y + rand_error * (2* np.random.random(len(X))-1)
# step  3
Q = 0.1
R = 5
P = 1
# step 4
state = 20
Y_reselt = np.zeros(len(X))
P_reselt = np.zeros(len(X))

Y_reselt[0] = state
P_reselt[0] = P

for i in range(1,len(X)):
    P = P + Q
    K = P / (P + R)
    state = state + K * (Y_obs[i]-state)
    P = (1-K) * P 
    P_reselt[i] = P 
    Y_reselt[i] = state


plt.plot(X,Y_obs,label = 'Noisy Signal')
plt.plot(X,Y_reselt,label = 'Estimated Signal')

plt.legend()
plt.show()

posted @   华小电  阅读(23)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
点击右上角即可分享
微信分享提示