3430
|
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 -*- |
3500
|
20 ## @deftypefn {Function File} {} zp2sys (@var{zer}, @var{pol}, @var{k}, @var{tsam}, @var{inname}, @var{outname}) |
3430
|
21 ## Create system data structure from zero-pole data. |
|
22 ## |
|
23 ## @strong{Inputs} |
|
24 ## @table @var |
|
25 ## @item zer |
|
26 ## vector of system zeros |
|
27 ## @item pol |
|
28 ## vector of system poles |
|
29 ## @item k |
|
30 ## scalar leading coefficient |
|
31 ## @item tsam |
|
32 ## sampling period. default: 0 (continuous system) |
|
33 ## @item inname |
|
34 ## @itemx outname |
|
35 ## input/output signal names (lists of strings) |
|
36 ## @end table |
|
37 ## |
|
38 ## @strong{Outputs} |
|
39 ## sys: system data structure |
|
40 ## |
|
41 ## @strong{Example} |
|
42 ## @example |
|
43 ## octave:1> sys=zp2sys([1 -1],[-2 -2 0],1); |
|
44 ## octave:2> sysout(sys) |
|
45 ## Input(s) |
|
46 ## 1: u_1 |
|
47 ## Output(s): |
|
48 ## 1: y_1 |
|
49 ## zero-pole form: |
|
50 ## 1 (s - 1) (s + 1) |
|
51 ## ----------------- |
|
52 ## s (s + 2) (s + 2) |
|
53 ## @end example |
|
54 ## @end deftypefn |
|
55 |
|
56 ## Modified by John Ingram July 20, 1996 |
|
57 |
|
58 function outsys = zp2sys (zer, pol, k, tsam, inname, outname) |
|
59 |
|
60 ## Test for the correct number of input arguments |
|
61 if ((nargin < 3) || (nargin > 6)) |
|
62 usage("outsys = zp2sys(zer,pol,k[,tsam,inname,outname])"); |
|
63 endif |
|
64 |
|
65 ## check input format |
4030
|
66 if( ! (isvector(zer) | isempty(zer) ) ) |
3430
|
67 error("zer must be a vector or empty"); |
|
68 endif |
|
69 if(!isempty(zer)) |
|
70 zer = reshape(zer,1,length(zer)); # make it a row vector |
|
71 endif |
|
72 |
4030
|
73 if( ! (isvector(pol) | isempty(pol))) |
3430
|
74 error("pol must be a vector"); |
|
75 endif |
|
76 if(!isempty(pol)) |
|
77 pol = reshape(pol,1,length(pol)); |
|
78 endif |
|
79 |
4030
|
80 if (! isscalar(k)) |
3430
|
81 error("k must be a scalar"); |
|
82 endif |
|
83 |
|
84 ## Test proper numbers of poles and zeros. The number of poles must be |
|
85 ## greater than or equal to the number of zeros. |
|
86 if (length(zer) > length(pol)) |
|
87 error(["number of poles (", num2str(length(pol)), ... |
|
88 ") < number of zeros (", num2str(length(zer)),")"]); |
|
89 endif |
|
90 |
|
91 ## Set the system transfer function |
|
92 outsys.zer = zer; |
|
93 outsys.pol = pol; |
|
94 outsys.k = k; |
|
95 |
|
96 ## Set the system vector: active = 1, updated = [0 1 0]; |
|
97 outsys.sys = [1, 0, 1, 0]; |
|
98 |
|
99 ## Set defaults |
|
100 outsys.tsam = 0; |
|
101 outsys.n = length(pol); |
|
102 outsys.nz = 0; |
|
103 outsys.yd = 0; # assume (for now) continuous time outputs |
|
104 |
|
105 ## Set the type of system |
|
106 if (nargin > 3) |
4030
|
107 if( !isscalar(tsam) ) |
3430
|
108 error("tsam must be a nonnegative scalar"); |
|
109 endif |
|
110 if (tsam < 0) |
|
111 error("sampling time must be positve") |
|
112 elseif (tsam > 0) |
|
113 [outsys.n,outsys.nz] = swap(outsys.n, outsys.nz); |
|
114 outsys.yd = 1; # discrete-time output |
|
115 endif |
|
116 |
|
117 outsys.tsam = tsam; |
|
118 endif |
|
119 |
3438
|
120 outsys.inname = __sysdefioname__ (1, "u"); |
|
121 outsys.outname = __sysdefioname__ (1, "y"); |
|
122 outsys.stname = __sysdefstname__ (outsys.n, outsys.nz); |
3430
|
123 |
|
124 ## Set name of input |
|
125 if (nargin > 4) |
|
126 ## make sure its a string |
|
127 if(!isempty(inname)) |
4030
|
128 if(!islist(inname)) inname = list(inname); endif |
3430
|
129 if(!is_signal_list(inname)) |
|
130 error("inname must be a single signal name"); |
|
131 endif |
|
132 outsys.inname = inname(1); |
|
133 endif |
|
134 endif |
|
135 |
|
136 ## Set name of output |
|
137 if (nargin > 5) |
|
138 if(!isempty(outname)) |
4030
|
139 if(!islist(outname)) outname = list(outname); endif |
3430
|
140 if(!is_signal_list(outname)) |
|
141 error("outname must be a single signal name"); |
|
142 endif |
|
143 outsys.outname = outname(1); |
|
144 endif |
|
145 endif |
|
146 |
|
147 endfunction |