comparison toolboxes/FullBNT-1.0.7/Kalman/tracking_demo.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 % Make a point move in the 2D plane
2 % State = (x y xdot ydot). We only observe (x y).
3
4 % This code was used to generate Figure 15.9 of "Artificial Intelligence: a Modern Approach",
5 % Russell and Norvig, 2nd edition, Prentice Hall, 2003.
6
7 % X(t+1) = F X(t) + noise(Q)
8 % Y(t) = H X(t) + noise(R)
9
10 ss = 4; % state size
11 os = 2; % observation size
12 F = [1 0 1 0; 0 1 0 1; 0 0 1 0; 0 0 0 1];
13 H = [1 0 0 0; 0 1 0 0];
14 Q = 0.1*eye(ss);
15 R = 1*eye(os);
16 initx = [10 10 1 0]';
17 initV = 10*eye(ss);
18
19 seed = 9;
20 rand('state', seed);
21 randn('state', seed);
22 T = 15;
23 [x,y] = sample_lds(F, H, Q, R, initx, T);
24
25 [xfilt, Vfilt, VVfilt, loglik] = kalman_filter(y, F, H, Q, R, initx, initV);
26 [xsmooth, Vsmooth] = kalman_smoother(y, F, H, Q, R, initx, initV);
27
28 dfilt = x([1 2],:) - xfilt([1 2],:);
29 mse_filt = sqrt(sum(sum(dfilt.^2)))
30
31 dsmooth = x([1 2],:) - xsmooth([1 2],:);
32 mse_smooth = sqrt(sum(sum(dsmooth.^2)))
33
34
35 figure(1)
36 clf
37 %subplot(2,1,1)
38 hold on
39 plot(x(1,:), x(2,:), 'ks-');
40 plot(y(1,:), y(2,:), 'g*');
41 plot(xfilt(1,:), xfilt(2,:), 'rx:');
42 for t=1:T, plotgauss2d(xfilt(1:2,t), Vfilt(1:2, 1:2, t)); end
43 hold off
44 legend('true', 'observed', 'filtered', 3)
45 xlabel('x')
46 ylabel('y')
47
48
49
50 % 3x3 inches
51 set(gcf,'units','inches');
52 set(gcf,'PaperPosition',[0 0 3 3])
53 %print(gcf,'-depsc','/home/eecs/murphyk/public_html/Bayes/Figures/aima_filtered.eps');
54 %print(gcf,'-djpeg','-r100', '/home/eecs/murphyk/public_html/Bayes/Figures/aima_filtered.jpg');
55
56
57 figure(2)
58 %subplot(2,1,2)
59 hold on
60 plot(x(1,:), x(2,:), 'ks-');
61 plot(y(1,:), y(2,:), 'g*');
62 plot(xsmooth(1,:), xsmooth(2,:), 'rx:');
63 for t=1:T, plotgauss2d(xsmooth(1:2,t), Vsmooth(1:2, 1:2, t)); end
64 hold off
65 legend('true', 'observed', 'smoothed', 3)
66 xlabel('x')
67 ylabel('y')
68
69
70 % 3x3 inches
71 set(gcf,'units','inches');
72 set(gcf,'PaperPosition',[0 0 3 3])
73 %print(gcf,'-djpeg','-r100', '/home/eecs/murphyk/public_html/Bayes/Figures/aima_smoothed.jpg');
74 %print(gcf,'-depsc','/home/eecs/murphyk/public_html/Bayes/Figures/aima_smoothed.eps');