Revision 7, 0.7 kB
(checked in by smidl, 17 years ago)
|
nefunkcni!!!
|
-
Property svn:eol-style set to
native
-
Property svn:keywords set to
Rev Author Date
|
Line | |
---|
1 | if 0 |
---|
2 | A=[1 -0.5; 1 0]; |
---|
3 | B=[1;0]; |
---|
4 | C=[1 0]; |
---|
5 | D=[0]; |
---|
6 | R=[0.1]; |
---|
7 | Q=[0.2 0 ; 0 0.02]; |
---|
8 | |
---|
9 | sQ = chol(Q)'; |
---|
10 | sR = chol(R)'; |
---|
11 | |
---|
12 | N =1000; |
---|
13 | |
---|
14 | u = ones(1,N); |
---|
15 | x = zeros(2,N); |
---|
16 | y = zeros(1,N); |
---|
17 | |
---|
18 | x(:,1) = [10;10]; |
---|
19 | for i=2:N; |
---|
20 | et(1:2,i) = sQ*randn(2,1); |
---|
21 | x(:,i) = A*x(:,i-1) + B*u(i) + et(:,i); |
---|
22 | y(:,i) = C*x(:,i) + D*u(i) + sR*randn(1,1); |
---|
23 | end |
---|
24 | |
---|
25 | d=[y;u]; |
---|
26 | itsave('testKF.it',d) |
---|
27 | else |
---|
28 | %!cd ../testKF |
---|
29 | |
---|
30 | % init |
---|
31 | mu = [0;0]; |
---|
32 | P = 200*eye(2); |
---|
33 | |
---|
34 | for t=2:N |
---|
35 | mu = A*mu + B*u(t); |
---|
36 | P = A*P*A' + Q; |
---|
37 | |
---|
38 | %Data update |
---|
39 | Ry = C*P*C' + R; |
---|
40 | iRy = inv(Ry); |
---|
41 | K = P*C'*iRy; |
---|
42 | P = P- K*C*P; % P = P -KCP; |
---|
43 | mu = mu + K*(y(t)-C*mu-D*u(t)); |
---|
44 | Mu(1:2,t)=mu; |
---|
45 | end |
---|
46 | |
---|
47 | |
---|
48 | |
---|
49 | itload('testKF_res.it'); |
---|
50 | |
---|
51 | hold off |
---|
52 | plot(x'); |
---|
53 | hold on |
---|
54 | plot(xth','--'); |
---|
55 | plot(Mu',':'); |
---|
56 | end |
---|