粒子滤波原理和MATLAB代码实现

news2024/10/7 8:23:39

理论基础1

(a) Prediction

  • Use the transition equation to propagate the particles:

在这里插入图片描述

(b) Update

  • Use the measurement equation to obtain measurements of the propagated particles and their standard deviations:

在这里插入图片描述

(in the case of our program, ym is obtained via simulation of the system, in real-time applications this value could be just the average of measurements).

  • Evaluate the measurement PDF at the propagated particles. Then, normalize to obtain the weights. For instance:

在这里插入图片描述

(the weights have been denoted as pq(n) in the program)

  • Resampling. Obtain new p ‾ x ( n + 1 ) \overline{p}x(n + 1) px(n+1) from a p ‾ x ( n + 1 ) a\overline{p}x (n + 1) apx(n+1)using the normalized weights.

Note: Several resampling methods:

1、Multinomial Resampling

%Resampling (multinomial)
acq=cumsum(pq);
mm=1;
nr=sort(rand(1,Np)); %ordered random numbers (0, 1]
for ip=1:Np
    while(acq(mm)<nr(ip))
        mm=mm+1;
    end
    aux=apx(:,mm);
    Mpx(:,ip)=aux+(sig.*rn(:,ip)); %roughening
end

2、Systematic Resampling

%Resampling (systematic)
acq=cumsum(pq);
cmb=linspace(0,1-(1/Np),Np)+(rand(1)/Np); %the "comb"
cmb(Np+1)=1;
ip=1; mm=1;
while(ip<=Np)
    if (cmb(ip)<acq(mm))
        aux=apx(:,mm);
        Spx(:,ip)=aux+(sig.*rn(:,ip)); %roughening
        ip=ip+1;
    else
    	mm=mm+1;
    end
end

3、 Stratified Resampling

%Resampling (stratified)
acq=cumsum(pq);
stf=zeros(1,Np);
nr=rand(1,Np)/Np;
j=1:Np;
stf(j)=nr(j)+((j-1)/Np); %(vectorized code)
stf(Np+1)=1;
ip=1; mm=1;
while(ip<=Np)
	if (stf(ip)<acq(mm))
        aux=apx(:,mm);
        Fpx(:,ip)=aux+(sig.*rn(:,ip)); %roughening
        ip=ip+1;
    else
        mm=mm+1;
    end
end

4、Residual Resampling

%Resampling (residual)
acq=cumsum(pq);
mm=1;
%preparation
na=floor(Np*pq); %repetition counts
NR=sum(na); %total count
Npr=Np-NR; %number of non-repeated particles
rpq=((Np*pq)-na)/Npr; %modified weights
acq=cumsum(rpq); %for the monomial part
%deterministic part
mm=1;
for j=1:Np
    for nn=1:na(j)
        Rpx(:,mm)=apx(:,j);
        mm=mm+1;
    end
end
%multinomial part:
nr=sort(rand(1,Npr)); %ordered random numbers (0, 1]
for j=1:Npr
    while(acq(mm)<nr(j))
    	mm=mm+1;
    end
    aux=apx(:,mm);
    Rpx(:,NR+j)=aux+(sig.*rn(:,j)); %roughening
end

一些比较研究表明,分层和系统重采样在滤波器估计和计算复杂度方面优于多项重采样。在残差重采样的情况下,大约一半的副本是确定的,另一半是随机的:这意味着更少的计算,但可以通过重新计算权重和算法的其他方面来补偿。部分实验证明,残差重采样的结果方差更小。

  • Roughening

为了防止样本贫化,对后验粒子进行粗化处理[21,96]。添加一个零均值噪声,其方差正比于:

在这里插入图片描述

where n is the dimension of the space, k is a tuning parameter, and the j-th element of the vector M is:

在这里插入图片描述

where xm k (j) is the j-th component of the posterior particle xm k (which is a vector).

  • Evaluate the mean of the set p ‾ x ( n + 1 ) \overline{p}x(n + 1) px(n+1) This is the estimated state

代码实现1

