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