Mercurial > octave-nkf
comparison scripts/control/system/tf.m @ 4779:f105000ab25c
[project @ 2004-02-17 02:34:33 by jwe]
author | jwe |
---|---|
date | Tue, 17 Feb 2004 02:34:33 +0000 |
parents | |
children | 4c8a2e4e0717 |
comparison
equal
deleted
inserted
replaced
4778:567c8e2d2438 | 4779:f105000ab25c |
---|---|
1 ## Copyright (C) 1996, 1998 Auburn University. All rights reserved. | |
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. | |
18 | |
19 ## -*- texinfo -*- | |
20 ## @deftypefn {Function File} {} tf (@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 | |
26 ## @itemx den | |
27 ## coefficients of numerator/denominator polynomials | |
28 ## @item tsam | |
29 ## sampling interval. default: 0 (continuous time) | |
30 ## @item inname | |
31 ## @itemx outname | |
32 ## input/output signal names; may be a string or cell array with a single string | |
33 ## entry. | |
34 ## @end table | |
35 ## | |
36 ## @strong{Outputs} | |
37 ## @var{sys} = system data structure | |
38 ## | |
39 ## @strong{Example} | |
40 ## @example | |
41 ## octave:1> sys=tf([2 1],[1 2 1],0.1); | |
42 ## octave:2> sysout(sys) | |
43 ## Input(s) | |
44 ## 1: u_1 | |
45 ## Output(s): | |
46 ## 1: y_1 (discrete) | |
47 ## Sampling interval: 0.1 | |
48 ## transfer function form: | |
49 ## 2*z^1 + 1 | |
50 ## ----------------- | |
51 ## 1*z^2 + 2*z^1 + 1 | |
52 ## @end example | |
53 ## @end deftypefn | |
54 | |
55 ## Author: R. Bruce Tenison <btenison@eng.auburn.edu> | |
56 ## Created: July 29, 1994 | |
57 ## Name changed to TF2SYS July 1995 | |
58 ## updated for new system data structure format July 1996 | |
59 | |
60 function outsys = tf (num, den, tsam, inname, outname) | |
61 | |
62 ## Test for the correct number of input arguments | |
63 if ((nargin < 2) || (nargin > 5)) | |
64 usage ("outsys = tf (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 = __tfl__ (num); | |
78 den = __tfl__ (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 it's a cell array of a single string | |
115 if(!isempty(inname)) | |
116 if(!iscell(inname)) inname = {inname}; endif | |
117 if( !is_signal_list(inname) ) | |
118 error("inname must be a string or cell array of strings"); | |
119 endif | |
120 if(length(inname) > 1) | |
121 warning("tf: %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(!iscell(outname)) outname = {outname}; endif | |
132 if(!is_signal_list(outname)) | |
133 error("outname must be a string or a cell array of strings"); | |
134 endif | |
135 if(length(outname) > 1) | |
136 warning("tf: %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 | |
143 endfunction |