1 ## Copyright (C) 2009, 2010, 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{gain} =} norm (@var{sys}, @var{2})
20 ## @deftypefnx {Function File} {[@var{gain}, @var{wpeak}] =} norm (@var{sys}, @var{inf})
21 ## @deftypefnx {Function File} {[@var{gain}, @var{wpeak}] =} norm (@var{sys}, @var{inf}, @var{tol})
22 ## Return H-2 or L-inf norm of LTI model.
24 ## @strong{Algorithm}@*
25 ## Uses SLICOT AB13BD and AB13DD by courtesy of
26 ## @uref{http://www.slicot.org, NICONET e.V.}
29 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
30 ## Created: November 2009
33 function [gain, varargout] = norm (sys, ntype = "2", tol = 0.01)
35 if (nargin > 3) # norm () is caught by built-in function
39 if (is_real_scalar (ntype))
42 elseif (isinf (ntype))
45 error ("lti: norm: invalid norm type");
47 elseif (ischar (ntype))
48 ntype = lower (ntype);
50 error ("lti: norm: invalid norm type");
58 [gain, varargout{1}] = linfnorm (sys, tol);
61 error ("lti: norm: invalid norm type");
67 function gain = h2norm (sys)
70 [a, b, c, d] = ssdata (sys);
71 discrete = ! isct (sys);
72 if (! discrete && any (d(:))) # continuous and non-zero feedthrough
75 gain = slab13bd (a, b, c, d, discrete);
84 function [gain, wpeak] = linfnorm (sys, tol = 0.01)
86 [a, b, c, d, e, tsam, scaled] = dssdata (sys, []);
87 discrete = ! isct (sys);
88 tol = max (tol, 100*eps);
91 [fpeak, gpeak] = slab13dd (a, a, b, c, d, discrete, false, tol, scaled); # TODO: avoid dummy argument
98 [fpeak, gpeak] = slab13dd (a, e, b, c, d, discrete, true, tol, scaled);
104 wpeak = fpeak(1) / abs (tsam); # tsam could be -1
123 %! sys = ss (-1, 1, 1, 0);
124 %! H2 = norm (sys, 2);
125 %! Hinf = norm (sys, inf);
126 %!assert (H2, 0.7071, 1.5e-5);
127 %!assert (Hinf, 1, 5e-4);
132 %! a = [ 2.417 -1.002 0.5488
138 %! c = [-0.424 0.436 -0.4552 ];
140 %! sys = ss (a, b, c, d, 0.1);
141 %! H2 = norm (sys, 2);
142 %! Hinf = norm (sys, inf);
143 %!assert (H2, 1.2527, 1.5e-5);
144 %!assert (Hinf, 2.7, 0.1);