【卡尔曼滤波器-Python】The g-h filter

【卡尔曼滤波器-Python】The g-h filter

The g-h filter是kalman的基本思想。通过经验值来改进测量值,达到滤波的效果。举个例子,假如有一个人有一天的重量是160斤,并且接下来每天的体重都会增加一斤,但是我们通过体重计测得的数据分别如下所示

[158.0, 164.2, 160.3, 159.9, 162.1, 164.6,169.6, 167.4, 166.4, 171.0, 171.2, 172.6]

滤波的过程如下

  1. 根据线性增长确定真实值
  2. 计算残差,真实值与测量值
  3. 根据残差的大小,在h因子的作用下确定下次增长率
  4. 根据残差的大小,在g因子的作用下确定估计值,即滤波后的结果

测试代码如下

from gh_internal import plot_g_h_results
import book_plots
import numpy as np


def g_h_filter(data,x0,dx,g,h,dt=1.,pred=None):
    x=x0
    results=[]
    for z in data:
        x_est=x+(dx*dt)
        dx=dx
        if pred is not None:
            pred.append(x_est)
        residual=z-x_est
        dx=dx+h*(residual)/dt
        x=x_est+g*residual
        results.append(x)
    return np.array(results)

weights=np.array([158.0, 164.2, 160.3, 159.9, 162.1, 164.6,
                  169.6, 167.4, 166.4, 171.0, 171.2, 172.6])
book_plots.plot_track([0, 11], [160, 172], label='Actual weight')
data = g_h_filter(data=weights, x0=160, dx=1, g=3./10, h=1./3, dt=1.)
plot_g_h_results(weights, data);

滤波结果

[1] Kalman_and_Bayesian_FIlters_in_Python
[2] https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值