%Particle filter example
%Radar monitoring of falling body
disp('please wait a bit');
%------------------------------------------
%Prepare for the simulation of the falling body
T=0.4; %sampling period
g=-9.81;
rho0=1.225; %air density, sea level
k=6705.6; %density vs. altitude constant
L=100; %horizontal distance radar<->object
L2=L^2;
Nf=100; %maximum number of steps
rx=zeros(3,Nf); %space for state record
tim=0:T:(Nf-1)*T; %time
%process noise
Sw=[10^5 0 0; 0 10^3 0; 0 0 10^2]; %cov
w11=sqrt(Sw(1,1)); w22=sqrt(Sw(2,2)); w33=sqrt(Sw(3,3));
w=[w11; w22; w33];
%observation noise
Sv=10^6; %cov.
v11=sqrt(Sv);
%------------------------------------------
%Prepare for filtering
%space for recording er(n), xe(n)
rer=zeros(3,Nf); rxe=zeros(3,Nf);
%------------------------------------------
%Behaviour of the system and the filter after initial state
x=[10^5; -5000; 400]; %initial state
xe=x; %initial estimation
%prepare particles
Np=1000; %number of particles
%reserve space
px=zeros(3,Np); %particles
apx=zeros(3,Np); %a priori particles
ny=zeros(1,Np); %particle measurements
vy=zeros(1,Np); %meas. dif.
pq=zeros(1,Np); %particle likelihoods
%particle generation
wnp=randn(3,Np); %noise (initial particles)
for ip=1:Np,
px(:,ip)=x+(w.*wnp(:,ip)); %initial particles
end
%system noises
wx=randn(3,Nf); %process
wy=randn(1,Nf); %output
nn=1;
while nn<Nf+1
    %estimation recording
    rxe(:,nn)=xe; %state
    rer(:,nn)=x-xe; %error
    %Simulation of the system
    %system
    rx(:,nn)=x; %state recording
    rho=rho0*exp(-x(1)/k); %air density
    d=(rho*(x(2)^2))/(2*x(3)); %drag
    rd(nn)=d; %drag recording
    %next system state
    x(1)=x(1)+(x(2)*T);
    x(2)=x(2)+((g+d)*T);
    x(3)=x(3);
    x=x+(w.*wx(:,nn)); %additive noise
    %system output
    y=sqrt(L2+(x(1)^2))+(v11*wy(nn)); %additive noise
    ym=y; %measurement
    %Particle propagation
    wp=randn(3,Np); %noise (process)
    vm=randn(1,Np); %noise (measurement)
    for ip=1:Np
        rho=rho0*exp(-px(1,ip)/k); %air density
        d=(rho*(px(2,ip)^2))/(2*px(3,ip)); %drag
        %next state
        apx(1,ip)=px(1,ip)+(px(2,ip)*T);
        apx(2,ip)=px(2,ip)+((g+d)*T);
        apx(3,ip)=px(3,ip);
        apx(:,ip)=apx(:,ip)+(w.*wp(:,ip)); %additive noise
        %measurement (for next state)
        ny(ip)=sqrt(L2+(apx(1,ip)^2))+(v11*vm(ip)); %additive noise
        vy(ip)=ym-ny(ip);
    end
    %Likelihood
    %(vectorized part)
    %scaling
    vs=max(abs(vy))/4;
    ip=1:Np;
    pq(ip)=exp(-((vy(ip)/vs).^2));
    spq=sum(pq);
    %normalization
    pq(ip)=pq(ip)/spq;
    %Prepare for roughening
    A=(max(apx')-min(apx'))';
    sig=0.2*A*Np^(-1/3);
    rn=randn(3,Np); %random numbers
    %================================
    %Resampling (systematic)
    acq=cumsum(pq);
    cmb=linspace(0,1-(1/Np),Np)+(rand(1)/Np); %the "comb"
    cmb(Np+1)=1;
    ip=1; mm=1;
    while(ip<=Np)
        if (cmb(ip)<acq(mm))
            aux=apx(:,mm);
            px(:,ip)=aux+(sig.*rn(:,ip)); %roughening
            ip=ip+1;
        else
            mm=mm+1;
        end
    end
    %=================================
    %Results
    %estimated state (the particle mean)
    xe=sum(px,2)/Np;
    nn=nn+1;
end
%------------------------------------------
%display
figure(1)
subplot(1,2,1)
plot(tim,rx(1,1:Nf),'kx'); hold on;
plot(tim,rxe(1,1:Nf),'r');
title('altitude'); xlabel('seconds')
axis([0 Nf*T 0 12*10^4]);
subplot(1,2,2)
plot(tim,rx(2,1:Nf),'kx'); hold on;
plot(tim,rxe(2,1:Nf),'r');
title('velocity'); xlabel('seconds');
axis([0 Nf*T -6000 1000]);

