3228
|
1 # Copyright (C) 1996,1998 A. Scottedward Hodel |
3213
|
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, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
18 |
|
19 function outsys = zp2sys (zer,pol,k,tsam,inname,outname) |
|
20 # sys = zp2sys (zer,pol,k{,tsam,inname,outname}) |
|
21 # Create system data structure from zero-pole data |
|
22 # inputs: |
|
23 # zer: vector of system zeros |
|
24 # pol: vector of system poles |
|
25 # k: scalar leading coefficient |
|
26 # tsam: sampling period. default: 0 (continuous system) |
|
27 # inname, outname: input/output signal names (strings) |
|
28 # outputs: sys: system data structure |
|
29 |
|
30 # Modified by John Ingram July 20, 1996 |
|
31 |
|
32 save_val = implicit_str_to_num_ok; # save for restoring later |
|
33 implicit_str_to_num_ok = 1; |
|
34 |
|
35 # Test for the correct number of input arguments |
|
36 if ((nargin < 3) || (nargin > 6)) |
|
37 usage("outsys = zp2sys(zer,pol,k[,tsam,inname,outname])"); |
|
38 endif |
|
39 |
|
40 # check input format |
|
41 if( ! (is_vector(zer) | isempty(zer) ) ) |
|
42 error("zer must be a vector or empty"); |
|
43 endif |
|
44 zer = reshape(zer,1,length(zer)); # make it a row vector |
|
45 |
|
46 if( ! (is_vector(pol) | isempty(pol))) |
|
47 error("pol must be a vector"); |
|
48 endif |
|
49 pol = reshape(pol,1,length(pol)); |
|
50 |
|
51 if (! is_scalar(k)) |
|
52 error('k must be a scalar'); |
|
53 endif |
|
54 |
|
55 # Test proper numbers of poles and zeros. The number of poles must be |
|
56 # greater than or equal to the number of zeros. |
|
57 if (length(zer) > length(pol)) |
|
58 error(["number of poles (", num2str(length(pol)), ... |
|
59 ") < number of zeros (", num2str(length(zer)),")"]); |
|
60 endif |
|
61 |
|
62 # Set the system transfer function |
|
63 outsys.zer = zer; |
|
64 outsys.pol = pol; |
|
65 outsys.k = k; |
|
66 |
|
67 # Set the system vector: active = 1, updated = [0 1 0]; |
3238
|
68 outsys.sys = [1, 0, 1, 0]; |
3213
|
69 |
|
70 # Set defaults |
|
71 outsys.tsam = 0; |
|
72 outsys.n = length(pol); |
|
73 outsys.nz = 0; |
|
74 outsys.yd = 0; # assume (for now) continuous time outputs |
|
75 |
|
76 # Set the type of system |
|
77 if (nargin > 3) |
|
78 if( !is_scalar(tsam) ) |
|
79 error("tsam must be a nonnegative scalar"); |
|
80 endif |
|
81 if (tsam < 0) |
|
82 error("sampling time must be positve") |
|
83 elseif (tsam > 0) |
|
84 [outsys.n,outsys.nz] = swap(outsys.n, outsys.nz); |
|
85 outsys.yd = 1; # discrete-time output |
|
86 endif |
|
87 |
|
88 outsys.tsam = tsam; |
|
89 endif |
|
90 |
|
91 outsys.inname = sysdefioname(1,"u"); |
|
92 outsys.outname = sysdefioname(1,"y"); |
|
93 outsys.stname = sysdefstname(outsys.n,outsys.nz); |
|
94 |
|
95 # Set name of input |
|
96 if (nargin > 4) |
3228
|
97 # make sure its a string |
|
98 if(!isempty(inname)) |
|
99 if(!is_list(inname)) inname = list(inname); endif |
|
100 if(!is_signal_list(inname)) |
|
101 error("inname must be a single signal name"); |
|
102 endif |
|
103 outsys.inname = inname(1); |
3213
|
104 endif |
|
105 endif |
|
106 |
|
107 # Set name of output |
|
108 if (nargin > 5) |
3228
|
109 if(!isempty(outname)) |
|
110 if(!is_list(outname)) outname = list(outname); endif |
|
111 if(!is_signal_list(outname)) |
|
112 error("outname must be a single signal name"); |
|
113 endif |
|
114 outsys.outname = outname(1); |
3213
|
115 endif |
|
116 endif |
|
117 |
|
118 implicit_str_to_num_ok = save_val; |
|
119 endfunction |