Mercurial > octave-nkf
comparison scripts/control/system/zp.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} {} zp (@var{zer}, @var{pol}, @var{k}, @var{tsam}, @var{inname}, @var{outname}) | |
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=zp([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 = zp (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 = zp(zer,pol,k[,tsam,inname,outname])"); | |
63 endif | |
64 | |
65 ## check input format | |
66 if( ! (isvector(zer) | isempty(zer) ) ) | |
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 | |
73 if( ! (isvector(pol) | isempty(pol))) | |
74 error("pol must be a vector"); | |
75 endif | |
76 if(!isempty(pol)) | |
77 pol = reshape(pol,1,length(pol)); | |
78 endif | |
79 | |
80 if (! isscalar(k)) | |
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) | |
107 if( !isscalar(tsam) ) | |
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 | |
120 outsys.inname = __sysdefioname__ (1, "u"); | |
121 outsys.outname = __sysdefioname__ (1, "y"); | |
122 outsys.stname = __sysdefstname__ (outsys.n, outsys.nz); | |
123 | |
124 ## Set name of input | |
125 if (nargin > 4) | |
126 ## make sure its a string | |
127 if(!isempty(inname)) | |
128 if(!iscell(inname)) | |
129 inname = {inname}; | |
130 endif | |
131 if(!is_signal_list(inname)) | |
132 error("inname must be a single signal name"); | |
133 endif | |
134 outsys.inname = inname(1); | |
135 endif | |
136 endif | |
137 | |
138 ## Set name of output | |
139 if (nargin > 5) | |
140 if(!isempty(outname)) | |
141 if(!iscell(outname)) | |
142 outname = {outname}; | |
143 endif | |
144 if(!is_signal_list(outname)) | |
145 error("outname must be a single signal name"); | |
146 endif | |
147 outsys.outname = outname(1); | |
148 endif | |
149 endif | |
150 | |
151 endfunction |