7017
|
1 ## Copyright (C) 1996, 1998, 2000, 2002, 2004, 2005, 2007 |
|
2 ## Auburn University. All rights reserved. |
3430
|
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. |
3430
|
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. |
3430
|
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/>. |
3430
|
19 |
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {[@var{num}, @var{den}] =} zp2tf (@var{zer}, @var{pol}, @var{k}) |
|
22 ## Converts zeros / poles to a transfer function. |
5016
|
23 ## |
3430
|
24 ## @strong{Inputs} |
|
25 ## @table @var |
|
26 ## @item zer |
|
27 ## @itemx pol |
5016
|
28 ## Vectors of (possibly complex) poles and zeros of a transfer |
|
29 ## function. Complex values must appear in conjugate pairs. |
3430
|
30 ## @item k |
5016
|
31 ## Real scalar (leading coefficient). |
3430
|
32 ## @end table |
|
33 ## @end deftypefn |
|
34 |
|
35 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu> |
|
36 ## (With help from students Ingram, McGowan.) |
|
37 |
|
38 function [num, den] = zp2tf (zer, pol, k) |
|
39 |
7125
|
40 if (nargin != 3) |
|
41 print_usage (); |
|
42 endif |
|
43 |
3430
|
44 ## Find out whether data was entered as a row or a column vector and |
|
45 ## convert to a column vector if necessary. |
|
46 |
7125
|
47 [rp, cp] = size (pol); |
|
48 [rz, cz] = size (zer); |
3430
|
49 |
7125
|
50 if (! (isvector (zer) || isempty (zer))) |
|
51 error ("zer(%dx%d) must be a vector", rz, cz); |
|
52 elseif(! (isvector (pol) || isempty (pol))) |
|
53 error ("pol(%dx%d) must be a vector", rp, cp); |
|
54 elseif (length (zer) > length (pol)) |
|
55 error ("zer(%dx%d) longer than pol(%dx%d)", rz, cz, rp, cp); |
3430
|
56 endif |
|
57 |
|
58 ## initialize converted polynomials |
|
59 |
|
60 num = k; den = 1; |
|
61 |
3438
|
62 ## call __zp2ssg2__ if there are complex conjugate pairs left, otherwise |
3430
|
63 ## construct real zeros one by one. Repeat for poles. |
|
64 |
7125
|
65 while(! isempty (zer)) |
|
66 if (max (abs (imag (zer)))) |
|
67 [poly, zer] = __zp2ssg2__ (zer); |
|
68 else |
|
69 poly = [1, -zer(1)]; |
|
70 zer = zer(2:length(zer)); |
|
71 endif |
|
72 num = conv (num, poly); |
3430
|
73 endwhile |
|
74 |
7125
|
75 while (! isempty (pol)) |
|
76 if (max (abs (imag (pol)))) |
|
77 [poly, pol] = __zp2ssg2__ (pol); |
|
78 else |
|
79 poly = [1, -pol(1)]; |
|
80 pol = pol(2:length(pol)); |
|
81 endif |
|
82 den = conv (den, poly); |
3430
|
83 endwhile |
|
84 |
|
85 endfunction |