]> Creatis software - CreaPhase.git/blob - octave_packages/control-2.3.52/estim.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / control-2.3.52 / estim.m
1 ## Copyright (C) 2009, 2010   Lukas F. Reichlin
2 ##
3 ## This file is part of LTI Syncope.
4 ##
5 ## LTI Syncope is free software: you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation, either version 3 of the License, or
8 ## (at your option) any later version.
9 ##
10 ## LTI Syncope is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 ## GNU General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with LTI Syncope.  If not, see <http://www.gnu.org/licenses/>.
17
18 ## -*- texinfo -*-
19 ## @deftypefn {Function File} {@var{est} =} estim (@var{sys}, @var{l})
20 ## @deftypefnx {Function File} {@var{est} =} estim (@var{sys}, @var{l}, @var{sensors}, @var{known})
21 ## Return state estimator for a given estimator gain.
22 ##
23 ## @strong{Inputs}
24 ## @table @var
25 ## @item sys
26 ## LTI model.
27 ## @item l
28 ## State feedback matrix.
29 ## @item sensors
30 ## Indices of measured output signals y from @var{sys}.  If omitted, all outputs are measured.
31 ## @item known
32 ## Indices of known input signals u (deterministic) to @var{sys}.  All other inputs to @var{sys}
33 ## are assumed stochastic.  If argument @var{known} is omitted, no inputs u are known.
34 ## @end table
35 ##
36 ## @strong{Outputs}
37 ## @table @var
38 ## @item est
39 ## State-space model of estimator.
40 ## @end table
41 ## @seealso{kalman, place}
42 ## @end deftypefn
43
44 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
45 ## Created: November 2009
46 ## Version: 0.2
47
48 function est = estim (sys, l, sensors = [], known = [])
49
50   if (nargin < 2 || nargin > 4)
51     print_usage ();
52   endif
53
54   if (! isa (sys, "lti"))
55     error ("estim: first argument must be an LTI system");
56   endif
57
58   [a, b, c, d, e, tsam] = dssdata (sys, []);
59
60   if (isempty (sensors))
61     sensors = 1 : rows (c);
62   endif
63
64   m = length (known);
65   n = rows (a);
66   p = length (sensors);
67
68   b = b(:, known);
69   c = c(sensors, :);
70   d = d(sensors, known);
71
72   f = a - l*c;
73   g = [b - l*d, l];
74   h = [c; eye(n)];
75   j = [d, zeros(p, p); zeros(n, m), zeros(n, p)];
76   ## k = e;
77
78   est = dss (f, g, h, j, e, tsam);
79
80   ## TODO: inname, stname, outname
81
82 endfunction
83
84
85 %!shared m, m_exp
86 %! sys = ss (-2, 1, 1, 3);
87 %! est = estim (sys, 5);
88 %! [a, b, c, d] = ssdata (est);
89 %! m = [a, b; c, d];
90 %! m_exp = [-7, 5; 1, 0; 1, 0];
91 %!assert (m, m_exp, 1e-4);
92
93 %!shared m, m_exp
94 %! sys = ss (-1, 2, 3, 4);
95 %! est = estim (sys, 5);
96 %! [a, b, c, d] = ssdata (est);
97 %! m = [a, b; c, d];
98 %! m_exp = [-16, 5; 3, 0; 1, 0];
99 %!assert (m, m_exp, 1e-4);