1 ## Copyright (C) 2012 Lukas F. Reichlin
2 ## Copyright (C) 2012 Megan Zagrobelny
4 ## This file is part of LTI Syncope.
6 ## LTI Syncope is free software: you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation, either version 3 of the License, or
9 ## (at your option) any later version.
11 ## LTI Syncope is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ## GNU General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with LTI Syncope. If not, see <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {[@var{l}, @var{p}, @var{e}] =} lqe (@var{sys}, @var{q}, @var{r})
21 ## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{e}] =} lqe (@var{sys}, @var{q}, @var{r}, @var{s})
22 ## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{e}] =} lqe (@var{a}, @var{g}, @var{c}, @var{q}, @var{r})
23 ## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{e}] =} lqe (@var{a}, @var{g}, @var{c}, @var{q}, @var{r}, @var{s})
24 ## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{e}] =} lqe (@var{a}, @var{[]}, @var{c}, @var{q}, @var{r})
25 ## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{e}] =} lqe (@var{a}, @var{[]}, @var{c}, @var{q}, @var{r}, @var{s})
26 ## Kalman filter for continuous-time systems.
31 ## x = Ax + Bu + Gw (State equation)
32 ## y = Cx + Du + v (Measurement Equation)
33 ## E(w) = 0, E(v) = 0, cov(w) = Q, cov(v) = R, cov(w,v) = S
40 ## Continuous or discrete-time LTI model (p-by-m, n states).
42 ## State transition matrix of continuous-time system (n-by-n).
44 ## Process noise matrix of continuous-time system (n-by-g).
45 ## If @var{g} is empty @code{[]}, an identity matrix is assumed.
47 ## Measurement matrix of continuous-time system (p-by-n).
49 ## Process noise covariance matrix (g-by-g).
51 ## Measurement noise covariance matrix (p-by-p).
53 ## Optional cross term covariance matrix (g-by-p), s = cov(w,v).
54 ## If @var{s} is empty @code{[]} or not specified, a zero matrix is assumed.
60 ## Kalman filter gain matrix (n-by-p).
62 ## Unique stabilizing solution of the continuous-time Riccati equation (n-by-n).
63 ## Symmetric matrix. If @var{sys} is a discrete-time model, the solution of the
64 ## corresponding discrete-time Riccati equation is returned.
66 ## Closed-loop poles (n-by-1).
73 ## x = Ax + Bu + L(y - Cx -Du)
79 ## @seealso{dare, care, dlqr, lqr, dlqe}
82 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
83 ## Created: April 2012
86 function [l, p, e] = lqe (a, g, c, q = [], r = [], s = [])
88 if (nargin < 3 || nargin > 6)
93 [l, p, e] = lqr (a.', g, c, q); # lqe (sys, q, r, s), g=I, works like lqr (sys.', q, r, s).'
95 [l, p, e] = lqr (a.', c.', q, r, s); # lqe (a, [], c, q, r, s), g=I, works like lqr (a.', c.', q, r, s).'
96 elseif (columns (g) != rows (q) || ! issquare (q))
97 error ("lqe: matrices g(%dx%d) and q(%dx%d) have incompatible dimensions", \
98 rows (g), columns (g), rows (q), columns (q));
100 [l, p, e] = lqr (a.', c.', g*q*g.', r);
101 elseif (columns (g) != rows (s))
102 error ("lqe: matrices g(%dx%d) and s(%dx%d) have incompatible dimensions", \
103 rows (g), columns (g), rows (s), columns (s));
105 [l, p, e] = lqr (a.', c.', g*q*g.', r, g*s);
110 ## NOTE: for discrete-time sys, the solution L' from DARE
111 ## is different to L from DLQE (a, s)