comparison scripts/control/system/zp.m @ 7136:59dcf01bb3e3

[project @ 2007-11-08 20:18:25 by jwe]
author jwe
date Thu, 08 Nov 2007 20:18:26 +0000
parents a1dbe9d80eee
children
comparison
equal deleted inserted replaced
7135:8aa770b6c5bf 7136:59dcf01bb3e3
57 ## Modified by John Ingram July 20, 1996 57 ## Modified by John Ingram July 20, 1996
58 58
59 function outsys = zp (zer, pol, k, tsam, inname, outname) 59 function outsys = zp (zer, pol, k, tsam, inname, outname)
60 60
61 ## Test for the correct number of input arguments 61 ## Test for the correct number of input arguments
62 if ((nargin < 3) || (nargin > 6)) 62 if (nargin < 3 || nargin > 6)
63 print_usage (); 63 print_usage ();
64 endif 64 endif
65 65
66 ## check input format 66 ## check input format
67 if( ! (isvector(zer) | isempty(zer) ) ) 67 if (! (isvector (zer) || isempty (zer)))
68 error("zer must be a vector or empty"); 68 error ("zer must be a vector or empty");
69 endif 69 endif
70 if(!isempty(zer)) 70 if (! isempty (zer))
71 zer = reshape(zer,1,length(zer)); # make it a row vector 71 zer = reshape (zer, 1, length (zer)); # make it a row vector
72 endif 72 endif
73 73
74 if( ! (isvector(pol) | isempty(pol))) 74 if (! (isvector (pol) || isempty (pol)))
75 error("pol must be a vector"); 75 error ("pol must be a vector");
76 endif 76 endif
77 if(!isempty(pol)) 77 if (! isempty (pol))
78 pol = reshape(pol,1,length(pol)); 78 pol = reshape (pol, 1, length (pol));
79 endif 79 endif
80 80
81 if (! isscalar(k)) 81 if (! isscalar (k))
82 error("k must be a scalar"); 82 error ("k must be a scalar");
83 endif 83 endif
84 84
85 ## Test proper numbers of poles and zeros. The number of poles must be 85 ## Test proper numbers of poles and zeros. The number of poles must be
86 ## greater than or equal to the number of zeros. 86 ## greater than or equal to the number of zeros.
87 if (length(zer) > length(pol)) 87 if (length (zer) > length (pol))
88 error(["number of poles (", num2str(length(pol)), ... 88 error ("number of poles (%d) < number of zeros (%d)",
89 ") < number of zeros (", num2str(length(zer)),")"]); 89 length (pol), length (zer));
90 endif 90 endif
91 91
92 ## Set the system transfer function 92 ## Set the system transfer function
93 outsys.zer = zer; 93 outsys.zer = zer;
94 outsys.pol = pol; 94 outsys.pol = pol;
97 ## Set the system vector: active = 1, updated = [0 1 0]; 97 ## Set the system vector: active = 1, updated = [0 1 0];
98 outsys.sys = [1, 0, 1, 0]; 98 outsys.sys = [1, 0, 1, 0];
99 99
100 ## Set defaults 100 ## Set defaults
101 outsys.tsam = 0; 101 outsys.tsam = 0;
102 outsys.n = length(pol); 102 outsys.n = length (pol);
103 outsys.nz = 0; 103 outsys.nz = 0;
104 outsys.yd = 0; # assume (for now) continuous time outputs 104 outsys.yd = 0; # assume (for now) continuous time outputs
105 105
106 ## Set the type of system 106 ## Set the type of system
107 if (nargin > 3) 107 if (nargin > 3)
108 if( !isscalar(tsam) ) 108 if (! isscalar (tsam))
109 error("tsam must be a nonnegative scalar"); 109 error ("tsam must be a nonnegative scalar");
110 endif 110 endif
111 if (tsam < 0) 111 if (tsam < 0)
112 error("sampling time must be positve") 112 error ("sampling time must be positve")
113 elseif (tsam > 0) 113 elseif (tsam > 0)
114 [outsys.n,outsys.nz] = swap(outsys.n, outsys.nz); 114 [outsys.n, outsys.nz] = swap (outsys.n, outsys.nz);
115 outsys.yd = 1; # discrete-time output 115 outsys.yd = 1; # discrete-time output
116 endif 116 endif
117 117
118 outsys.tsam = tsam; 118 outsys.tsam = tsam;
119 endif 119 endif
123 outsys.stname = __sysdefstname__ (outsys.n, outsys.nz); 123 outsys.stname = __sysdefstname__ (outsys.n, outsys.nz);
124 124
125 ## Set name of input 125 ## Set name of input
126 if (nargin > 4) 126 if (nargin > 4)
127 ## make sure its a string 127 ## make sure its a string
128 if(!isempty(inname)) 128 if (! isempty (inname))
129 if(!iscell(inname)) 129 if (! iscell (inname))
130 inname = {inname}; 130 inname = {inname};
131 endif 131 endif
132 if(!is_signal_list(inname)) 132 if (! is_signal_list (inname))
133 error("inname must be a single signal name"); 133 error ("inname must be a single signal name");
134 endif 134 endif
135 outsys.inname = inname(1); 135 outsys.inname = inname(1);
136 endif 136 endif
137 endif 137 endif
138 138
139 ## Set name of output 139 ## Set name of output
140 if (nargin > 5) 140 if (nargin > 5)
141 if(!isempty(outname)) 141 if (! isempty (outname))
142 if(!iscell(outname)) 142 if (! iscell (outname))
143 outname = {outname}; 143 outname = {outname};
144 endif 144 endif
145 if(!is_signal_list(outname)) 145 if (! is_signal_list (outname))
146 error("outname must be a single signal name"); 146 error ("outname must be a single signal name");
147 endif 147 endif
148 outsys.outname = outname(1); 148 outsys.outname = outname(1);
149 endif 149 endif
150 endif 150 endif
151 151