mirror of
https://github.com/introlab/rtabmap.git
synced 2026-09-02 17:40:23 +08:00
updated pf_filter.m
This commit is contained in:
@@ -1,17 +1,24 @@
|
|||||||
|
|
||||||
function filtered = pf_filter(x, nParticles, noise, lambda)
|
function filtered = pf_filter(x, nParticles, noise, lambda)
|
||||||
|
|
||||||
particles = zeros(nParticles,1) ;
|
particles = ones(nParticles,1)*x(1) ;
|
||||||
weights = zeros(nParticles,1);
|
weights = ones(nParticles,1);
|
||||||
filtered=zeros(1,length(x));
|
filtered=zeros(1,length(x));
|
||||||
for i = 1:length(x);
|
for i = 1:length(x);
|
||||||
for j = 1:nParticles
|
for j = 1:nParticles
|
||||||
rn = sqrt(-2.0*log(rand))*cos(2*pi*rand); % randn c++
|
rn = sqrt(-2.0*log(rand))*cos(2*pi*rand); % randn c++
|
||||||
particles(j) = particles(j) + noise*rn ;
|
noisyP = particles(j) + noise*rn ;
|
||||||
dist = abs(particles(j) - x(i));
|
dist = abs(noisyP - x(i));
|
||||||
weights(j) = exp(-lambda*dist);
|
tmp = exp(-lambda*dist);
|
||||||
|
if isfinite(tmp) && tmp > 0
|
||||||
|
particles(j) = noisyP;
|
||||||
|
weights(j) = tmp;
|
||||||
|
end
|
||||||
end
|
end
|
||||||
weights = weights ./(sum(weights(:)));
|
if sum(weights(:)) > 0
|
||||||
|
weights = weights ./sum(weights(:));
|
||||||
|
end
|
||||||
|
|
||||||
filtered(i) = weights'*particles;
|
filtered(i) = weights'*particles;
|
||||||
particles = pf_resample(particles, weights);
|
particles = pf_resample(particles, weights);
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user