版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、function ParticleEx1% Particle filter example, adapted from Gordon, Salmond, and Smith paper.x = 0.1; % initial stateQ = 1; % process noise covarianceR = 1; % measurement noise covariancetf = 50; % simulation lengthN = 100; % number of particles in the particle filterxhat = x;P = 2;xhatPart = x;% In
2、itialize the particle filter.for i = 1 : Nxpart(i = x + sqrt(P * randn;endjArr = 0;xArr = x;yArr = x2 / 20 + sqrt(R * randn;xhatArr = x;PArr = P;xhatPartArr = xhatPart;close all;for k = 1 : tf% System simulationx = 0.5 * x + 25 * x / (1 + x2 + 8 * cos(1.2*(k-1 + sqrt(Q * randn;%状态方程y = x2 / 20 + sqr
3、t(R * randn;%观测方程% Extended Kalman filterF = 0.5 + 25 * (1 - xhat2 / (1 + xhat22;P = F * P * F + Q;H = xhat / 10;K = P * H * (H * P * H + R(-1;xhat = 0.5 * xhat + 25 * xhat / (1 + xhat2 + 8 * cos(1.2*(k-1;%预测xhat = xhat + K * (y - xhat2 / 20;%更新P = (1 - K * H * P;% Particle filterfor i = 1 : Nxpartm
4、inus(i = 0.5 * xpart(i + 25 * xpart(i / (1 + xpart(i2 + 8 * cos(1.2*(k-1 + sqrt(Q * randn;ypart = xpartminus(i2 / 20;vhat = y - ypart;%观测和预测的差q(i = (1 / sqrt(R / sqrt(2*pi * exp(-vhat2 / 2 / R;end% Normalize the likelihood of each a priori estimate.qsum = sum(q;for i = 1 : Nq(i = q(i / qsum;%归一化权重en
5、d% Resample.重采样for i = 1 : Nu = rand; % uniform random number between 0 and 1qtempsum = 0;for j = 1 : Nqtempsum = qtempsum + q(j;if qtempsum = uxpart(i = xpartminus(j;if k = 20qArr=q;jArr = jArr j;endbreak;endendend% The particle filter estimate is the mean of the particles.xhatPart = mean(xpart;% P
6、lot the estimated pdfs at a specific time.if k = 20% Particle filter pdfpdf = zeros(81,1;for m = -40 : 40for i = 1 : Nif (m = xpart(i & (xpart(i m+1pdf(m+41 = pdf(m+41 + 1;endendendfigure;m = -40 : 40;plot(m, pdf / N, r;hold;title(Estimated pdf at k=20;disp(min, max xpart(i at k = 20: , num2str(min(
7、xpart, , , num2str(max(xpart;% Kalman filter pdfend% Save data in arrays for later plottingxArr = xArr x;yArr = yArr y;xhatArr = xhatArr xhat;PArr = PArr P;xhatPartArr = xhatPartArr xhatPart;endt = 0 : tf;%figure;%plot(t, xArr;%ylabel(true state;figure;plot(t, xArr, b., t, xhatArr, g-., t, xhatArr-2
8、*sqrt(PArr, r:, t, xhatArr+2*sqrt(PArr, r:; axis(0 tf -40 40;set(gca,FontSize,12; set(gcf,Color,White;xlabel(time step; ylabel(state;legend(True state, EKF estimate, 95% confidence region;grid on;figure;plot(t, xArr, b., t, xhatPartArr, k-;set(gca,FontSize,12; set(gcf,Color,White;xlabel(time step; ylabel(state;legend(True state, Particle filter estimate;grid on;xhatRMS = sqrt(norm(xArr - xhatArr2 / tf;xhatPartRMS = sqrt(norm(xArr - xhatPartArr2 / tf;disp(Kalman filter RMS error = , num2str(xhatRMS;disp(Particle filter RMS error = , num2str(xhatPartRMS;/*qArrtt=max(qArrt=jArrm,n=hi
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论