annotate toolboxes/FullBNT-1.0.7/Kalman/tracking_demo.m @ 0:cc4b1211e677 tip

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