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