7017
|
1 ## Copyright (C) 1996, 1998, 2004, 2005, 2006, 2007 |
|
2 ## Auburn University. All rights reserved. |
4779
|
3 ## |
|
4 ## This file is part of Octave. |
|
5 ## |
|
6 ## Octave is free software; you can redistribute it and/or modify it |
7016
|
7 ## under the terms of the GNU General Public License as published by |
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
|
9 ## your option) any later version. |
4779
|
10 ## |
7016
|
11 ## Octave is distributed in the hope that it will be useful, but |
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 ## General Public License for more details. |
4779
|
15 ## |
|
16 ## You should have received a copy of the GNU General Public License |
7016
|
17 ## along with Octave; see the file COPYING. If not, see |
|
18 ## <http://www.gnu.org/licenses/>. |
4779
|
19 |
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} tf (@var{num}, @var{den}, @var{tsam}, @var{inname}, @var{outname}) |
|
22 ## build system data structure from transfer function format data |
|
23 ## |
|
24 ## @strong{Inputs} |
|
25 ## @table @var |
|
26 ## @item num |
|
27 ## @itemx den |
|
28 ## coefficients of numerator/denominator polynomials |
|
29 ## @item tsam |
|
30 ## sampling interval. default: 0 (continuous time) |
|
31 ## @item inname |
|
32 ## @itemx outname |
|
33 ## input/output signal names; may be a string or cell array with a single string |
|
34 ## entry. |
|
35 ## @end table |
|
36 ## |
|
37 ## @strong{Outputs} |
|
38 ## @var{sys} = system data structure |
|
39 ## |
|
40 ## @strong{Example} |
|
41 ## @example |
|
42 ## octave:1> sys=tf([2 1],[1 2 1],0.1); |
|
43 ## octave:2> sysout(sys) |
|
44 ## Input(s) |
|
45 ## 1: u_1 |
|
46 ## Output(s): |
|
47 ## 1: y_1 (discrete) |
|
48 ## Sampling interval: 0.1 |
|
49 ## transfer function form: |
|
50 ## 2*z^1 + 1 |
|
51 ## ----------------- |
|
52 ## 1*z^2 + 2*z^1 + 1 |
|
53 ## @end example |
|
54 ## @end deftypefn |
|
55 |
|
56 ## Author: R. Bruce Tenison <btenison@eng.auburn.edu> |
|
57 ## Created: July 29, 1994 |
|
58 ## Name changed to TF2SYS July 1995 |
|
59 ## updated for new system data structure format July 1996 |
|
60 |
|
61 function outsys = tf (num, den, tsam, inname, outname) |
|
62 |
|
63 ## Test for the correct number of input arguments |
7135
|
64 if (nargin < 2 || nargin > 5) |
6046
|
65 print_usage (); |
4779
|
66 endif |
|
67 |
|
68 ## check input format |
7135
|
69 if (! ((isvector (num) || isscalar (num)) |
|
70 && (isvector (den) || isscalar (den)))) |
|
71 error ("num (%dx%d) and den (%dx%d) must be vectors", |
|
72 rows (num), columns (num), rows (den), columns (den)); |
4779
|
73 endif |
|
74 |
|
75 ## strip leading zero coefficients |
|
76 num = __tfl__ (num); |
|
77 den = __tfl__ (den); |
|
78 |
7135
|
79 if (length (num) > length (den)) |
|
80 error ("# of poles (%d) < # of zeros (%d)", length(den)-1, length(num)-1); |
4779
|
81 endif |
|
82 |
|
83 ## check sampling interval (if any) |
7135
|
84 if (nargin <= 2) |
|
85 tsam = 0; # default |
|
86 elseif (isempty (tsam)) |
|
87 tsam = 0; |
|
88 endif |
|
89 if (! (isscalar (tsam) && imag (tsam) == 0) || tsam < 0) |
|
90 error ("tsam must be a positive real scalar") |
4779
|
91 endif |
|
92 |
|
93 outsys.num = num; |
|
94 outsys.den = den; |
|
95 |
|
96 ## Set the system vector: active = 0(tf), updated = [1 0 0]; |
|
97 outsys.sys = [0, 1, 0, 0]; |
|
98 |
|
99 ## Set defaults |
|
100 outsys.tsam = tsam; |
7135
|
101 outsys.n = length (den) - 1; |
4779
|
102 outsys.nz = 0; |
|
103 outsys.yd = 0; # assume discrete-time |
|
104 ## check discrete time |
7135
|
105 if (tsam > 0) |
|
106 [outsys.n, outsys.nz] = swap (outsys.n, outsys.nz); |
4779
|
107 outsys.yd = 1; |
|
108 endif |
|
109 |
|
110 outsys.inname = __sysdefioname__ (1, "u"); |
|
111 outsys.outname = __sysdefioname__ (1, "y"); |
|
112 outsys.stname = __sysdefstname__ (outsys.n, outsys.nz); |
|
113 |
|
114 ## Set name of input |
|
115 if (nargin > 3) |
|
116 ## make sure it's a cell array of a single string |
7135
|
117 if (! isempty (inname)) |
|
118 if (! iscell (inname)) |
|
119 inname = {inname}; |
4779
|
120 endif |
7135
|
121 if (! is_signal_list (inname)) |
|
122 error ("inname must be a string or cell array of strings"); |
|
123 endif |
|
124 if (length (inname) > 1) |
|
125 warning ("tf: %d input names provided; first used", length (inname)); |
4779
|
126 inname = inname(1); |
|
127 endif |
7135
|
128 outsys = syssetsignals (outsys, "in", inname); |
4779
|
129 endif |
|
130 endif |
|
131 |
|
132 ## Set name of output |
|
133 if (nargin > 4) |
7135
|
134 if (! isempty (outname)) |
|
135 if (! iscell (outname)) |
|
136 outname = {outname}; |
4779
|
137 endif |
7135
|
138 if (! is_signal_list (outname)) |
|
139 error ("outname must be a string or a cell array of strings"); |
|
140 endif |
|
141 if (length (outname) > 1) |
|
142 warning ("tf: %d output names provided; first used", length(outname)); |
4779
|
143 outname = outname(1); |
|
144 endif |
7135
|
145 outsys = syssetsignals (outsys, "out", outname); |
4779
|
146 endif |
|
147 endif |
|
148 |
|
149 endfunction |