结果:
在这里插入图片描述

参考:


  1. Kalman Filter, Particle Filter and Other Bayesian Filters ↩︎ ↩︎

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/125375.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

如何在 Manjaro Linux 上安装 ONLYOFFICE 桌面编辑器

ONLYOFFICE 桌面编辑器是一款免费开源办公套件&#xff0c;其中包括适用于文本文档、电子表格与演示文稿的离线编辑器。同时&#xff0c;您还可将应用程序连接至云端&#xff08;ONLYOFFICE、Nextcloud 等&#xff09;以便在线开展文档协作。该应用的源代码已根据 AGPL v.3.0 许…

业务中台10讲2.0合辑(推荐收藏)

目录V3.0迭代内容&#xff1a; 增加最近更新的中台系列文章至本目录&#xff1b;根据最新热点修订并调整部分未更新内容方向&#xff1b;为各文章标注《中台产品经理宝典》书中原文出处&#xff1b;本目录使用方法&#xff1a; 本目录推文为中台内容系列中的业务中台子类新原…

华润微功放CS3850EO,2×40W D 类音频功率放大电路,替换:智浦芯CS8673,TI的TAS5780、TAS5754,国产功放

1、概述 CS3850EO 是一款典型输出功率为 40W 立体声的 D 类音频功率放大电路&#xff0c;适用于拉杆音箱、高级桌面音响等场合。 特点 ● 工作电压范围&#xff1a;8V~26V ● 典型输出功率&#xff1a;30W2 20V、8Ω、THD10% 40W2 18V、4Ω、THD10% 50W2 26.5V、8Ω、…

你以为Shell只是命令行?读懂这篇文,给你的工作赋能

可以使用adb tcpip 端口在Android设备上启动一个指定的端口&#xff0c;然后使用adb connect Android设备ip:端口远程连接Android设备。 uiautomator 是一个 java 库&#xff0c;包含用于创建自定义功能UI测试的API&#xff0c;以及用于自动执行和运行测试的执行引擎。使用uiau…

Transformer与看图说话

&#x1f3c5;&#x1f3c5;&#x1f3c5;&#x1f3c5;&#x1f3c5;&#x1f3c5;&#x1f3c5;&#x1f3c5;&#x1f3c5;&#x1f3c5;&#x1f3c5;&#x1f3c5;&#x1f3c5;&#x1f3c5;&#x1f3c5;&#x1f3c5; 一年一度的【博客之星】评选活动已开始啦 作为第一…

Redis的持久化技术

1. 前言 今天呢&#xff0c;我们来了解下Redis的持久化技术。都知道Redis是内存型key-value型数据库。其实叫缓存中间件更合适。既然是内存性数据库就知道存入磁盘的必要性了。所以就需要持久化技术来支持了 2. 合适人群 对Redis 持久化技术不了解的人 3. RDB RDB 其实就是Re…

推荐三款 Mac 上的理财神器 iCompta、Rublik、UctoX

推荐三款 Mac 上的理财神器 iCompta、Rublik、UctoX 今天推荐三款理财神器&#xff0c;像个人的话可以使用 iCompta&#xff08;个人财务管理&#xff09;一款软件就好了&#xff0c;但有些朋友可能有关注汇率的需求&#xff0c;可以使用 Rublik&#xff08;汇率动态&#xff…

尚硅谷密码学

密码学1. 密码学1.1. 密码学基本概念1.2 密码学的历史1.2.1 古典密码学1.2.1.1. 替换法1.2.1.2移位法1.2.1.2 古代密码学的破解方式1.2.2 进代密码学1.2.3 现代密码学1.2.3.1 散列函数1.2.3.2 对称密码1.2.3.3 非对称密码1.2.4 如何设置密码才安全1.2.5 ASCII编码1.3 凯撒加密1…

Ant Design Pro入门

目录 一&#xff1a;了解Ant Design Pro 二&#xff1a;快速入门 一&#xff1a;了解Ant Design Pro Ant Design Pro 是基于Ant Design的一个开箱即用的&#xff0c;企业级中后台前端/设计解决方案。 效果&#xff1a;源码地址&#xff1a;https://github.com/ant-design/ant…

