annotate scripts/control/zp2sys.m @ 3238:041ea33fbbf4

[project @ 1999-03-26 17:48:16 by jwe]
author jwe
date Fri, 26 Mar 1999 17:48:35 +0000
parents 98e15955107e
children 6dd06d525de6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3228
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
1 # Copyright (C) 1996,1998 A. Scottedward Hodel
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
2 #
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
3 # This file is part of Octave.
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
4 #
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
5 # Octave is free software; you can redistribute it and/or modify it
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
6 # under the terms of the GNU General Public License as published by the
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
7 # Free Software Foundation; either version 2, or (at your option) any
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
8 # later version.
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
9 #
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
10 # Octave is distributed in the hope that it will be useful, but WITHOUT
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
13 # for more details.
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
14 #
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
15 # You should have received a copy of the GNU General Public License
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
16 # along with Octave; see the file COPYING. If not, write to the Free
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
17 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
18
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
19 function outsys = zp2sys (zer,pol,k,tsam,inname,outname)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
20 # sys = zp2sys (zer,pol,k{,tsam,inname,outname})
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
21 # Create system data structure from zero-pole data
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
22 # inputs:
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
23 # zer: vector of system zeros
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
24 # pol: vector of system poles
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
25 # k: scalar leading coefficient
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
26 # tsam: sampling period. default: 0 (continuous system)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
27 # inname, outname: input/output signal names (strings)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
28 # outputs: sys: system data structure
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
29
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
30 # Modified by John Ingram July 20, 1996
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
31
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
32 save_val = implicit_str_to_num_ok; # save for restoring later
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
33 implicit_str_to_num_ok = 1;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
34
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
35 # Test for the correct number of input arguments
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
36 if ((nargin < 3) || (nargin > 6))
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
37 usage("outsys = zp2sys(zer,pol,k[,tsam,inname,outname])");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
38 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
39
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
40 # check input format
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
41 if( ! (is_vector(zer) | isempty(zer) ) )
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
42 error("zer must be a vector or empty");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
43 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
44 zer = reshape(zer,1,length(zer)); # make it a row vector
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
45
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
46 if( ! (is_vector(pol) | isempty(pol)))
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
47 error("pol must be a vector");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
48 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
49 pol = reshape(pol,1,length(pol));
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
50
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
51 if (! is_scalar(k))
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
52 error('k must be a scalar');
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
53 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
54
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
55 # Test proper numbers of poles and zeros. The number of poles must be
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
56 # greater than or equal to the number of zeros.
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
57 if (length(zer) > length(pol))
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
58 error(["number of poles (", num2str(length(pol)), ...
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
59 ") < number of zeros (", num2str(length(zer)),")"]);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
60 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
61
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
62 # Set the system transfer function
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
63 outsys.zer = zer;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
64 outsys.pol = pol;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
65 outsys.k = k;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
66
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
67 # Set the system vector: active = 1, updated = [0 1 0];
3238
041ea33fbbf4 [project @ 1999-03-26 17:48:16 by jwe]
jwe
parents: 3236
diff changeset
68 outsys.sys = [1, 0, 1, 0];
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
69
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
70 # Set defaults
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
71 outsys.tsam = 0;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
72 outsys.n = length(pol);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
73 outsys.nz = 0;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
74 outsys.yd = 0; # assume (for now) continuous time outputs
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
75
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
76 # Set the type of system
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
77 if (nargin > 3)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
78 if( !is_scalar(tsam) )
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
79 error("tsam must be a nonnegative scalar");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
80 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
81 if (tsam < 0)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
82 error("sampling time must be positve")
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
83 elseif (tsam > 0)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
84 [outsys.n,outsys.nz] = swap(outsys.n, outsys.nz);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
85 outsys.yd = 1; # discrete-time output
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
86 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
87
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
88 outsys.tsam = tsam;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
89 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
90
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
91 outsys.inname = sysdefioname(1,"u");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
92 outsys.outname = sysdefioname(1,"y");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
93 outsys.stname = sysdefstname(outsys.n,outsys.nz);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
94
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
95 # Set name of input
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
96 if (nargin > 4)
3228
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
97 # make sure its a string
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
98 if(!isempty(inname))
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
99 if(!is_list(inname)) inname = list(inname); endif
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
100 if(!is_signal_list(inname))
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
101 error("inname must be a single signal name");
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
102 endif
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
103 outsys.inname = inname(1);
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
104 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
105 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
106
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
107 # Set name of output
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
108 if (nargin > 5)
3228
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
109 if(!isempty(outname))
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
110 if(!is_list(outname)) outname = list(outname); endif
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
111 if(!is_signal_list(outname))
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
112 error("outname must be a single signal name");
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
113 endif
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
114 outsys.outname = outname(1);
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
115 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
116 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
117
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
118 implicit_str_to_num_ok = save_val;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents:
diff changeset
119 endfunction