Changeset 9
- Timestamp:
- 01/23/08 13:27:35 (17 years ago)
- Files:
-
- 1 added
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
Makefile
r8 r9 2 2 CPPFLAGS=-g 3 3 4 all: test PF4 all: testKF 5 5 6 6 test: test0 -
matlab/testKF.m
r8 r9 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]; 1 function testKF(skipgen) 2 if nargin<1, skipgen=0; 8 3 9 sQ = chol(Q)'; 10 sR = chol(R)'; 4 if ~skipgen 5 A=[1 -0.5; 1 0]; 6 B=[1;0]; 7 C=[1 0]; 8 D=[0]; 9 R=[0.1]; 10 Q=[0.2 0 ; 0 0.02]; 11 11 12 N =1000; 13 mu0 = [0;0]; 14 P0 = 200*eye(2); 12 sQ = chol(Q)'; 13 sR = chol(R)'; 15 14 16 u = ones(1,N);17 x = zeros(2,N);18 y = zeros(1,N);15 N =1000; 16 mu0 = [0;0]; 17 P0 = 200*eye(2); 19 18 20 x(:,1) = [10;10]; 21 for 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); 19 u = ones(1,N); 20 x = zeros(2,N); 21 y = zeros(1,N); 22 23 x(:,1) = [10;10]; 24 for i=2:N; 25 et(1:2,i) = sQ*randn(2,1); 26 x(:,i) = A*x(:,i-1) + B*u(i) + et(:,i); 27 y(:,i) = C*x(:,i) + D*u(i) + sR*randn(1,1); 28 end 29 30 d=[y;u]; 31 itsave('testKF.it',d,A,B,C,D,Q,R,P0,mu0) 32 save testKF 33 else 34 load testKF 25 35 end 26 27 d=[y;u];28 itsave('testKF.it',d,A,B,C,D,Q,R,P0,mu0)29 save testKF30 else31 %!cd ../testKF32 33 load testKF34 36 % init 35 37 mu = mu0; … … 46 48 K = P*C'*iRy; 47 49 P = P- K*C*P; % P = P -KCP; 48 EP(:,t) = eig(P);49 if any(EP<0), keyboard; end50 50 mu = mu + K*(y(t)-C*mu-D*u(t)); 51 51 Mu(1:2,t)=mu; 52 52 end 53 53 54 55 54 !./testKF 56 55 itload('testKF_res.it'); 57 56 -
testKF.cpp
r8 r9 16 16 mat Mu0;; 17 17 // input from Matlab 18 it_file fin( " matlab/testKF.it" );18 it_file fin( "testKF.it" ); 19 19 mat Dt, Xt,Xt2; 20 20 int Ndat; … … 52 52 // Kmu = KF.mu; 53 53 // cout << "t:" <<t<< " " << dt<<" "<<Kmu <<endl; 54 cout <<t <<endl;55 54 } 56 55 57 it_file fou( " matlab/testKF_res.it" );56 it_file fou( "testKF_res.it" ); 58 57 fou << Name("xth") << Xt; 59 58 fou << Name("xth2") << Xt2;