1 ## Copyright (C) 2011 Lukas F. Reichlin
3 ## This file is part of LTI Syncope.
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.
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.
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/>.
19 ## @deftypefn{Function File} {[@var{Kr}, @var{info}] =} fwcfconred (@var{G}, @var{F}, @var{L}, @dots{})
20 ## @deftypefnx{Function File} {[@var{Kr}, @var{info}] =} fwcfconred (@var{G}, @var{F}, @var{L}, @var{ncr}, @dots{})
21 ## @deftypefnx{Function File} {[@var{Kr}, @var{info}] =} fwcfconred (@var{G}, @var{F}, @var{L}, @var{opt}, @dots{})
22 ## @deftypefnx{Function File} {[@var{Kr}, @var{info}] =} fwcfconred (@var{G}, @var{F}, @var{L}, @var{ncr}, @var{opt}, @dots{})
24 ## Reduction of state-feedback-observer based controller by frequency-weighted coprime factorization (FW CF).
25 ## Given a plant @var{G}, state feedback gain @var{F} and full observer gain @var{L},
26 ## determine a reduced order controller @var{Kr} by using stability enforcing frequency weights.
31 ## LTI model of the open-loop plant (A,B,C,D).
32 ## It has m inputs, p outputs and n states.
34 ## Stabilizing state feedback matrix (m-by-n).
36 ## Stabilizing observer gain matrix (n-by-p).
38 ## The desired order of the resulting reduced order controller @var{Kr}.
39 ## If not specified, @var{ncr} is chosen automatically according
40 ## to the description of key @var{'order'}.
42 ## Optional pairs of keys and values. @code{"key1", value1, "key2", value2}.
44 ## Optional struct with keys as field names.
45 ## Struct @var{opt} can be created directly or
46 ## by command @command{options}. @code{opt.key1 = value1, opt.key2 = value2}.
52 ## State-space model of reduced order controller.
54 ## Struct containing additional information.
57 ## The Hankel singular values of the extended system?!?.
58 ## The @var{n} Hankel singular values are ordered decreasingly.
60 ## The order of the obtained reduced order controller @var{Kr}.
64 ## @strong{Option Keys and Values}
66 ## @item 'order', 'ncr'
67 ## The desired order of the resulting reduced order controller @var{Kr}.
68 ## If not specified, @var{ncr} is chosen automatically such that states with
69 ## Hankel singular values @var{info.hsv} > @var{tol1} are retained.
72 ## Order reduction approach to be used as follows:
75 ## Use the square-root Balance & Truncate method.
77 ## Use the balancing-free square-root Balance & Truncate method. Default method.
81 ## Specifies whether left or right coprime factorization is
82 ## to be used as follows:
85 ## Use left coprime factorization.
87 ## Use right coprime factorization. Default method.
91 ## Specifies whether @var{F} and @var{L} are fed back positively or negatively:
94 ## A+BK and A+LC are both Hurwitz matrices.
96 ## A-BK and A-LC are both Hurwitz matrices. Default value.
100 ## If @var{'order'} is not specified, @var{tol1} contains the tolerance for
101 ## determining the order of the reduced system.
102 ## For model reduction, the recommended value of @var{tol1} is
103 ## c*info.hsv(1), where c lies in the interval [0.00001, 0.001].
104 ## Default value is n*eps*info.hsv(1).
105 ## If @var{'order'} is specified, the value of @var{tol1} is ignored.
108 ## @strong{Algorithm}@*
109 ## Uses SLICOT SB16CD by courtesy of
110 ## @uref{http://www.slicot.org, NICONET e.V.}
113 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
114 ## Created: December 2011
117 function [Kr, info] = fwcfconred (G, F, L, varargin)
123 if (! isa (G, "lti"))
124 error ("fwcfconred: first argument must be an LTI system");
127 if (! is_real_matrix (F))
128 error ("fwcfconred: second argument must be a real matrix");
131 if (! is_real_matrix (L))
132 error ("fwcfconred: third argument must be a real matrix");
135 if (nargin > 3) # fwcfconred (G, F, L, ...)
136 if (is_real_scalar (varargin{1})) # fwcfconred (G, F, L, nr)
137 varargin = horzcat (varargin(2:end), {"order"}, varargin(1));
139 if (isstruct (varargin{1})) # fwcfconred (G, F, L, opt, ...), fwcfconred (G, F, L, nr, opt, ...)
140 varargin = horzcat (__opt2cell__ (varargin{1}), varargin(2:end));
142 ## order placed at the end such that nr from fwcfconred (G, F, L, nr, ...)
143 ## and fwcfconred (G, F, L, nr, opt, ...) overrides possible nr's from
144 ## key/value-pairs and inside opt struct (later keys override former keys,
145 ## nr > key/value > opt)
148 nkv = numel (varargin); # number of keys and values
151 error ("fwcfconred: keys and values must come in pairs");
154 [a, b, c, d, tsam] = ssdata (G);
162 if (mf != m || nf != n)
163 error ("fwcfconred: dimensions of state-feedback matrix (%dx%d) and plant (%dx%d, %d states) don't match", \
167 if (nl != n || pl != p)
168 error ("fwcfconred: dimensions of observer matrix (%dx%d) and plant (%dx%d, %d states) don't match", \
175 jobmr = 1; # balancing-free BTA
178 negfb = true; # A-BK, A-LC Hurwitz
181 ## handle keys and values
183 key = lower (varargin{k});
186 case {"order", "ncr", "nr"}
187 [ncr, ordsel] = __modred_check_order__ (val, n);
190 tol1 = __modred_check_tol__ (val, "tol1");
193 switch (lower (val(1)))
199 error ("cfconred: '%s' is an invalid coprime factorization", val);
202 case "method" # approximation method
203 switch (tolower (val))
204 case {"sr-bta", "b", "sr"} # 'B': use the square-root Balance & Truncate method
206 case {"bfsr-bta", "f", "bfsr"} # 'F': use the balancing-free square-root Balance & Truncate method
209 error ("cfconred: '%s' is an invalid approach", val);
213 negfb = __conred_check_feedback_sign__ (val);
216 warning ("fwcfconred: invalid property name '%s' ignored", key);
221 ## A - B*F --> A + B*F ; A - L*C --> A + L*C
227 ## perform model order reduction
228 [acr, bcr, ccr, ncr, hsv] = slsb16cd (a, b, c, d, dt, ncr, ordsel, jobd, jobmr, \
231 ## assemble reduced order controller
232 Kr = ss (acr, bcr, ccr, [], tsam);
234 ## assemble info struct
235 info = struct ("ncr", ncr, "hsv", hsv);
240 %!shared Mo, Me, Info, HSVe
241 %! A = [ 0 1.0000 0 0 0 0 0 0
243 %! 0 0 -0.0150 0.7650 0 0 0 0
244 %! 0 0 -0.7650 -0.0150 0 0 0 0
245 %! 0 0 0 0 -0.0280 1.4100 0 0
246 %! 0 0 0 0 -1.4100 -0.0280 0 0
247 %! 0 0 0 0 0 0 -0.0400 1.850
248 %! 0 0 0 0 0 0 -1.8500 -0.040 ];
259 %! C = [ -.996 -.105 0.261 .009 -.001 -.043 0.002 -0.026 ];
263 %! G = ss (A, B, C, D); % "scaled", false
265 %! F = [ 4.472135954999638e-002 6.610515358414598e-001 4.698598960657579e-003 3.601363251422058e-001 1.032530880771415e-001 -3.754055214487997e-002 -4.268536964759344e-002 3.287284547842979e-002 ];
267 %! L = [ 4.108939884667451e-001
268 %! 8.684600000000012e-002
269 %! 3.852317308197148e-004
270 %! -3.619366874815911e-003
271 %! -8.803722876359955e-003
272 %! 8.420521094001852e-003
273 %! 1.234944428038507e-003
274 %! 4.263205617645322e-003 ];
276 %! [Kr, Info] = fwcfconred (G, F, L, 2, "method", "bfsr", "cf", "right", "feedback", "+");
277 %! [Ao, Bo, Co, Do] = ssdata (Kr);
279 %! Ae = [ -0.4334 0.4884
280 %! -0.1950 -0.1093 ];
285 %! Ce = [ -0.0326 -0.2307 ];
289 %! HSVe = [ 3.3073 0.7274 0.1124 0.0784 0.0242 0.0182 0.0101 0.0094 ].';
291 %! Mo = [Ao, Bo; Co, Do];
292 %! Me = [Ae, Be; Ce, De];
294 %!assert (Mo, Me, 1e-4);
295 %!assert (Info.hsv, HSVe, 1e-4);