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} {} 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 |
7136
|
62 if (nargin < 3 || nargin > 6) |
6046
|
63 print_usage (); |
4779
|
64 endif |
|
65 |
|
66 ## check input format |
7136
|
67 if (! (isvector (zer) || isempty (zer))) |
|
68 error ("zer must be a vector or empty"); |
4779
|
69 endif |
7136
|
70 if (! isempty (zer)) |
|
71 zer = reshape (zer, 1, length (zer)); # make it a row vector |
4779
|
72 endif |
|
73 |
7136
|
74 if (! (isvector (pol) || isempty (pol))) |
|
75 error ("pol must be a vector"); |
4779
|
76 endif |
7136
|
77 if (! isempty (pol)) |
|
78 pol = reshape (pol, 1, length (pol)); |
4779
|
79 endif |
|
80 |
7136
|
81 if (! isscalar (k)) |
|
82 error ("k must be a scalar"); |
4779
|
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. |
7136
|
87 if (length (zer) > length (pol)) |
|
88 error ("number of poles (%d) < number of zeros (%d)", |
|
89 length (pol), length (zer)); |
4779
|
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; |
7136
|
102 outsys.n = length (pol); |
4779
|
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) |
7136
|
108 if (! isscalar (tsam)) |
|
109 error ("tsam must be a nonnegative scalar"); |
4779
|
110 endif |
|
111 if (tsam < 0) |
7136
|
112 error ("sampling time must be positve") |
4779
|
113 elseif (tsam > 0) |
7136
|
114 [outsys.n, outsys.nz] = swap (outsys.n, outsys.nz); |
4779
|
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 |
7136
|
128 if (! isempty (inname)) |
|
129 if (! iscell (inname)) |
4779
|
130 inname = {inname}; |
|
131 endif |
7136
|
132 if (! is_signal_list (inname)) |
|
133 error ("inname must be a single signal name"); |
4779
|
134 endif |
|
135 outsys.inname = inname(1); |
|
136 endif |
|
137 endif |
|
138 |
|
139 ## Set name of output |
|
140 if (nargin > 5) |
7136
|
141 if (! isempty (outname)) |
|
142 if (! iscell (outname)) |
4779
|
143 outname = {outname}; |
|
144 endif |
7136
|
145 if (! is_signal_list (outname)) |
|
146 error ("outname must be a single signal name"); |
4779
|
147 endif |
|
148 outsys.outname = outname(1); |
|
149 endif |
|
150 endif |
|
151 |
|
152 endfunction |