资源简介
这是用于目标跟踪的粒子滤波代码,
用matlab编写的,很有借鉴性,一维情况下,
非高斯非线性,其中将扩展卡尔曼滤波与粒子滤波进行比较,更好的说明了粒子滤波的优越性
代码片段和文件信息
function ParticleEx1
% Particle filter example adapted from Gordon Salmond and Smith paper.
x = 0.1; % initial state
Q = 1; % process noise covariance
R = 1; % measurement noise covariance
tf = 50; % simulation length
N = 100; % number of particles in the particle filter
xhat = x;
P = 2;
xhatPart = x;
% Initialize the particle filter.
for i = 1 : N
xpart(i) = x + sqrt(P) * randn;
end
xArr = [x];
yArr = [x^2 / 20 + sqrt(R) * randn];
xhatArr = [x];
PArr = [P];
xhatPartArr = [xhatPart];
close all;
for k = 1 : tf
% System simulation
x = 0.5 * x + 25 * x / (1 + x^2) + 8 * cos(1.2*(k-1)) + sqrt(Q) * randn;%状态方程
y = x^2 / 20 + sqrt(R) * randn;%观测方程
% Extended Kalman filter
F = 0.5 + 25 * (1 - xhat^2) / (1 + xhat^2)^2;
P = F * P * F‘ + Q;
H = xhat / 10;
K = P * H‘ * (H * P * H‘ + R)^(-1);
xhat = 0.5 * xhat + 25 * xhat / (1 + xhat^2) + 8 * cos(1.2*(k-1));%预测
xhat = xhat + K * (y - xhat^2 / 20);%更新
P = (1 - K * H) * P;
% Particle filter
for i = 1 : N
xpartminus(i) = 0.5 * xpart(i) + 25 * xpart(i) / (1 + xpart(i)^2) + 8 * cos(1.2*(k-1)) + sqrt(Q) * randn;
ypart = xpartminus(i)^2 / 20;
vhat = y - ypart;%观测和预测的差
q(i) = (1 / sqrt(R) / sqrt(2*pi)) * exp(-vhat^2 / 2 / R);
end
% Normalize the likelihood of each a priori estimate.
qsum = sum(q);
for i = 1 : N
q(i) = q(i) / qsum;%归一化权重
end
% Resample.
for i = 1 : N
u = rand; % uniform random number between 0 and 1
qtempsum = 0;
for j = 1 : N
qtempsum = qtempsum + q(j);
if qtempsum >= u
xpart(i) = xpartminus(j);
break;
end
end
end
% The particle filter estimate is the mean of the particles.
xhatPart = mean(xpart);
% Plot the estimated pdf‘s at a specific time.
if k == 20
% Particle filter pdf
pdf = zeros(811);
for m = -40 : 40
for i = 1 : N
if (m <= xpart(i)) && (xpart(i) < m+1)
pdf(m+41) = pdf(m+41) + 1;
end
end
end
figure;
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(xpart)) ‘ ‘ num2str(max(xpart))]);
% Kalman filter pdf
pdf = (1 / sqrt(P) / sqrt(2*pi)) .* exp(-(m - xhat).^2 / 2 / P);
plot(m pdf ‘b‘);
legend(‘Particle filter‘ ‘Kalman filter‘);
end
% Save data in arrays for later plotting
xArr = [xArr x];
yArr = [yArr y];
xhatArr = [xhatArr xhat];
PArr = [PArr P];
xhatPartArr = [xhatPartArr xhatPart];
end
t = 0 : tf;
%figure;
%plot(t xArr);
%ylabel(‘true state‘);
figure;
plot(t xArr ‘b.‘ t xhatArr ‘k-‘ t xhatArr-2*sqrt(PArr) ‘r:‘ t xhatArr+2*sqrt(PArr)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3636 2007-01-14 17:09 粒子滤波 目标跟踪 一维情况下 非线性非高斯\ParticleEx1.m
文件 28672 2008-07-04 10:52 粒子滤波 目标跟踪 一维情况下 非线性非高斯\Doc1.doc
目录 0 2008-07-04 09:50 粒子滤波 目标跟踪 一维情况下 非线性非高斯
----------- --------- ---------- ----- ----
32526 4
- 上一篇:matlab FFT变换
- 下一篇:图像分裂合并的matlab实现.
相关资源
- Rao+ Blackwellized PF
- TDOA/AOA定位的扩展卡尔曼滤波定位算法
- 无迹粒子滤波的matlab实现
- EKF扩展卡尔曼滤波程序
- TDOA_AOA定位的扩展卡尔曼滤波算法MA
- 扩展卡尔曼滤波程序(matlab实现)
- 一维信号前提下粒子滤波器和卡尔曼
- 扩展卡尔曼滤波器的matlab代码
- Particle Filter 粒子滤波 MATLAB程序 Samp
- EKF扩展卡尔曼滤波车身状态估计
- 《粒子滤波原理及应用-MATLAB仿真》程
- 粒子滤波算法 matlab
- 基于扩展卡尔曼滤波的电池soc估计s
- 粒子滤波及其原理黄小平随书代码
- 惯性导航扩展卡尔曼滤波MATLAB
- 正则化粒子滤波matlab程序
- AOA定位的扩展卡尔曼滤波定位算法M
-
扩展卡尔曼滤波SOC算法Simuli
nk模型 - 粒子滤波的基本原理和其在非线性系
- Gaussian Particle Filter 高斯粒子滤波算法
- 最新最完整的Matlab粒子滤波工具箱(
- 姿态确定的扩展卡尔曼滤波Matlab
- 永磁同步电机扩展卡尔曼滤波器.rar
- MATLAB编写的粒子滤波器的源代码
- EKF算法扩展卡尔曼滤波
- PF-EKF 粒子滤波和扩展卡尔曼滤波的对
- pfvsmarginal 粒子滤波与PHD多目标跟踪比
- 1111 卡尔曼滤波、无迹卡尔曼滤波、扩
- EKF 扩展卡尔曼滤波的基础代码
- particle-filter 粒子滤波的改进程序
评论
共有 条评论