当前位置:网站首页>Kalman filter (KF) unscented Kalman filter (UKF)
Kalman filter (KF) unscented Kalman filter (UKF)
2022-06-09 20:03:00 【Changsha has fat fish】
Write it at the front : Kalman filter is rather obscure , Popular point , According to my understanding, it is to use the known information to estimate the optimal location , for instance , Where will a person or a car be next , This is what the Kalman filter does , Use relevant mathematical methods to figure out where the next position is most likely , Its essence is to optimize the estimation algorithm .
It's today 6 month 7 Number , I wish many students , Jinbang title , Today's college entrance examination students admitted to the University , When searching for information , This blog may be read by some students today , Wish them well , May they be better than blue ( Because I'm a good cook ), Become an expert in this field , Take me then !!
There's so much on it , If you can't see clearly , You can download it from my baidu online disk , At the end of the article, there are some codes , interested , You can go and study !!
link :https://pan.baidu.com/s/1MZNHKxtO3pgF6iWfp5pbyw
Extraction code :8888
I saw B Standing on the great God's explanation , I wrote a copy by myself , It's very good , You can go and have a look ( Thank you for your explanation )
From giving up to mastery ! Kalman filter from theory to practice ~_ Bili, Bili _bilibili
![]()
UKF deduction :
Bayesian filtering and Kalman filtering Lecture 14 Unscented Kalman filter _ Bili, Bili _bilibili
thank B Explanation from the station boss , Although I wrote it by hand , Still can't understand ( It's mainly because I'm too busy ), But the boss is strong , And modest , Thank you very much !!
KF Small example :
# -*- coding=utf-8 -*- # Kalman filter example demo in Python # A Python implementation of the example given in pages 11-15 of "An # Introduction to the Kalman Filter" by Greg Welch and Gary Bishop, # University of North Carolina at Chapel Hill, Department of Computer # Science, TR 95-041, # coding:utf-8 import numpy import pylab # Here's the assumption A=1,H=1 The situation of # intial parameters n_iter = 50 sz = (n_iter,) # size of array x = -0.37727 # truth value (typo in example at top of p. 13 calls this z) z = numpy.random.normal(x,0.1,size=sz) # observations (normal about x, sigma=0.1) Q = 1e-5 # process variance # allocate space for arrays xhat=numpy.zeros(sz) # a posteri estimate of x P=numpy.zeros(sz) # a posteri error estimate xhatminus=numpy.zeros(sz) # a priori estimate of x Pminus=numpy.zeros(sz) # a priori error estimate K=numpy.zeros(sz) # gain or blending factor R = 0.1**2 # estimate of measurement variance, change to see effect # intial guesses xhat[0] = 0.0 P[0] = 1.0 for k in range(1,n_iter): # time update xhatminus[k] = xhat[k-1] #X(k|k-1) = AX(k-1|k-1) + BU(k) + W(k),A=1,BU(k) = 0 Pminus[k] = P[k-1]+Q #P(k|k-1) = AP(k-1|k-1)A' + Q(k) ,A=1 # measurement update K[k] = Pminus[k]/( Pminus[k]+R ) #Kg(k)=P(k|k-1)H'/[HP(k|k-1)H' + R],H=1 xhat[k] = xhatminus[k]+K[k]*(z[k]-xhatminus[k]) #X(k|k) = X(k|k-1) + Kg(k)[Z(k) - HX(k|k-1)], H=1 P[k] = (1-K[k])*Pminus[k] #P(k|k) = (1 - Kg(k)H)P(k|k-1), H=1 pylab.figure() pylab.plot(z,'k+',label='noisy measurements') # Measured value pylab.plot(xhat,'b-',label='a posteri estimate') # The filtered value pylab.axhline(x,color='g',label='truth value') # System value pylab.legend() pylab.xlabel('Iteration') pylab.ylabel('Voltage') pylab.figure() valid_iter = range(1,n_iter) # Pminus not valid at step 0 pylab.plot(valid_iter,Pminus[valid_iter],label='a priori error estimate') pylab.xlabel('Iteration') pylab.ylabel('$(Voltage)^2$') pylab.setp(pylab.gca(),'ylim',[0,.01]) pylab.show()
EKF Small example :
import numpy as np import math import matplotlib.pyplot as plt # Estimation parameter of EKF Q = np.diag([0.1, 0.1, np.deg2rad(1.0), 1.0])**2 R = np.diag([1.0, np.deg2rad(40.0)])**2 # Simulation parameter Qsim = np.diag([0.5, 0.5])**2 Rsim = np.diag([1.0, np.deg2rad(30.0)])**2 DT = 0.1 # time tick [s] SIM_TIME = 50.0 # simulation time [s] show_animation = True def calc_input(): v = 1.0 # [m/s] yawrate = 0.1 # [rad/s] u = np.matrix([v, yawrate]).T return u def observation(xTrue, xd, u): xTrue = motion_model(xTrue, u) # add noise to gps x-y zx = xTrue[0, 0] + np.random.randn() * Qsim[0, 0] zy = xTrue[1, 0] + np.random.randn() * Qsim[1, 1] z = np.matrix([zx, zy]) # add noise to input ud1 = u[0, 0] + np.random.randn() * Rsim[0, 0] ud2 = u[1, 0] + np.random.randn() * Rsim[1, 1] ud = np.matrix([ud1, ud2]).T xd = motion_model(xd, ud) return xTrue, z, xd, ud def motion_model(x, u): F = np.matrix([[1.0, 0, 0, 0], [0, 1.0, 0, 0], [0, 0, 1.0, 0], [0, 0, 0, 0]]) B = np.matrix([[DT * math.cos(x[2, 0]), 0], [DT * math.sin(x[2, 0]), 0], [0.0, DT], [1.0, 0.0]]) x = F * x + B * u return x def observation_model(x): # Observation Model H = np.matrix([ [1, 0, 0, 0], [0, 1, 0, 0] ]) z = H * x return z def jacobF(x, u): """ Jacobian of Motion Model motion model x_{t+1} = x_t+v*dt*cos(yaw) y_{t+1} = y_t+v*dt*sin(yaw) yaw_{t+1} = yaw_t+omega*dt v_{t+1} = v{t} so dx/dyaw = -v*dt*sin(yaw) dx/dv = dt*cos(yaw) dy/dyaw = v*dt*cos(yaw) dy/dv = dt*sin(yaw) """ yaw = x[2, 0] v = u[0, 0] jF = np.matrix([ [1.0, 0.0, -DT * v * math.sin(yaw), DT * math.cos(yaw)], [0.0, 1.0, DT * v * math.cos(yaw), DT * math.sin(yaw)], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]]) return jF def jacobH(x): # Jacobian of Observation Model jH = np.matrix([ [1, 0, 0, 0], [0, 1, 0, 0] ]) return jH def ekf_estimation(xEst, PEst, z, u): # Predict xPred = motion_model(xEst, u) jF = jacobF(xPred, u) PPred = jF * PEst * jF.T + Q # Update jH = jacobH(xPred) zPred = observation_model(xPred) y = z.T - zPred S = jH * PPred * jH.T + R K = PPred * jH.T * np.linalg.inv(S) xEst = xPred + K * y PEst = (np.eye(len(xEst)) - K * jH) * PPred return xEst, PEst def plot_covariance_ellipse(xEst, PEst): Pxy = PEst[0:2, 0:2] eigval, eigvec = np.linalg.eig(Pxy) if eigval[0] >= eigval[1]: bigind = 0 smallind = 1 else: bigind = 1 smallind = 0 t = np.arange(0, 2 * math.pi + 0.1, 0.1) a = math.sqrt(eigval[bigind]) b = math.sqrt(eigval[smallind]) x = [a * math.cos(it) for it in t] y = [b * math.sin(it) for it in t] angle = math.atan2(eigvec[bigind, 1], eigvec[bigind, 0]) R = np.matrix([[math.cos(angle), math.sin(angle)], [-math.sin(angle), math.cos(angle)]]) fx = R * np.matrix([x, y]) px = np.array(fx[0, :] + xEst[0, 0]).flatten() py = np.array(fx[1, :] + xEst[1, 0]).flatten() plt.plot(px, py, "--r") def main(): print(__file__ + " start!!") time = 0.0 # State Vector [x y yaw v]' xEst = np.matrix(np.zeros((4, 1))) xTrue = np.matrix(np.zeros((4, 1))) PEst = np.eye(4) xDR = np.matrix(np.zeros((4, 1))) # Dead reckoning # history hxEst = xEst hxTrue = xTrue hxDR = xTrue hz = np.zeros((1, 2)) while SIM_TIME >= time: time += DT u = calc_input() xTrue, z, xDR, ud = observation(xTrue, xDR, u) xEst, PEst = ekf_estimation(xEst, PEst, z, ud) # store data history hxEst = np.hstack((hxEst, xEst)) hxDR = np.hstack((hxDR, xDR)) hxTrue = np.hstack((hxTrue, xTrue)) hz = np.vstack((hz, z)) if show_animation: plt.cla() plt.plot(hz[:, 0], hz[:, 1], ".g") plt.plot(np.array(hxTrue[0, :]).flatten(), np.array(hxTrue[1, :]).flatten(), "-b") plt.plot(np.array(hxDR[0, :]).flatten(), np.array(hxDR[1, :]).flatten(), "-k") plt.plot(np.array(hxEst[0, :]).flatten(), np.array(hxEst[1, :]).flatten(), "-r") plot_covariance_ellipse(xEst, PEst) plt.axis("equal") plt.grid(True) plt.pause(0.001) if __name__ == '__main__': main()
Finally, I sorted out some code , If you need it, you can download it yourself , What can be used , The breadth and depth of the Kalman filter will not be solved in a moment and a half , Ah , It's really hard , I hope you can give me more advice !!
link :https://pan.baidu.com/s/1aeyGpRS5uqHq4U2NAqdh5w
Extraction code :8888
边栏推荐
- 阿里云22Q1状况汇总,你往哪走
- Set creation and traversal methods
- VNCTF 2022 InterestingPHP
- 台湾再度严查陆企挖角:出动百余人次,10家企业被查,约谈近70人次!
- The crayfish left out by the young people has only a life of losing money?
- 【RK2206】4. MQTT示例
- Système de fichiers racine
- Smart PLC calls the same subroutine (FC) multiple times
- Leetcode stack and queue
- STM32内存知识
猜你喜欢

Xcode 14 带来全新提升,Xcode Cloud 正式推出!
![[effectiveness platform] test case management module - obtain use case list data, view use case details data, add and update use cases, delete use case related function development (7)](/img/0a/8842fc7bdb557ef76bffd746e6d060.png)
[effectiveness platform] test case management module - obtain use case list data, view use case details data, add and update use cases, delete use case related function development (7)

Leetcode 1984. Minimum difference in student scores (yes, resolved)

Unity将Project升级至URP

Babbitt | metauniverse daily must read: Citibank reported that the metauniverse economy represents $13 trillion in income opportunities, and there are five identified early investment opportunities
![[opencvsharpdnn] implementation example of yolov3 and Caffe in opencvsharp](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[opencvsharpdnn] implementation example of yolov3 and Caffe in opencvsharp

种一棵树最好的时间是十年前,其次便是现在(C语言选择和循环训练题目)

Uniapp H5 single page horizontal screen

The best time to plant a tree is ten years ago, and the second is now (C language selection and cycle training topic)

Exploration and analysis of hidden information of network security system vulnerabilities in Secondary Vocational Schools
随机推荐
2022 "network security" competition of secondary vocational group freshmen test of Shandong Zibo Industrial school competition assignment
95后大厂程序员删库被判刑9个月
Not only Lenovo, which sells computers, but also what's new?
台湾再度严查陆企挖角:出动百余人次,10家企业被查,约谈近70人次!
Qualcomm: it will adhere to the diversified OEM strategy and pay attention to the business cooperation conditions of Intel OEM
【tgowt】cmake转ninja构建
Look at other people's text recognition system. It's called elegant!
只出现一次的数字(异或运算,哈希表)
Official competition paper and scoring standard of "Cyberspace Security" of secondary vocational group in 2018 national vocational college skills competition
Aspx datatable row column interchange
手把手带你使用代码迁移工具实现源码迁移到鲲鹏处理器
Leetcode 1984. Minimum difference in student scores (yes, resolved)
Assignment for "information security management and evaluation" of higher vocational group in 20XX national vocational college skills competition
TiDB单机、集群环境安装,单机急速体验
paramiko和线程池Demo(快速批量操作服务器)
Fastjson解析JSON时乱序解决
Unity upgrade project to URP
安路科技发布SF1系列FPSoC新品:高集成低功耗,助力实现多种应用场景
ASPX DataTable 行列互换
JVM-字节码是如何被JVM执行的+关于线程一点思想引子










































