comparison scripts/control/system/tf2sys.m @ 4771:b8105302cfe8

[project @ 2004-02-16 17:45:50 by jwe]
author jwe
date Mon, 16 Feb 2004 17:45:50 +0000
parents 22bd65326ec1
children bdbee5282954
comparison
equal deleted inserted replaced
4770:ef5e598f099b 4771:b8105302cfe8
1 ## Copyright (C) 1996, 1998 Auburn University. All rights reserved. 1 ## Copyright (C) 1996, 1998, 2004 Auburn University. All rights reserved.
2 ## 2 ##
3 ## This file is part of Octave. 3 ## This file is part of Octave.
4 ## 4 ##
5 ## Octave is free software; you can redistribute it and/or modify it 5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by the 6 ## under the terms of the GNU General Public License as published by the
27 ## coefficients of numerator/denominator polynomials 27 ## coefficients of numerator/denominator polynomials
28 ## @item tsam 28 ## @item tsam
29 ## sampling interval. default: 0 (continuous time) 29 ## sampling interval. default: 0 (continuous time)
30 ## @item inname 30 ## @item inname
31 ## @itemx outname 31 ## @itemx outname
32 ## input/output signal names; may be a string or list with a single string 32 ## input/output signal names; may be a string or cell array with a single string
33 ## entry. 33 ## entry.
34 ## @end table 34 ## @end table
35 ## 35 ##
36 ## @strong{Outputs} 36 ## @strong{Outputs}
37 ## @var{sys} = system data structure 37 ## @var{sys} = system data structure
54 54
55 ## Author: R. Bruce Tenison <btenison@eng.auburn.edu> 55 ## Author: R. Bruce Tenison <btenison@eng.auburn.edu>
56 ## Created: July 29, 1994 56 ## Created: July 29, 1994
57 ## Name changed to TF2SYS July 1995 57 ## Name changed to TF2SYS July 1995
58 ## updated for new system data structure format July 1996 58 ## updated for new system data structure format July 1996
59 ## name changed to tf Feb 2004
59 60
60 function outsys = tf2sys (num, den, tsam, inname, outname) 61 function outsys = tf2sys (varargin)
61 62
62 ## Test for the correct number of input arguments 63 warning("tf2sys is deprecated. Use tf() instead.");
63 if ((nargin < 2) || (nargin > 5)) 64 outsys = tf(varargin{:});
64 usage ("outsys = tf2sys (num, den [, tsam, inname, outname])");
65 return
66 endif
67
68 ## check input format
69 if( ! ( (isvector(num) || isscalar(num)) && ...
70 (isvector(den) || isscalar(den))) )
71 error(["num (",num2str(rows(num)),"x",num2str(columns(num)), ...
72 ") and den (",num2str(rows(den)),"x",num2str(columns(den)), ...
73 ") must be vectors"])
74 endif
75
76 ## strip leading zero coefficients
77 num = __tf2sysl__ (num);
78 den = __tf2sysl__ (den);
79
80 if (length(num) > length(den))
81 error("# of poles (%d) < # of zeros (%d)",length(den)-1, length(num)-1);
82 endif
83
84 ## check sampling interval (if any)
85 if(nargin <= 2) tsam = 0; # default
86 elseif (isempty(tsam)) tsam = 0; endif
87 if ( (! (isscalar(tsam) && (imag(tsam) == 0) )) || (tsam < 0) )
88 error("tsam must be a positive real scalar")
89 endif
90
91 outsys.num = num;
92 outsys.den = den;
93
94 ## Set the system vector: active = 0(tf), updated = [1 0 0];
95 outsys.sys = [0, 1, 0, 0];
96
97 ## Set defaults
98 outsys.tsam = tsam;
99 outsys.n = length(den)-1;
100 outsys.nz = 0;
101 outsys.yd = 0; # assume discrete-time
102 ## check discrete time
103 if(tsam > 0)
104 [outsys.n,outsys.nz] = swap(outsys.n, outsys.nz);
105 outsys.yd = 1;
106 endif
107
108 outsys.inname = __sysdefioname__ (1, "u");
109 outsys.outname = __sysdefioname__ (1, "y");
110 outsys.stname = __sysdefstname__ (outsys.n, outsys.nz);
111
112 ## Set name of input
113 if (nargin > 3)
114 ## make sure its a list of a single string
115 if(!isempty(inname))
116 if(!islist(inname)) inname = list(inname); endif
117 if( !is_signal_list(inname) )
118 error("inname must be a string or list of strings");
119 endif
120 if(length(inname) > 1)
121 warning("tf2sys: %d input names provided; first used",length(inname));
122 inname = inname(1);
123 endif
124 outsys = syssetsignals(outsys,"in",inname);
125 endif
126 endif
127
128 ## Set name of output
129 if (nargin > 4)
130 if(!isempty(outname))
131 if(!islist(outname)) outname = list(outname); endif
132 if(!is_signal_list(outname))
133 error("outname must be a string or a list of strings");
134 endif
135 if(length(outname) > 1)
136 warning("tf2sys: %d output names provided; first used",length(outname));
137 outname = outname(1);
138 endif
139 outsys = syssetsignals(outsys,"out",outname);
140 endif
141 endif
142 65
143 endfunction 66 endfunction