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