annotate scripts/control/system/dmr2d.m @ 5307:4c8a2e4e0717

[project @ 2005-04-26 19:24:27 by jwe]
author jwe
date Tue, 26 Apr 2005 19:24:47 +0000
parents 9f7ef92b50b0
children ec8c33dcd1bf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
1 ## Copyright (C) 1998 Auburn University. All rights reserved.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
2 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
4 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by the
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
7 ## Free Software Foundation; either version 2, or (at your option) any
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
8 ## later version.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
9 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but WITHOUT
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
11 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
12 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
13 ## for more details.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
14 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, write to the Free
5307
4c8a2e4e0717 [project @ 2005-04-26 19:24:27 by jwe]
jwe
parents: 4844
diff changeset
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
4c8a2e4e0717 [project @ 2005-04-26 19:24:27 by jwe]
jwe
parents: 4844
diff changeset
18 ## 02110-1301 USA.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
19
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
20 ## -*- texinfo -*-
3502
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3500
diff changeset
21 ## @deftypefn {Function File} {[@var{dsys}, @var{fidx}] =} dmr2d (@var{sys}, @var{idx}, @var{sprefix}, @var{ts2}, @var{cuflg})
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
22 ## convert a multirate digital system to a single rate digital system
3502
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3500
diff changeset
23 ## states specified by @var{idx}, @var{sprefix} are sampled at @var{ts2}, all
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3500
diff changeset
24 ## others are assumed sampled at @var{ts1} = @code{sysgettsam (@var{sys})}.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
25 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
26 ## @strong{Inputs}
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
27 ## @table @var
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
28 ## @item sys
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
29 ## discrete time system;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
30 ## @code{dmr2d} exits with an error if @var{sys} is not discrete
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
31 ## @item idx
3462
04aef7306dca [project @ 2000-01-19 17:16:43 by hodelas]
hodelas
parents: 3431
diff changeset
32 ## indices or names of states with sampling time
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4771
diff changeset
33 ## @code{sysgettsam(@var{sys})} (may be empty); see @code{cellidx}
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
34 ## @item sprefix
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
35 ## list of string prefixes of states with sampling time
3462
04aef7306dca [project @ 2000-01-19 17:16:43 by hodelas]
hodelas
parents: 3431
diff changeset
36 ## @code{sysgettsam(@var{sys})} (may be empty)
3502
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3500
diff changeset
37 ## @item ts2
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
38 ## sampling time of states not specified by @var{idx}, @var{sprefix}
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
39 ## must be an integer multiple of @code{sysgettsam(@var{sys})}
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
40 ## @item cuflg
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
41 ## "constant u flag" if @var{cuflg} is nonzero then the system inputs are
3502
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3500
diff changeset
42 ## assumed to be constant over the revised sampling interval @var{ts2}.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
43 ## Otherwise, since the inputs can change during the interval
3502
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3500
diff changeset
44 ## @var{t} in @math{[k ts2, (k+1) ts2]}, an additional set of inputs is
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
45 ## included in the revised B matrix so that these intersample inputs
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
46 ## may be included in the single-rate system.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
47 ## default @var{cuflg} = 1.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
48 ## @end table
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
49 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
50 ## @strong{Outputs}
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
51 ## @table @var
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
52 ## @item dsys
3502
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3500
diff changeset
53 ## equivalent discrete time system with sampling time @var{ts2}.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
54 ##
3502
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3500
diff changeset
55 ## The sampling time of sys is updated to @var{ts2}.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
56 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
57 ## if @var{cuflg}=0 then a set of additional inputs is added to
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
58 ## the system with suffixes _d1, ..., _dn to indicate their
3502
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3500
diff changeset
59 ## delay from the starting time k @var{ts2}, i.e.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
60 ## u = [u_1; u_1_d1; ..., u_1_dn] where u_1_dk is the input
3502
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3500
diff changeset
61 ## k*ts1 units of time after u_1 is sampled. (@var{ts1} is
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3500
diff changeset
62 ## the original sampling time of the discrete time system and
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3500
diff changeset
63 ## @var{ts2} = (n+1)*ts1)
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
64 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
65 ## @item fidx
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
66 ## indices of "formerly fast" states specified by @var{idx} and @var{sprefix};
3502
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3500
diff changeset
67 ## these states are updated to the new (slower) sampling interval @var{ts2}.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
68 ## @end table
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
69 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
70 ## @strong{WARNING} Not thoroughly tested yet; especially when
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
71 ## @var{cuflg} == 0.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
72 ## @end deftypefn
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
73
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
74 ## Adapted from c2d by a.s.hodel@eng.auburn.edu
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
75
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
76 function [dsys, fidx] = dmr2d (sys, idx, sprefix, Ts2, cuflg)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
77
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
78 ## parse input arguments
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
79 if(nargin != 4 | nargout > 2)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
80 usage("[dsys,fidx] = dmr2d (sys, idx, sprefix, Ts2 {,cuflg})");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
81
4030
22bd65326ec1 [project @ 2002-08-09 18:58:13 by jwe]
jwe
parents: 3502
diff changeset
82 elseif (!isstruct(sys))
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
83 error("sys must be in system data structure form");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
84
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
85 elseif(!is_digital(sys))
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
86 error("sys must be discrete-time; continuous time passed");
3462
04aef7306dca [project @ 2000-01-19 17:16:43 by hodelas]
hodelas
parents: 3431
diff changeset
87
04aef7306dca [project @ 2000-01-19 17:16:43 by hodelas]
hodelas
parents: 3431
diff changeset
88 endif
04aef7306dca [project @ 2000-01-19 17:16:43 by hodelas]
hodelas
parents: 3431
diff changeset
89
04aef7306dca [project @ 2000-01-19 17:16:43 by hodelas]
hodelas
parents: 3431
diff changeset
90 if(is_signal_list(idx) | isstr(idx))
04aef7306dca [project @ 2000-01-19 17:16:43 by hodelas]
hodelas
parents: 3431
diff changeset
91 idx = sysidx(sys,"st",idx);
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
92
4030
22bd65326ec1 [project @ 2002-08-09 18:58:13 by jwe]
jwe
parents: 3502
diff changeset
93 elseif (!(isvector(idx) | isempty(idx)))
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
94 error(["idx(",num2str(rows(idx)),"x",num2str(columns(idx)), ...
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
95 ") must be a vector"]);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
96
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
97 elseif (any(idx <= 0))
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
98 idv = find(idx <= 0);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
99 ii = idv(1);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
100 error(["idx(",num2str(ii),")=",num2str(idx(ii)), ...
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
101 "; entries of idx must be positive"]);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
102
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
103 elseif(!(is_signal_list(sprefix) | isempty(sprefix)))
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
104 error("sprefix must be a signal list (see is_signal_list) or empty");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
105
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
106 elseif(!is_sample(Ts2))
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
107 error(["Ts2=",num2str(Ts2),"; invalid sampling time"]);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
108
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
109 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
110
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
111 ## optional argument: cuflg
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
112 if(nargin <= 4)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
113 cuflg = 1; # default: constant inputs over Ts2 sampling interv.
4030
22bd65326ec1 [project @ 2002-08-09 18:58:13 by jwe]
jwe
parents: 3502
diff changeset
114 elseif( !isscalar(cuflg) )
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
115 error("cuflg must be a scalar")
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
116 elseif( cuflg != 0 | cuflg != 1)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
117 error(["cuflg = ",num2str(cuflg),", should be 0 or 1"]);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
118 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
119
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
120 ## extract state space information
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
121 [da,db,dc,dd,Ts1,nc,nz,stname,inname,outname,yd] = sys2ss(sys);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
122
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
123 ## compute number of steps
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
124 if(Ts1 > Ts2)
3462
04aef7306dca [project @ 2000-01-19 17:16:43 by hodelas]
hodelas
parents: 3431
diff changeset
125 error(["Current sampling time=",num2str(Ts1)," > Ts2=",num2str(Ts2)]);
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
126 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
127 nstp = floor(Ts2/Ts1+0.5);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
128 if(abs((Ts2 - Ts1*nstp)/Ts1) > 1e-12)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
129 warning(["dmr2d: Ts1=",num2str(Ts1),", Ts2=",num2str(Ts2), ...
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
130 ", selecting nsteps=",num2str(nstp),"; mismatch"]);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
131 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
132
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
133 if(isempty(sprefix) & isempty(idx))
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
134 warning("both sprefix and idx are empty; returning dsys=sys");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
135 fidx = [];
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
136 dsys = sys;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
137 return
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
138 elseif(isempty(sprefix))
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
139 fidx = idx;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
140 else
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
141 fidx = reshape(idx,1,length(idx));
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
142 ## find states whose name begins with any strings in sprefix.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
143 ns = length(sprefix);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
144 for kk=1:ns
4771
b8105302cfe8 [project @ 2004-02-16 17:45:50 by jwe]
jwe
parents: 4030
diff changeset
145 spk = sprefix{kk}; # get next prefix and length
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
146 spl = length(spk);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
147
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
148 ## check each state name
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
149 for ii=1:nz
4771
b8105302cfe8 [project @ 2004-02-16 17:45:50 by jwe]
jwe
parents: 4030
diff changeset
150 sti = stname{ii}; # compare spk with this state name
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
151 if(length(sti) >= spl)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
152 ## if the prefix matches and ii isn't already in the list, add ii
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
153 if(strcmp(sti(1:spl),spk) & !any(fidx == ii) )
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
154 fidx = sort([fidx,ii]);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
155 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
156 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
157 endfor
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
158 endfor
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
159 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
160
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
161 if(nstp == 0)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
162 warning("dmr2d: nstp = 0; setting tsam and returning");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
163 dsys = syschtsam(sys,Ts2);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
164 return
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
165 elseif(nstp < 0)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
166 error(["nstp = ", num2str(nstp)," < 0; this shouldn't be!"]);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
167 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
168
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
169 ## permute system matrices
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
170 pv = sysreorder(nz,fidx);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
171 pv = pv(nz:-1:1); # reverse order to put fast modes in leading block
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
172
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
173 ## construct inverse permutation
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
174 Inz = eye(nz);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
175 pvi = (Inz(pv,:)'*[1:nz]')';
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
176
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
177 ## permute A, B (stname permuted for debugging only)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
178 da = da(pv,pv);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
179 db = db(pv,:);
3462
04aef7306dca [project @ 2000-01-19 17:16:43 by hodelas]
hodelas
parents: 3431
diff changeset
180 stname = stname(pv);
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
181
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
182 ## partition A, B:
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
183 lfidx = length(fidx);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
184 bki = 1:lfidx;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
185 a11 = da(bki,bki);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
186 b1 = db(bki,:);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
187
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
188 if(lfidx < nz)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
189 lfidx1 = lfidx+1;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
190 bki2 = (lfidx1):nz;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
191 a12 = da(bki,bki2);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
192 b2 = db(bki2,:);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
193 else
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
194 warning("dmr2d: converting entire A,B matrices to new sampling rate");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
195 lfidx1 = -1;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
196 bki2 = [];
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
197 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
198
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
199 ## begin system conversion: nstp steps
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
200
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
201 ## compute abar_{n-1}*a12 and appropriate b matrix stuff
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
202 a12b = a12; # running total of abar_{n-1}*a12
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
203 a12w = a12; # current a11^n*a12 (start with n = 0)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
204 if(cuflg)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
205 b1b = b1;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
206 b1w = b1;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
207 else
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
208 ## cuflg == 0, need to keep track of intersample inputs too
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
209 nzdx = find(max(abs(b1)) != 0); # FIXME: check tolerance relative to ||b1||
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
210 b1w = b1(nzdx);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
211 innamenz = inname(nzdx);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
212 b1b = b1; # initial b1 must match columns in b2
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
213 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
214
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
215 ## compute a11h = a11^nstp by squaring
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
216 a11h = eye(size(a11));
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
217 p2 = 1;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
218 a11p2 = a11; #a11^p2
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
219
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
220 nstpw = nstp; # workspace for computing a11^nstp
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
221 while(nstpw > 0.5)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
222 oddv = rem(nstpw,2);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
223 if(oddv)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
224 a11h = a11h*a11p2;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
225 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
226 nstpw = (nstpw-oddv)/2;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
227 if(nstpw > 0.5)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
228 a11p2 = a11p2*a11p2; # a11^(next power of 2)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
229 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
230 endwhile
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
231
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
232 ## FIXME: this part should probably also use squaring, but
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
233 ## that would require exponentially growing memory. What do do?
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
234 for kk=2:nstp
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
235 ## update a12 block to sum(a12 + ... + a11^(kk-1)*a12)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
236 a12w = a11*a12w;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
237 a12b = a12b + a12w;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
238
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
239 ## similar for b1 block (checking for cuflg first!)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
240 b1w = a11*b1w;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
241 if(cuflg)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
242 b1b = b1b + b1w; # update b1 block just like we did a12
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
243 else
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
244 b1b = [b1b, b1w]; # append new inputs
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
245 newin = strappend(innamenz,["_d",num2str(kk-1)]);
4771
b8105302cfe8 [project @ 2004-02-16 17:45:50 by jwe]
jwe
parents: 4030
diff changeset
246 inname = __sysconcat__(inname,newin);
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
247 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
248 endfor
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
249
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
250 ## reconstruct system and return
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
251 da(bki,bki) = a11h;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
252 db(bki,1:columns(b1b)) = b1b;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
253 if(!isempty(bki2))
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
254 da(bki,bki2) = a12b;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
255 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
256
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
257 da = da(pvi,pvi);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
258 db = db(pvi,:);
3462
04aef7306dca [project @ 2000-01-19 17:16:43 by hodelas]
hodelas
parents: 3431
diff changeset
259 stname = stname(pvi);
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
260
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
261 ## construct new system and return
4771
b8105302cfe8 [project @ 2004-02-16 17:45:50 by jwe]
jwe
parents: 4030
diff changeset
262 dsys = ss(da,db,dc,dd,Ts2,0,nz,stname,inname,outname,find(yd == 1));
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
263
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
264 endfunction