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 |
|
64 if ((nargin < 2) || (nargin > 5)) |
6046
|
65 print_usage (); |
4779
|
66 return |
|
67 endif |
|
68 |
|
69 ## check input format |
|
70 if( ! ( (isvector(num) || isscalar(num)) && ... |
|
71 (isvector(den) || isscalar(den))) ) |
|
72 error(["num (",num2str(rows(num)),"x",num2str(columns(num)), ... |
|
73 ") and den (",num2str(rows(den)),"x",num2str(columns(den)), ... |
|
74 ") must be vectors"]) |
|
75 endif |
|
76 |
|
77 ## strip leading zero coefficients |
|
78 num = __tfl__ (num); |
|
79 den = __tfl__ (den); |
|
80 |
|
81 if (length(num) > length(den)) |
|
82 error("# of poles (%d) < # of zeros (%d)",length(den)-1, length(num)-1); |
|
83 endif |
|
84 |
|
85 ## check sampling interval (if any) |
|
86 if(nargin <= 2) tsam = 0; # default |
|
87 elseif (isempty(tsam)) tsam = 0; endif |
|
88 if ( (! (isscalar(tsam) && (imag(tsam) == 0) )) || (tsam < 0) ) |
|
89 error("tsam must be a positive real scalar") |
|
90 endif |
|
91 |
|
92 outsys.num = num; |
|
93 outsys.den = den; |
|
94 |
|
95 ## Set the system vector: active = 0(tf), updated = [1 0 0]; |
|
96 outsys.sys = [0, 1, 0, 0]; |
|
97 |
|
98 ## Set defaults |
|
99 outsys.tsam = tsam; |
|
100 outsys.n = length(den)-1; |
|
101 outsys.nz = 0; |
|
102 outsys.yd = 0; # assume discrete-time |
|
103 ## check discrete time |
|
104 if(tsam > 0) |
|
105 [outsys.n,outsys.nz] = swap(outsys.n, outsys.nz); |
|
106 outsys.yd = 1; |
|
107 endif |
|
108 |
|
109 outsys.inname = __sysdefioname__ (1, "u"); |
|
110 outsys.outname = __sysdefioname__ (1, "y"); |
|
111 outsys.stname = __sysdefstname__ (outsys.n, outsys.nz); |
|
112 |
|
113 ## Set name of input |
|
114 if (nargin > 3) |
|
115 ## make sure it's a cell array of a single string |
|
116 if(!isempty(inname)) |
|
117 if(!iscell(inname)) inname = {inname}; endif |
|
118 if( !is_signal_list(inname) ) |
|
119 error("inname must be a string or cell array of strings"); |
|
120 endif |
|
121 if(length(inname) > 1) |
|
122 warning("tf: %d input names provided; first used",length(inname)); |
|
123 inname = inname(1); |
|
124 endif |
|
125 outsys = syssetsignals(outsys,"in",inname); |
|
126 endif |
|
127 endif |
|
128 |
|
129 ## Set name of output |
|
130 if (nargin > 4) |
|
131 if(!isempty(outname)) |
|
132 if(!iscell(outname)) outname = {outname}; endif |
|
133 if(!is_signal_list(outname)) |
|
134 error("outname must be a string or a cell array of strings"); |
|
135 endif |
|
136 if(length(outname) > 1) |
|
137 warning("tf: %d output names provided; first used",length(outname)); |
|
138 outname = outname(1); |
|
139 endif |
|
140 outsys = syssetsignals(outsys,"out",outname); |
|
141 endif |
|
142 endif |
|
143 |
|
144 endfunction |