Linux制作和使用动静态库

文章目录一、概念1.1 动态库和静态库1.2 动态链接和静态链接二、制作第三方库2.1 生成静态库① 制作静态库② 使用静态库2.2 生成动态库① 制作动态库② 使用动态库三、相关题目一、概念 1.1 动态库和静态库 静态库与动态库本质都是一堆目标文件(xxx.o)的集合&#xff0c;库的…

MySQL 索引之道

文章目录1. 索引的介绍2. 索引的本质3. 索引的结构3.1 Hash3.2 B树3.3 常见面试题之为什么用B树4. 索引的分类4.1 功能逻辑层次4.2 存储形式层次5. 索引的失效5.1 最左前缀原则5.2 索引失效的场景6. 索引常见面试题7. 总结及参考文献1. 索引的介绍 索引是通过某种算法&#xf…

快速学习一门新技术的工作原理(十步学习法来自软技能)

快速学习一门新技术的工作原理 ●如何开始——要想开始使用自己所学的&#xff0c;我需要掌握哪些基本知识&#xff1f; ●学科范围——我现在学的东西有多宏大&#xff1f;我应该怎么做&#xff1f;在开始阶段&#xff0c;我不需要了解每个细节&#xff0c;但是如果我能对该学…

后台交互-首页

目录 后台准备 pom.xml 配置数据源 mybatis-generator 整合mybatis 准备前端的首页的数据 Promise 封装request 会议展示 后台准备 springbootmybatis pom.xml <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://ma…

数据结构之链表(java语言实现)

链表的底层储存结构&#xff1a; 相对于数组这一需要连续、足够大空间的数据结构&#xff0c;链表只需要利用“指针”将一组零碎的空间(在链表中称之为节点)串联起来&#xff0c;这样就可以避免在创建数组时一次性申请过大的空间二导致有可能创建失败的问题!!! 同时比较两种数…

20221228英语学习

今日短文 Words and Phrases to Avoid in a Difficult Conversation Difficult conversations are difficult for a reason, and when you’re anxious or stressed out, it’s easy to say the wrong thing.And it doesn’t matter how prepared you are.Your best laid plan…

UDP协议与TCP协议详解

UDP协议详解 UDP&#xff0c;即User Datagram Protocol&#xff0c;用户数据报协议 UDP协议的特点&#xff1a;无连接&#xff0c;不可靠传输&#xff0c;面向数据报&#xff0c;全双工 无连接&#xff1a;知道对端的IP和端口号就直接进行传输&#xff0c;不需要建立连接&am…

深入讲解Linux中断子系统--Workqueue

说明&#xff1a; Kernel版本&#xff1a;4.14ARM64处理器&#xff0c;Contex-A53&#xff0c;双核使用工具&#xff1a;Source Insight 3.5&#xff0c; Visio 1. 概述 Workqueue工作队列是利用内核线程来异步执行工作任务的通用机制&#xff1b;Workqueue工作队列可以用作中…

以前的互联网时代,其实就是一个以互联网技术为主导的年代

事实上&#xff0c;以往&#xff0c;我们所经历的那个互联网玩家频出的年代&#xff0c;其实就是一个以互联网技术为主导的年代。在那样一个年代里&#xff0c;互联网技术几乎是解决一切痛点和难题的万能解药&#xff0c;几乎是破解一切行业痛点和难题的杀手锏。任何一个行业&a…

使用Python读取网易邮箱大师客户端的所有邮件

文章目录1. 前言2. 效果3. 探究过程3.1. 找到本地存储的数据库3.2. 使用Python读取数据库3.2.1. 代码4. 探究结果4.1. 函数4.1.1. 找到特定邮~箱的最新一条邮件4.1.2. 找到特定邮箱的最新一次验证码4.1.3. 通过命令行调用Python代码找到特定邮箱的最新的验证码1. 前言 现在绝大…

中科大FPGAOL使用方法

1.中科大的FPGA在线平台提供了一个非常好用的功能&#xff0c;将bit文件上传到远程FPGA开发板上加以功能验证&#xff0c;而且可以游客的身份访问。 Login - FPGA Onlinehttp://fpgaol.ustc.edu.cn/ 2.系统采用的硬件平台是赛灵思的Nexys4 DDR开发板(xc7a100t-csg324)&#x…