1 ## Copyright (C) 2009, 2010, 2011, 2012 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{sv}, @var{w}] =} sigma (@var{sys})
20 ## @deftypefnx{Function File} {[@var{sv}, @var{w}] =} sigma (@var{sys}, @var{w})
21 ## @deftypefnx{Function File} {[@var{sv}, @var{w}] =} sigma (@var{sys}, @var{[]}, @var{ptype})
22 ## @deftypefnx{Function File} {[@var{sv}, @var{w}] =} sigma (@var{sys}, @var{w}, @var{ptype})
23 ## Singular values of frequency response. If no output arguments are given,
24 ## the singular value plot is printed on the screen;
29 ## LTI system. Multiple inputs and/or outputs (MIMO systems) make practical sense.
31 ## Optional vector of frequency values. If @var{w} is not specified,
32 ## it is calculated by the zeros and poles of the system.
33 ## Alternatively, the cell @code{@{wmin, wmax@}} specifies a frequency range,
34 ## where @var{wmin} and @var{wmax} denote minimum and maximum frequencies
37 ## Singular values of the frequency response @var{H} of system @var{sys}. Default Value.
39 ## Singular values of the frequency response @code{inv(H)}; i.e. inversed system.
41 ## Singular values of the frequency response @code{I + H}; i.e. inversed sensitivity
42 ## (or return difference) if @code{H = P * C}.
44 ## Singular values of the frequency response @code{I + inv(H)}; i.e. inversed complementary
45 ## sensitivity if @code{H = P * C}.
51 ## Array of singular values. For a system with m inputs and p outputs, the array sv
52 ## has @code{min (m, p)} rows and as many columns as frequency points @code{length (w)}.
53 ## The singular values at the frequency @code{w(k)} are given by @code{sv(:,k)}.
55 ## Vector of frequency values used.
58 ## @seealso{bodemag, svd}
61 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
65 function [sv_r, w_r] = sigma (sys, w = [], resptype = 0)
67 ## TODO: multiplot feature: sigma (sys1, "b", sys2, "r", ...)
69 if (nargin == 0 || nargin > 3)
73 [H, w] = __frequency_response__ (sys, w, true, resptype, "std", true);
75 sv = cellfun (@svd, H, "uniformoutput", false);
78 if (! nargout) # plot the information
80 ## convert to dB for plotting
81 sv_db = 20 * log10 (sv);
85 xl_str = "Frequency [rad/s]";
87 xl_str = sprintf ("Frequency [rad/s] w_N = %g", pi / get (sys, "tsam"));
91 semilogx (w, sv_db, "b")
93 ylim (__axis_margin__ (ylim))
95 title (["Singular Values of ", inputname(1)])
97 ylabel ("Singular Values [dB]")
100 w_r = reshape (w, [], 1);
106 %!shared sv_exp, w_exp, sv_obs, w_obs
112 %! sv_exp = [7.9176, 8.6275, 9.4393;
113 %! 0.6985, 0.6086, 0.5195];
114 %! w_exp = [2; 3; 4];
115 %! [sv_obs, w_obs] = sigma (ss (A, B, C, D), w);
116 %!assert (sv_obs, sv_exp, 1e-4);
117 %!assert (w_obs, w_exp, 1e-4);