-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParticleFilter.asv
72 lines (60 loc) · 1.28 KB
/
ParticleFilter.asv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
function []=ParticleFilter(fwd_Noise,turn_Noise,sense_Noise,turn_Angle,distance,grid_Size,no_Particles,no_Robots,no_Iterations)
d=robot();
d.worldSize=grid_Size;
C=[1,0,0;0,1,0;0,0,1];
N=no_Particles;
for i=1:N
x=robot();
x=x.SetNoise(fwd_Noise,turn_Noise,sense_Noise);
P(i)=x;
clear x;
end
for i=1:N
X(i)=P(i).x;
Y(i)=P(i).y;
O(i)=P(i).orientation;
end
disp(d.eval(P));
for k=1:no_Iterations
scatter(X,Y,10,[C(1,:)]);
set(gca,'XLim',[0,grid_Size],'YLim',[0,grid_Size]);
drawnow;
% linkdata on;
d = d.Move(turn_Angle,distance);
Z = d.Sense();
for i=1:N
P(i)=P(i).Move(turn_Angle,distance);
end
for i=1:N
W(i)=P(i).measurementProb(Z);
end
norm=sum(W);
W=W./norm; %normalized weight array
mW=max(W);
beta=0;
index=randi(N);
for i=1:N
beta=beta+rand(1)*2*mW;
while(beta>W(index))
beta=beta-W(index);
index=index+1;
if(index==N)
index=index-N+1;
end
end
P1(i)=P(index);
end
P=P1;
for i=1:N
X(i)=P(i).x;
Y(i)=P(i).y;
O(i)=P(i).orientation;
end
disp(d.eval(P));
end
for i=1:N
X(i)=P(i).x;
Y(i)=P(i).y;
O(i)=P(i).orientation;
end
end