4 概率机器人 Probabilistic Robotics 扩展卡尔曼滤波算法

    科技2022-07-11  98

    文章目录

    1 前提介绍2 通过泰勒展式进行线性化3 扩展卡尔曼滤波算法(EKF)4 扩展卡尔曼滤波实例5 扩展卡尔曼滤波(EKF)公式推导5.1 预测公式推导5.2 测量更新公式推导 6 扩展卡尔曼滤波的优缺点7 参考文献

    1 前提介绍

    扩展卡尔曼滤波顾名思义是卡尔曼滤波的扩展形式(卡尔曼滤波教程),但是在哪些方面进行扩展呢?这就要从卡尔曼滤波的三个前提条件入手: 状态转移函数必须是线性函数: x t = A t x t − 1 + B t u t + ϵ t x_t = A_t x_{t-1} + B_t u_t + \epsilon_t xt=Atxt1+Btut+ϵt测量函数必须是线性函数: z t = C t x t + δ t z_t = C_t x_t + \delta_t zt=Ctxt+δt初始的置信度函数服从正态分布: b ( x 0 ) ∼ N ( μ 0 , Σ 0 ) b(x_0) \sim N(\mu_0, \Sigma_0) b(x0)N(μ0,Σ0) 扩展卡尔曼滤波对第 1 , 2 1,2 1,2个前提条件进行扩展: 状态转移函数不必是线性函数 x t = g ( u t , x t − 1 ) + ϵ t x_t = g(u_t, x_{t-1}) + \epsilon_t xt=g(ut,xt1)+ϵt测量函数必须不必是线性函数: z t = h ( x t ) + δ t z_t = h(x_t) + \delta_t zt=h(xt)+δt X X X服从正态分布 X ∼ N ( x ; μ , σ 2 ) X \sim N(x;\mu, \sigma^2) XN(x;μ,σ2),那么变换后的变量 Y Y Y服从怎样的分布? 线性变换 Y = a X + b Y=aX+b Y=aX+b,那么变量 Y Y Y也服从正态分布 Y ∼ N ( y ; a μ + b , a 2 σ 2 ) Y \sim N(y;a\mu+b, a^2\sigma^2) YN(y;aμ+b,a2σ2)

    非线性变换 Y = g ( X ) Y = g(X) Y=g(X),那么变量 Y Y Y将不再服从正态分布,且解析形式很难求得

    扩展卡尔曼滤波与卡尔曼滤波状态转移函数和测量函数对比: 用函数 g g g代替矩阵 A t , B t A_t,B_t At,Bt用函数 h h h代替矩阵 C t C_t Ct 对于任意函数 g , h g,h g,h将会导致置信度 b e l ( x ) bel(x) bel(x)不再服从正态分布,那么置信度更新将不再存在封闭解,换句话说贝叶斯滤波将不能进行那么为了克服上述问题,只能退而求其次,采用将上述两个非线性函数 g , h g,h g,h进行线性化

    2 通过泰勒展式进行线性化

    泰勒展开式与线性化: 在 x = a 出泰勒展开形式: f ( x ) = f ( a ) + f ′ ( a ) 1 ! ( x − a ) + f ( 2 ) ( a ) 2 ! ( x − a ) 2 + ⋯ + f ( n ) ( a ) n ! ( x − a ) n + ⋯ ↓ 仅保留线性部分 f ( x ) ≈ f ( a ) + f ′ ( a ) 1 ! ( x − a ) \text{在}x=a\text{出泰勒展开形式:}\\ f(x) = f(a) + \frac{f'(a)}{1!}(x-a) + \frac{f^{(2)}(a)}{2!}(x-a)^2 + \cdots + \frac{f^{(n)}(a)}{n!}(x-a)^n + \cdots \\ \downarrow \text{仅保留线性部分}\\ f(x) \approx f(a) + \frac{f'(a)}{1!}(x-a) x=a出泰勒展开形式:f(x)=f(a)+1!f(a)(xa)+2!f(2)(a)(xa)2++n!f(n)(a)(xa)n+仅保留线性部分f(x)f(a)+1!f(a)(xa)如果 X X X服从正态分布 X ∼ N ( x ; μ , σ 2 ) X \sim N(x; \mu, \sigma^2) XN(x;μ,σ2) g ( x ) g(x) g(x)是非线性函数,那么为了线性化 g ( x ) g(x) g(x),应该在什么位置对 g ( x ) g(x) g(x)进行一阶泰勒展开呢? 答案是应该在 X X X的均值出进行展开 ( x = μ ) (x=\mu) (x=μ)这是因为 x x x等于均值 μ \mu μ的概率最大变换如下图: 右下角为 X X X服从正态分布 X ∼ N ( x ; μ , σ 2 ) X \sim N(x; \mu, \sigma^2) XN(x;μ,σ2) x x x等于均值 μ \mu μ的概率最大(峰值)右上角为对 x x x进行非线性变换 g ( x ) g(x) g(x),虚线是在 x = μ x=\mu x=μ处的一阶泰勒展开式,用来近似实线部分左上角虚线为通过线性化 g ( x ) g(x) g(x),求得的 g ( x ) g(x) g(x)的概率分布;实线为实际的概率分布,可见误差在允许的范围内

    线性化状态转移函数 x t = g ( u t , x t − 1 ) + ϵ t x_t = g(u_t, x_{t-1}) + \epsilon_t xt=g(ut,xt1)+ϵt 对于高斯分布,后验概率 μ t − 1 \mu_{t-1} μt1是状态变量 x t − 1 x_{t-1} xt1最可能的状态所以对 x t = g ( u t , x t − 1 ) + ϵ t x_t = g(u_t, x_{t-1}) + \epsilon_t xt=g(ut,xt1)+ϵt μ t − 1 \mu_{t-1} μt1处展开(即 a = μ t − 1 a=\mu_{t-1} a=μt1) g ( u t , x t − 1 ) ≈ g ( u t , μ t − 1 ) + g ′ ( u t , μ t − 1 ) ( x t − 1 − μ t − 1 ) ↓ 定义: G t : = g ′ ( u t , μ t − 1 )    雅克比矩阵 g ( u t , x t − 1 ) ≈ g ( u t , μ t − 1 ) + G t ( x t − 1 − μ t − 1 ) ↓ x t ≈ g ( u t , μ t − 1 ) + G t ( x t − 1 − μ t − 1 ) + ϵ t ↓ x t ∼ N ( x t ; g ( u t , μ t − 1 ) + G t ( x t − 1 − μ t − 1 ) , R t ) ↓ p ( x t ∣ u t , x t − 1 ) = d e t ( 2 π R t ) − 1 2 exp ⁡ { − 1 2 ( x t − g ( u t , μ t − 1 ) − G t ( x t − 1 − μ t − 1 ) ) T R t − 1 ( x t − g ( u t , μ t − 1 ) − G t ( x t − 1 − μ t − 1 ) ) } 雅克比矩阵: G t = g ′ ( u t , μ t − 1 ) = [ ∂ g 1 ∂ x 1 ∂ g 1 ∂ x 2 ⋯ ∂ g 1 ∂ x n ∂ g 2 ∂ x 1 ∂ g 2 ∂ x 2 ⋯ ∂ g 2 ∂ x n ⋮ ⋮ ⋮ ⋮ ∂ g n ∂ x 1 ∂ g n ∂ x 2 ⋯ ∂ g n ∂ x n ] x t − 1 = μ t − 1 g(u_t, x_{t-1}) \approx g(u_t, \mu_{t-1}) + g'(u_t, \mu_{t-1})(x_{t-1} - \mu_{t-1})\\ \downarrow \text{定义:}G_t := g'(u_t, \mu_{t-1})~~~\text{雅克比矩阵}\\ g(u_t, x_{t-1}) \approx g(u_t, \mu_{t-1}) + G_t(x_{t-1} - \mu_{t-1})\\ \downarrow \\ x_t \approx g(u_t, \mu_{t-1}) + G_t(x_{t-1} - \mu_{t-1}) + \epsilon_t\\ \downarrow \\ x_t \sim N(x_t; g(u_t, \mu_{t-1}) + G_t(x_{t-1} - \mu_{t-1}), R_t)\\ \downarrow \\ \begin{aligned} &p(x_t|u_t,x_{t-1})\\ &= det(2\pi R_t)^{-\frac{1}{2}}\exp\left \{ -\frac{1}{2} (x_t-g(u_t, \mu_{t-1}) - G_t(x_{t-1} - \mu_{t-1}))^T R_t^{-1}(x_t-g(u_t, \mu_{t-1}) - G_t(x_{t-1} - \mu_{t-1}))\right \} \end{aligned}\\ \text{雅克比矩阵:} G_t = g'(u_t, \mu_{t-1}) = \begin{bmatrix} \frac{\partial g_1}{\partial x_1}& \frac{\partial g_1}{\partial x_2}& \cdots& \frac{\partial g_1}{\partial x_n} \\ \frac{\partial g_2}{\partial x_1}& \frac{\partial g_2}{\partial x_2}& \cdots& \frac{\partial g_2}{\partial x_n} \\ \vdots & \vdots & \vdots & \vdots \\ \frac{\partial g_n}{\partial x_1}& \frac{\partial g_n}{\partial x_2}& \cdots& \frac{\partial g_n}{\partial x_n} \\ \end{bmatrix}_{x_{t-1}=\mu_{t-1}} g(ut,xt1)g(ut,μt1)+g(ut,μt1)(xt1μt1)定义:Gt:=g(ut,μt1)   雅克比矩阵g(ut,xt1)g(ut,μt1)+Gt(xt1μt1)xtg(ut,μt1)+Gt(xt1μt1)+ϵtxtN(xt;g(ut,μt1)+Gt(xt1μt1),Rt)p(xtut,xt1)=det(2πRt)21exp{21(xtg(ut,μt1)Gt(xt1μt1))TRt1(xtg(ut,μt1)Gt(xt1μt1))}雅克比矩阵:Gt=g(ut,μt1)=x1g1x1g2x1gnx2g1x2g2x2gnxng1xng2xngnxt1=μt1 线性化测量函数: z t = h ( x t ) + δ t z_t = h(x_t) + \delta_t zt=h(xt)+δt 对于高斯分布, μ ˉ t \bar{\mu}_{t} μˉt是状态变量 x t x_{t} xt最可能的状态所以对 z t = h ( x t ) + δ t z_t = h(x_t) + \delta_t zt=h(xt)+δt μ ˉ t \bar{\mu}_{t} μˉt处展开(即 a = μ ˉ t a=\bar{\mu}_{t} a=μˉt) h ( x t ) ≈ h ( μ ˉ t ) + h ′ ( μ ˉ t ) ( x t − μ ˉ t ) ↓ 定义: H t : = h ′ ( μ ˉ t ) = ∂ h ( x t ) ∂ x t ∣ x t = μ ˉ t    雅克比矩阵 ↓ z t ≈ h ( μ ˉ t ) + H t ( x t − μ ˉ t ) + δ t ↓ z t ∼ N ( z t ; h ( μ ˉ t ) + H t ( x t − μ ˉ t ) , Q t ) ↓ p ( z t ∣ x t ) = d e t ( 2 π Q t ) − 1 2 exp ⁡ { − 1 2 ( z t − h ( μ ˉ t ) − H t ( x t − μ ˉ t ) ) T Q t − 1 ( z t − h ( μ ˉ t ) − H t ( x t − μ ˉ t ) ) } 雅克比矩阵: H t = h ′ ( μ ˉ t ) = [ ∂ h 1 ∂ x 1 ∂ h 1 ∂ x 2 ⋯ ∂ h 1 ∂ x n ∂ h 2 ∂ x 1 ∂ h 2 ∂ x 2 ⋯ ∂ h 2 ∂ x n ⋮ ⋮ ⋮ ⋮ ∂ h n ∂ x 1 ∂ h n ∂ x 2 ⋯ ∂ h n ∂ x n ] x t = μ ˉ t h(x_t) \approx h(\bar{\mu}_{t}) + h'(\bar{\mu}_{t})(x_t - \bar{\mu}_{t})\\ \downarrow \text{定义:}H_t := h'(\bar{\mu}_{t})=\frac{\partial h(x_t)}{\partial x_t}|_{x_t = \bar{\mu}_{t}}~~~\text{雅克比矩阵}\\ \downarrow \\ z_t \approx h(\bar{\mu}_{t}) + H_t(x_t - \bar{\mu}_{t}) + \delta_t\\ \downarrow \\ z_t \sim N(z_t; h(\bar{\mu}_{t}) + H_t(x_t - \bar{\mu}_{t}), Q_t)\\ \downarrow \\ \begin{aligned} &p(z_t|x_t)\\ &= det(2\pi Q_t)^{-\frac{1}{2}}\exp\left \{ -\frac{1}{2} (z_t-h(\bar{\mu}_{t}) - H_t(x_t - \bar{\mu}_{t}))^T Q_t^{-1}(z_t-h(\bar{\mu}_{t}) - H_t(x_t - \bar{\mu}_{t}))\right \} \end{aligned}\\ \text{雅克比矩阵:} H_t = h'(\bar{\mu}_{t})= \begin{bmatrix} \frac{\partial h_1}{\partial x_1}& \frac{\partial h_1}{\partial x_2}& \cdots& \frac{\partial h_1}{\partial x_n} \\ \frac{\partial h_2}{\partial x_1}& \frac{\partial h_2}{\partial x_2}& \cdots& \frac{\partial h_2}{\partial x_n} \\ \vdots & \vdots & \vdots & \vdots \\ \frac{\partial h_n}{\partial x_1}& \frac{\partial h_n}{\partial x_2}& \cdots& \frac{\partial h_n}{\partial x_n} \\ \end{bmatrix}_{x_{t}=\bar{\mu}_{t}} h(xt)h(μˉt)+h(μˉt)(xtμˉt)定义:Ht:=h(μˉt)=xth(xt)xt=μˉt   雅克比矩阵zth(μˉt)+Ht(xtμˉt)+δtztN(zt;h(μˉt)+Ht(xtμˉt),Qt)p(ztxt)=det(2πQt)21exp{21(zth(μˉt)Ht(xtμˉt))TQt1(zth(μˉt)Ht(xtμˉt))}雅克比矩阵:Ht=h(μˉt)=x1h1x1h2x1hnx2h1x2h2x2hnxnh1xnh2xnhnxt=μˉt

    3 扩展卡尔曼滤波算法(EKF)

    通过上一部分对状态转移函数和观测函数的线性化,使得这两个函数用两个线性函数表示,使得置信度 b e l ( x t ) bel(x_t) bel(xt)还服从正态分布这里先给出扩展卡尔曼滤波算法,并与卡尔曼滤波进行对比,具体公式推导见下面 扩展卡尔曼滤波算法

    卡尔曼滤波算法

    将扩展卡尔曼滤波与卡尔曼滤波进行一下对比: A t μ t − 1 + B t u t ⇒ g ( u t , μ t − 1 ) A_t\mu_{t-1} + B_tu_t \Rightarrow g(u_t,\mu_{t-1}) Atμt1+Btutg(ut,μt1) C t μ t ˉ ⇒ h ( μ t ˉ ) C_t\bar{\mu_t} \Rightarrow h(\bar{\mu_t} ) Ctμtˉh(μtˉ)雅可比矩阵 G t G_t Gt代替 A t , B t A_t,B_t At,Bt雅可比矩阵 H t H_t Ht代替 C t C_t Ct

    4 扩展卡尔曼滤波实例

    这里采用滤波算法 “扩展卡尔曼滤波(EFK)实例” 讲解的例子实例:雷达监测空中抛物轨迹 从空中位置 ( x ( 0 ) = 0 , y ( 0 ) = 500 ) (x(0)=0,y(0)=500) (x(0)=0,y(0)=500)水平抛射出一个物体(初始水平速度为 v x ( 0 ) = 50 v_x(0)=50 vx(0)=50,初始竖直速度为 v y ( 0 ) = 0 v_y(0)=0 vy(0)=0)物体受重力 g = 9.8 g=9.8 g=9.8和阻尼力(与速度的平方成正比)的影响水平和竖直阻尼系数分别为 k x = 0.01 , k y = 0.05 k_x=0.01,k_y=0.05 kx=0.01,ky=0.05,不确定度为零均值白噪声 δ a x ∼ N ( 0 , 0.09 ) , δ a y ∼ N ( 0 , 0.09 ) \delta a_x \sim N(0, 0.09),\delta a_y \sim N(0, 0.09) δaxN(0,0.09),δayN(0,0.09)在坐标原点处有一雷达,可测得距离 r r r,角度 α \alpha α, 不确定度为零均值白噪声 δ r ∼ N ( 0 , 64 ) , δ α ∼ N ( 0 , 0.01 ) \delta r \sim N(0, 64),\delta \alpha \sim N(0, 0.01) δrN(0,64),δαN(0,0.01)

    状态变量: 物体横向位置 x ( k ) x(k) x(k),物体横向速度 v x ( k ) v_x(k) vx(k),物体纵向位置 y ( k ) y(k) y(k),物体纵向速度 v y ( k ) v_y(k) vy(k) X ( k ) = [ x ( k ) , v x ( k ) , y ( k ) , v y ( k ) ] X(k) = [x(k), v_x(k), y(k), v_y(k)] X(k)=[x(k),vx(k),y(k),vy(k)]

    状态方程: x ( k + 1 ) = x ( k ) + v x ( k ) ⋅ T v x ( k + 1 ) = v x ( k ) − ( k x ⋅ v x 2 ( k ) + δ a x ) ⋅ T y ( k + 1 ) = y ( k ) + v y ( k ) ⋅ T v y ( k + 1 ) = v y ( k ) + ( k y ⋅ v y 2 ( k ) − g + δ a y ) ⋅ T \begin{aligned} x(k+1) &= x(k) + v_x(k) \cdot T\\ v_x(k+1) &= v_x(k) - (k_x \cdot v_x^2(k) + \delta a_x)\cdot T\\ y(k+1) &= y(k) + v_y(k) \cdot T \\ v_y(k+1) &= v_y(k) + (k_y \cdot v_y^2(k) - g + \delta a_y)\cdot T \end{aligned} x(k+1)vx(k+1)y(k+1)vy(k+1)=x(k)+vx(k)T=vx(k)(kxvx2(k)+δax)T=y(k)+vy(k)T=vy(k)+(kyvy2(k)g+δay)T

    观测方程: r ( k ) = x ( k ) 2 + y ( k ) 2 + δ r α ( k ) = arctan ⁡ x ( k ) y ( k ) + δ α \begin{aligned} r(k) &= \sqrt{x(k)^2 + y(k)^2 } + \delta r\\ \alpha(k) &= \arctan{\frac{x(k)}{y(k)}} + \delta \alpha\\ \end{aligned} r(k)α(k)=x(k)2+y(k)2 +δr=arctany(k)x(k)+δα

    雅克比矩阵: G t \text{雅克比矩阵:} G_t 雅克比矩阵:Gt G t = [ 1 T 0 0 0 1 − 2 k x v x T 0 0 0 0 1 T 0 0 0 1 + 2 k y v y T ] x t − 1 = μ t − 1 G_t = \begin{bmatrix} 1& T& 0& 0 \\ 0& 1 - 2k_x v_xT& 0& 0\\ 0& 0& 1& T \\ 0& 0& 0& 1 + 2k_y v_yT\\ \end{bmatrix}_{x_{t-1}=\mu_{t-1}} Gt=1000T12kxvxT00001000T1+2kyvyTxt1=μt1

    雅克比矩阵: H t \text{雅克比矩阵:} H_t 雅克比矩阵:Ht H t = [ x r 0 y r 0 1 / y 1 + ( x / y ) 2 0 − x / y 2 1 + ( x / y ) 2 0 ] x t = μ ˉ t H_t = \begin{bmatrix} \frac{x}{r}& 0& \frac{y}{r}& 0 \\ \frac{1/y}{1+(x/y)^2}& 0& \frac{-x/y^2}{1+(x/y)^2}& 0 \\ \end{bmatrix}_{x_t = \bar{\mu}_{t}} Ht=[rx1+(x/y)21/y00ry1+(x/y)2x/y200]xt=μˉt

    仿真时间总为 t = 15 t=15 t=15,采样周期 T = 0.1 T=0.1 T=0.1, 滤波效果如图:

    matlab 代码 clear; close all; clc %% 初值设定 x_0 = 0; %初始x位置 y_0 = 500; %初始y位置 v_x_0 = 50; %初始x速度 v_y_0 = 0; %初始y速度 g = 9.8; % 重力加速度 k_x = 0.01; % 阻尼系数 k_y = 0.05; % 阻尼系数 sigma_a_x = 0.09; % 状态转移不确定度方差 sigma_a_y = 0.09; % 状态转移不确定度方差 sigma_r = 64; % 测量不确定度方差 sigma_alpha = 0.01; % 测量不确定度方差 t = 15; % 仿真时间 T = 0.1; % 采样周期 len = fix(t/T); % 仿真步数 %% 真实轨迹 X = zeros(len, 4); X(1,:) = [x_0, v_x_0, y_0, v_y_0]; for k = 2 : len x_k = X(k-1,1); v_x_k = X(k-1,2); y_k = X(k-1,3); v_y_k = X(k-1,4); x_k = x_k + v_x_k * T; v_x_k = v_x_k - (k_x*v_x_k^2 + sqrt(sigma_a_x)*randn(1,1)) * T; y_k = y_k + v_y_k * T; v_y_k = v_y_k + (k_y*v_y_k^2 - g + sqrt(sigma_a_y)*randn(1,1)) * T; X(k,:) = [x_k, v_x_k, y_k, v_y_k]; end X_temp = X; %% 雷达测量 Z = zeros(len, 2); for k = 1 : len x_k = X(k,1); y_k = X(k,3); r = sqrt(x_k^2 + y_k^2) + sqrt(sigma_r)*randn(1,1); alpha = atan(x_k / y_k) * 180 / pi + sqrt(sigma_alpha)*randn(1,1); Z(k,:) = [r, alpha]; end %% EKF 扩展卡尔曼滤波 R_k = diag([0; sigma_a_x; 0; sigma_a_y]); % 状态转移误差的协方差矩阵 Q_k = diag([sigma_r, sigma_alpha]); % 测量函数误差的协方差矩阵 sigma_k = 10 * eye(4); % 最优状态协方差矩阵 sigma_bar_k= 10 * eye(4); % 预测状态协方差矩阵 mu_k = [0, 40, 400, 0]'; % 最优状态均值矩阵 mu_bar_k = zeros(4,1); % 预测的状态均值矩阵 z_k = zeros(4,1); % 观测矩阵 X_est = zeros(len,4); %EKF后的状态存储 for k = 1 : len % 1 状态预测 x1 = mu_k(1) + mu_k(2)*T; v_x1 = mu_k(2) - (k_x*mu_k(2)^2)*T; y1 = mu_k(3) + mu_k(4)*T; v_y1 = mu_k(4) + (k_y*mu_k(4)^2 - g)*T; mu_bar_k = [x1; v_x1; y1; v_y1]; % 预测的均值 G_k = zeros(4,4); % 状态雅可比矩阵 G_k(1,1) = 1; G_k(1,2) = T; G_k(2,2) = 1 - 2*k_x*v_x1*T; G_k(3,3) = 1; G_k(3,4) = T; G_k(4,4) = 1 + 2*k_y*v_y1*T; sigma_bar_k = G_k * sigma_k * G_k' + R_k; % 2 观测更新 r = sqrt(x1*x1+y1*y1); alpha = atan(x1/y1)*180/pi; z_k = [r, alpha]'; % h(\bar{\mu}_t) H_k = zeros(2,4); % 状态雅可比矩阵 x = mu_k(1); y = mu_k(3); H_k(1,1) = x / r; H_k(1,3) = y / r; H_k(2,1) = (1/y)/(1 + (x/y)^2); H_k(2,3) = (-x/(y^2))/(1 + (x/y)^2); K_k = sigma_bar_k * H_k' * (H_k * sigma_bar_k * H_k' + Q_k)^(-1); mu_k = mu_bar_k + K_k * (Z(k,:)' - z_k); sigma_k = (eye(4) - K_k * H_k) * sigma_bar_k; % 3 存储EKF后的值 X_est(k,:) = mu_k; end %% 绘图 figure, hold on, grid on; plot(X(:,1),X(:,3),'-g'); %真实位置 plot(Z(:,1).*sin(Z(:,2)*pi/180), Z(:,1).*cos(Z(:,2)*pi/180),'-b'); %观测位置 plot(X_est(:,1),X_est(:,3), 'r'); %最优位置 xlabel('X'); ylabel('Y'); title('EKF simulation'); legend('real', 'measurement', 'ekf estimated'); axis([-5,230,290,530]);

    5 扩展卡尔曼滤波(EKF)公式推导

    这里的公式推导用卡尔曼滤波公式进行类比,详细过程可以结合卡尔曼滤波公式的推导过程 Step 1: 预测 { μ ˉ t = g ( u t , μ t − 1 ) Σ ˉ t = G t Σ t − 1 G t T + R t Step 2: 测量更新 { K t = Σ ˉ t H t T ( H t Σ ˉ t H t T + Q t ) − 1 μ t = μ ˉ t + K t ( z t − h ( μ ˉ t ) ) Σ t = ( I − K t H t ) Σ ˉ t \text{Step 1: 预测}\left\{\begin{matrix} \bar{\mu}_t = g(u_t, \mu_{t-1})\\ \bar{\Sigma}_t = G_t\Sigma_{t-1} G_t^T+R_t \end{matrix}\right.\\ \text{Step 2: 测量更新}\left\{\begin{matrix} K_t = \bar{\Sigma}_t H_t^T(H_t \bar{\Sigma}_t H_t^T + Q_t)^{-1} \\ \mu_t = \bar{\mu}_t + K_t(z_t - h(\bar{\mu}_{t}))\\ \Sigma_t = (I - K_tH_t)\bar{\Sigma}_t \end{matrix}\right. Step 1: 预测{μˉt=g(ut,μt1)Σˉt=GtΣt1GtT+RtStep 2: 测量更新Kt=ΣˉtHtT(HtΣˉtHtT+Qt)1μt=μˉt+Kt(zth(μˉt))Σt=(IKtHt)Σˉt

    5.1 预测公式推导

    预测公式: b e l ˉ ( x t ) = ∫ p ( x t ∣ x t − 1 , u t ) b e l ( x t − 1 ) d x t − 1 卡尔曼滤波: p ( x t ∣ x t − 1 , u t ) ∼ N ( x t ; A t x t − 1 + B t u t , R t ) b e l ( x t − 1 ) ∼ N ( x t − 1 ; u t − 1 , Σ t − 1 ) 扩展卡尔曼滤波: p ( x t ∣ x t − 1 , u t ) ∼ N ( x t ; g ( u t , μ t − 1 ) + G t ( x t − 1 − μ t − 1 ) , R t ) b e l ( x t − 1 ) ∼ N ( x t − 1 ; u t − 1 , Σ t − 1 ) \bar{bel}(x_t) = \int p(x_t|x_{t-1},u_t)bel(x_{t-1})dx_{t-1}\\ \text{卡尔曼滤波:}p(x_t|x_{t-1},u_t) \sim N(x_t; A_t x_{t-1} + B_t u_t, R_t)\\ bel(x_{t-1}) \sim N(x_{t-1}; u_{t-1}, \Sigma_{t-1})\\ \text{扩展卡尔曼滤波:}p(x_t|x_{t-1},u_t) \sim N(x_t; g(u_t, \mu_{t-1}) + G_t(x_{t-1} - \mu_{t-1}), R_t)\\ bel(x_{t-1}) \sim N(x_{t-1}; u_{t-1}, \Sigma_{t-1}) belˉ(xt)=p(xtxt1,ut)bel(xt1)dxt1卡尔曼滤波:p(xtxt1,ut)N(xt;Atxt1+Btut,Rt)bel(xt1)N(xt1;ut1,Σt1)扩展卡尔曼滤波:p(xtxt1,ut)N(xt;g(ut,μt1)+Gt(xt1μt1),Rt)bel(xt1)N(xt1;ut1,Σt1)不同之处对比: A t x t − 1 + B t u t ⇔ g ( u t , μ t − 1 ) + G t ( x t − 1 − μ t − 1 ) A_t x_{t-1} + B_t u_t \Leftrightarrow g(u_t, \mu_{t-1}) + G_t(x_{t-1} - \mu_{t-1}) Atxt1+Btutg(ut,μt1)+Gt(xt1μt1) A t ⇔ G t A_t \Leftrightarrow G_t AtGt B t u t ⇔ g ( u t , μ t − 1 ) − G t μ t − 1 B_t u_t \Leftrightarrow g(u_t, \mu_{t-1}) - G_t \mu_{t-1} Btutg(ut,μt1)Gtμt1 那么扩展卡尔曼滤波预测步的公式可以根据卡尔曼滤波公式进行类比 Step 1: 预测 { μ ˉ t = A t μ t − 1 + B t u t ⇒ G t μ t − 1 + g ( u t , μ t − 1 ) − G t μ t − 1 = g ( u t , μ t − 1 ) Σ ˉ t = A t Σ t − 1 A t T + R t ⇒ G t Σ t − 1 G t T + R t ↓ Step 1: 预测 { μ ˉ t = g ( u t , μ t − 1 ) Σ ˉ t = G t Σ t − 1 G t T + R t \text{Step 1: 预测}\left\{\begin{matrix} \bar{\mu}_t = A_t\mu_{t-1}+B_t u_t \Rightarrow G_t\mu_{t-1}+g(u_t, \mu_{t-1}) - G_t \mu_{t-1}= g(u_t, \mu_{t-1})\\ \bar{\Sigma}_t = A_t\Sigma_{t-1} A_t^T+R_t \Rightarrow G_t\Sigma_{t-1} G_t^T+R_t \end{matrix}\right.\\ \downarrow\\ \text{Step 1: 预测}\left\{\begin{matrix} \bar{\mu}_t = g(u_t, \mu_{t-1})\\ \bar{\Sigma}_t = G_t\Sigma_{t-1} G_t^T+R_t \end{matrix}\right. Step 1: 预测{μˉt=Atμt1+BtutGtμt1+g(ut,μt1)Gtμt1=g(ut,μt1)Σˉt=AtΣt1AtT+RtGtΣt1GtT+RtStep 1: 预测{μˉt=g(ut,μt1)Σˉt=GtΣt1GtT+Rt

    5.2 测量更新公式推导

    测量更新公式: b e l ( x t ) = η p ( z t ∣ x t ) b e l ˉ ( x t )     ( η : 用于归一化 ) 卡尔曼滤波: p ( z t ∣ x t ) ∼ N ( z t ; C t x t , Q t ) b e l ˉ ( x t ) ∼ N ( x t ; μ ˉ t , Σ ˉ t ) 扩展卡尔曼滤波: p ( x t ∣ x t − 1 , u t ) ∼ N ( z t ; h ( μ ˉ t ) + H t ( x t − μ ˉ t ) , Q t ) b e l ˉ ( x t ) ∼ N ( x t ; μ ˉ t , Σ ˉ t ) bel(x_t) = \eta p(z_t|x_t)\bar{bel}(x_t)~~~(\eta:\text{用于归一化})\\ \text{卡尔曼滤波:} p(z_t|x_t) \sim N(z_t;C_tx_t,Q_t)\\ \bar{bel}(x_t) \sim N(x_t;\bar{\mu}_t,\bar{\Sigma}_t)\\ \text{扩展卡尔曼滤波:}p(x_t|x_{t-1},u_t) \sim N(z_t; h(\bar{\mu}_{t}) + H_t(x_t - \bar{\mu}_{t}), Q_t)\\ \bar{bel}(x_t) \sim N(x_t;\bar{\mu}_t,\bar{\Sigma}_t) bel(xt)=ηp(ztxt)belˉ(xt)   (η:用于归一化)卡尔曼滤波:p(ztxt)N(zt;Ctxt,Qt)belˉ(xt)N(xt;μˉt,Σˉt)扩展卡尔曼滤波:p(xtxt1,ut)N(zt;h(μˉt)+Ht(xtμˉt),Qt)belˉ(xt)N(xt;μˉt,Σˉt)不同之处对比: C t x t ⇔ h ( μ ˉ t ) + H t ( x t − μ ˉ t ) C_tx_t \Leftrightarrow h(\bar{\mu}_{t}) + H_t(x_t - \bar{\mu}_{t}) Ctxth(μˉt)+Ht(xtμˉt) C t ⇔ H t C_t \Leftrightarrow H_t CtHt C t μ ˉ t ⇔ h ( μ ˉ t ) + H t ( μ ˉ t − μ ˉ t ) = h ( μ ˉ t ) C_t \bar{\mu}_{t}\Leftrightarrow h(\bar{\mu}_{t}) + H_t( \bar{\mu}_{t} - \bar{\mu}_{t}) = h(\bar{\mu}_{t}) Ctμˉth(μˉt)+Ht(μˉtμˉt)=h(μˉt) 那么扩展卡尔曼滤波预测步的公式可以根据卡尔曼滤波公式进行类比 Step 2: 测量更新 { K t = Σ ˉ t C t T ( C t Σ ˉ t C t T + Q t ) − 1 ⇒ Σ ˉ t H t T ( H t Σ ˉ t H t T + Q t ) − 1 μ t = μ ˉ t + K t ( z t − C t μ ˉ t ) ⇒ μ ˉ t + K t ( z t − h ( μ ˉ t ) ) Σ t = ( I − K t C t ) Σ ˉ t ⇒ ( I − K t H t ) Σ ˉ t ↓ Step 2: 测量更新 { K t = Σ ˉ t H t T ( H t Σ ˉ t H t T + Q t ) − 1 μ t = μ ˉ t + K t ( z t − h ( μ ˉ t ) ) Σ t = ( I − K t H t ) Σ ˉ t \text{Step 2: 测量更新}\left\{\begin{matrix} K_t =\bar{\Sigma}_t C_t^T(C_t \bar{\Sigma}_t C_t^T + Q_t)^{-1} \Rightarrow \bar{\Sigma}_t H_t^T(H_t \bar{\Sigma}_t H_t^T + Q_t)^{-1} \\ \mu_t =\bar{\mu}_t + K_t(z_t - C_t\bar{\mu}_t) \Rightarrow \bar{\mu}_t + K_t(z_t - h(\bar{\mu}_{t}))\\ \Sigma_t =(I - K_tC_t)\bar{\Sigma}_t \Rightarrow (I - K_tH_t)\bar{\Sigma}_t \end{matrix}\right.\\ \downarrow\\ \text{Step 2: 测量更新}\left\{\begin{matrix} K_t = \bar{\Sigma}_t H_t^T(H_t \bar{\Sigma}_t H_t^T + Q_t)^{-1} \\ \mu_t = \bar{\mu}_t + K_t(z_t - h(\bar{\mu}_{t}))\\ \Sigma_t = (I - K_tH_t)\bar{\Sigma}_t \end{matrix}\right. Step 2: 测量更新Kt=ΣˉtCtT(CtΣˉtCtT+Qt)1ΣˉtHtT(HtΣˉtHtT+Qt)1μt=μˉt+Kt(ztCtμˉt)μˉt+Kt(zth(μˉt))Σt=(IKtCt)Σˉt(IKtHt)ΣˉtStep 2: 测量更新Kt=ΣˉtHtT(HtΣˉtHtT+Qt)1μt=μˉt+Kt(zth(μˉt))Σt=(IKtHt)Σˉt

    6 扩展卡尔曼滤波的优缺点

    优点:计算简单效率高缺点:对状态转移函数和测量函数的线性近似,使得结果存在误差 原函数不确定度(方差)越大,近似效果越差,见下图: 右下角 p ( x ) p(x) p(x)的分布均值相同,方差不同右上角变换函数 y = g ( x ) y=g(x) y=g(x)相同左上角 p ( y ) p(y) p(y)的分布,下图误差小于上图,原因在于下图的方差较小

    原函数局部非线性越强,近似效果越差,见下图: 右下角 p ( x ) p(x) p(x)的分布均值不同,方差相同右上角变换函数 y = g ( x ) y=g(x) y=g(x)相同左上角 p ( y ) p(y) p(y)的分布,下图误差小于上图,原因在于下图变换函数的局部非线性越弱

    总结:状态变量的不确定度(方差)对EKF影响很大,尽量保持一个小的不确定度

    7 参考文献

    Thrun, & Sebastian. (2005). Probabilistic robotics.滤波算法 “扩展卡尔曼滤波(EFK)实例” 讲解
    Processed: 0.096, SQL: 8