3430
|
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} {[@var{num}, @var{den}] =} zp2tf (@var{zer}, @var{pol}, @var{k}) |
|
21 ## Converts zeros / poles to a transfer function. |
|
22 ## @strong{Inputs} |
|
23 ## @table @var |
|
24 ## @item zer |
|
25 ## @itemx pol |
|
26 ## vectors of (possibly complex) poles and zeros of a transfer |
|
27 ## function. Complex values should appear in conjugate pairs |
|
28 ## @item k |
|
29 ## real scalar (leading coefficient) |
|
30 ## @end table |
|
31 ## @code{[num,den] = zp2tf(zer,pol,k)} forms the transfer function |
|
32 ## @code{num/den} from the vectors of poles and zeros. |
|
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 |
|
40 ## Find out whether data was entered as a row or a column vector and |
|
41 ## convert to a column vector if necessary. |
|
42 |
|
43 [rp,cp] = size(pol); |
|
44 [rz,cz] = size(zer); |
|
45 |
4030
|
46 if(!(isvector(zer) | isempty(zer)) ) |
3430
|
47 error(sprintf("zer(%dx%d) must be a vector",rz,cz)); |
4030
|
48 elseif(!(isvector(pol) | isempty(pol)) ) |
3430
|
49 error(sprintf("pol(%dx%d) must be a vector",rp,cp)); |
|
50 elseif(length(zer) > length(pol)) |
|
51 error(sprintf("zer(%dx%d) longer than pol(%dx%d)",rz,cz,rp,cp)); |
|
52 endif |
|
53 |
|
54 ## initialize converted polynomials |
|
55 |
|
56 num = k; den = 1; |
|
57 |
3438
|
58 ## call __zp2ssg2__ if there are complex conjugate pairs left, otherwise |
3430
|
59 ## construct real zeros one by one. Repeat for poles. |
|
60 |
|
61 while(!isempty(zer)) |
3438
|
62 if( max(abs(imag(zer))) ) [poly, zer] = __zp2ssg2__ (zer); |
3430
|
63 else poly = [1, -zer(1)]; |
|
64 zer = zer(2:length(zer)); endif |
|
65 num = conv(num,poly); |
|
66 endwhile |
|
67 |
|
68 while(!isempty(pol)) |
3438
|
69 if( max(abs(imag(pol))) ) [poly, pol] = __zp2ssg2__ (pol); |
3430
|
70 else poly = [1, -pol(1)]; |
|
71 pol = pol(2:length(pol)); endif |
|
72 den = conv(den,poly); |
|
73 endwhile |
|
74 |
|
75 endfunction |