annotate scripts/control/tf2sys.m @ 3397:1a8e2c0d627a

[project @ 1999-12-18 03:02:18 by jwe]
author jwe
date Sat, 18 Dec 1999 03:02:45 +0000
parents 10f21f7ccc7f
children 0f515bc98460
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3397
1a8e2c0d627a [project @ 1999-12-18 03:02:18 by jwe]
jwe
parents: 3385
diff changeset
1 ## Copyright (C) 1996, 1998 Auburn University. All rights reserved.
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
2 ##
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
3 ## This file is part of Octave.
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
4 ##
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
6 ## under the terms of the GNU General Public License as published by the
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
7 ## Free Software Foundation; either version 2, or (at your option) any
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
8 ## later version.
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
9 ##
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but WITHOUT
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
11 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
12 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
13 ## for more details.
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
14 ##
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
15 ## You should have received a copy of the GNU General Public License
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
16 ## along with Octave; see the file COPYING. If not, write to the Free
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
17 ## Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
3346
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
18
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
19 ## -*- texinfo -*-
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
20 ## @deftypefn {Function File } { @var{sys} = } tf2sys( @var{num}, @var{den} @{, @var{tsam}, @var{inname}, @var{outname} @})
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
21 ## build system data structure from transfer function format data
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
22 ##
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
23 ## @strong{Inputs}
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
24 ## @table @var
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
25 ## @item num, den
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
26 ## coefficients of numerator/denominator polynomials
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
27 ## @item tsam
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
28 ## sampling interval. default: 0 (continuous time)
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
29 ## @item inname, outname
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
30 ## input/output signal names; may be a string or list with a single string
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
31 ## entry.
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
32 ## @end table
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
33 ##
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
34 ## @strong{Outputs}
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
35 ## @var{sys} = system data structure
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
36 ##
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
37 ## @strong{Example}
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
38 ## @example
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
39 ## octave:1> sys=tf2sys([2 1],[1 2 1],0.1);
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
40 ## octave:2> sysout(sys)
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
41 ## Input(s)
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
42 ## 1: u_1
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
43 ## Output(s):
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
44 ## 1: y_1 (discrete)
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
45 ## Sampling interval: 0.1
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
46 ## transfer function form:
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
47 ## 2*z^1 + 1
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
48 ## -----------------
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
49 ## 1*z^2 + 2*z^1 + 1
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
50 ## @end example
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
51 ## @end deftypefn
8dd4718801fd [project @ 1999-11-09 18:18:12 by jwe]
jwe
parents: 3284
diff changeset
52
3385
10f21f7ccc7f [project @ 1999-12-15 22:28:26 by jwe]
jwe
parents: 3383
diff changeset
53 function outsys = tf2sys (num, den, tsam, inname, outname)
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
54 ## Written by R. Bruce Tenison July 29, 1994
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
55 ## Name changed to TF2SYS July 1995
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
56 ## updated for new system data structure format July 1996
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
57
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
58 ## Test for the correct number of input arguments
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
59 if ((nargin < 2) || (nargin > 5))
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
60 usage('outsys=tf2sys(num,den[,tsam,inname,outname])');
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
61 return
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
62 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
63
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
64 ## check input format
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
65 if( ! ( (is_vector(num) || is_scalar(num)) && ...
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
66 (is_vector(den) || is_scalar(den))) )
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
67 error(['num (',num2str(rows(num)),'x',num2str(columns(num)), ...
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
68 ') and den (',num2str(rows(den)),'x',num2str(columns(den)), ...
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
69 ') must be vectors'])
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
70 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
71
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
72 ## strip leading zero coefficients
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
73 num = tf2sysl(num);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
74 den = tf2sysl(den);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
75
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
76 if (length(num) > length(den))
3228
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
77 error("# of poles (%d) < # of zeros (%d)",length(den)-1, length(num)-1);
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
78 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
79
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
80 ## check sampling interval (if any)
3228
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
81 if(nargin <= 2) tsam = 0; # default
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
82 elseif (isempty(tsam)) tsam = 0; endif
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
83 if ( (! (is_scalar(tsam) && (imag(tsam) == 0) )) || (tsam < 0) )
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
84 error('tsam must be a positive real scalar')
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
85 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
86
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
87 outsys.num = num;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
88 outsys.den = den;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
89
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
90 ## Set the system vector: active = 0(tf), updated = [1 0 0];
3238
041ea33fbbf4 [project @ 1999-03-26 17:48:16 by jwe]
jwe
parents: 3236
diff changeset
91 outsys.sys = [0, 1, 0, 0];
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
92
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
93 ## Set defaults
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
94 outsys.tsam = tsam;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
95 outsys.n = length(den)-1;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
96 outsys.nz = 0;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
97 outsys.yd = 0; # assume discrete-time
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
98 ## check discrete time
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
99 if(tsam > 0)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
100 [outsys.n,outsys.nz] = swap(outsys.n, outsys.nz);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
101 outsys.yd = 1;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
102 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
103
3228
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
104 outsys.inname = sysdefioname(1,"u");
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
105 outsys.outname = sysdefioname(1,"y");
3228
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
106 outsys.stname = sysdefstname(outsys.n,outsys.nz);
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
107
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
108 ## Set name of input
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
109 if (nargin > 3)
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
110 ## make sure its a list of a single string
3228
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
111 if(!isempty(inname))
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
112 if(!is_list(inname)) inname = list(inname); endif
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
113 if( !is_signal_list(inname) )
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
114 error("inname must be a string or list of strings");
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
115 endif
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
116 if(length(inname) > 1)
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
117 warning("tf2sys: %d input names provided; first used",length(inname));
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
118 inname = inname(1);
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
119 endif
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
120 outsys = syssetsignals(outsys,"in",inname);
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
121 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
122 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
123
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3346
diff changeset
124 ## Set name of output
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
125 if (nargin > 4)
3228
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
126 if(!isempty(outname))
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
127 if(!is_list(outname)) outname = list(outname); endif
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
128 if(!is_signal_list(outname))
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
129 error("outname must be a string or a list of strings");
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
130 endif
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
131 if(length(outname) > 1)
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
132 warning("tf2sys: %d output names provided; first used",length(outname));
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
133 outname = outname(1);
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
134 endif
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
135 outsys = syssetsignals(outsys,"out",outname);
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
136 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
137 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
138
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
139 endfunction