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 |
|
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 |