root/matlab/testKF.m @ 8

Revision 8, 0.8 kB (checked in by smidl, 16 years ago)

Kalmany funkci, PF nefunkci

  • Property svn:eol-style set to native
  • Property svn:keywords set to Rev Author Date
Line 
1if 0
2A=[1 -0.5; 1 0];
3B=[1;0];
4C=[1 0];
5D=[0];
6R=[0.1];
7Q=[0.2 0 ; 0 0.02];
8
9sQ = chol(Q)';
10sR = chol(R)';
11
12N =1000;
13mu0 = [0;0];
14P0 = 200*eye(2);
15
16u = ones(1,N);
17x = zeros(2,N);
18y = zeros(1,N);
19
20x(:,1) = [10;10];
21for i=2:N;
22        et(1:2,i) = sQ*randn(2,1);
23        x(:,i) = A*x(:,i-1) + B*u(i) + et(:,i);
24        y(:,i) = C*x(:,i) + D*u(i) + sR*randn(1,1);
25end
26
27d=[y;u];
28itsave('testKF.it',d,A,B,C,D,Q,R,P0,mu0)
29save testKF
30else
31%!cd ../testKF
32
33load testKF
34% init
35mu = mu0;
36P = P0;
37EP = [0;0];
38
39for t=2:N
40        mu = A*mu + B*u(t);
41        P  = A*P*A' + Q;
42
43        %Data update
44        Ry = C*P*C' + R;
45        iRy = inv(Ry);
46        K = P*C'*iRy;
47        P = P- K*C*P; % P = P -KCP;
48        EP(:,t) = eig(P);
49        if any(EP<0), keyboard; end
50        mu = mu + K*(y(t)-C*mu-D*u(t));
51        Mu(1:2,t)=mu;
52end
53
54
55
56itload('testKF_res.it');
57
58hold off
59plot(x');
60hold on
61plot(xth','--');
62plot(xth2','+');
63plot(Mu',':');
64end
Note: See TracBrowser for help on using the browser.