1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 1988 - INRIA - C. Bunks
// Copyright (C) DIGITEO - 2011 - Allan CORNET
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution. The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
//
function [x1, y] = system(x0, f, g, h, q, r)
//<x1,y>=system(x0,f,g,h,q,r)
//define system macro which generates the next
//observation given the old state
// x0 :Input state vector
// f :System matrix
// g :Input matrix
// h :Output matrix
// q :Input noise covariance matrix
// r :Output noise covariance matrix
// x1 :Output state vector
// y :Output observation
//System recursively calculates
//
// x1=f*x0+g*u
// y=h*x0+v
//
//where u is distributed N(0,q)
//and v is distribute N(0,r).
[lhs, rhs] = argn(0);
if rhs == 0 then
error(999, msprintf(_("%s: Wrong number of input argument(s).\n"), "system"));
end
rand("normal");
q2 = chol(q);
r2 = chol(r);
u = q2' * rand(ones(x0));
v = r2' * rand(ones(x0));
x1 = f * x0 + g * u;
y = h * x0 + v;
endfunction
|