3279
|
1 # Copyright (C) 1996,1998 Auburn University. All Rights Reserved |
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 |
3284
|
17 # Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. |
3213
|
18 |
|
19 function [num,den] = zp2tf(zer,pol,k) |
|
20 # [num,den] = zp2tf(zer,pol,k) |
|
21 # Converts zeros / poles to a transfer function. |
|
22 # |
|
23 # Inputs: |
|
24 # zer, pol: vectors of (possibly complex) poles and zeros of a transfer |
|
25 # function. Complex values should appear in conjugate pairs |
|
26 # k: real scalar (leading coefficient) |
|
27 # Forms the transfer function num/den from |
|
28 # the vectors of poles and zeros. K is a scalar gain associated with the |
|
29 # zeros. |
|
30 |
|
31 # Find out whether data was entered as a row or a column vector and |
|
32 # convert to a column vector if necessary |
|
33 # Written by A. S. Hodel with help from students Ingram, McGowan. |
|
34 # a.s.hodel@eng.auburn.edu |
|
35 # |
|
36 |
|
37 [rp,cp] = size(pol); |
|
38 [rz,cz] = size(zer); |
|
39 |
|
40 if(!(is_vector(zer) | isempty(zer)) ) |
|
41 error(sprintf("zer(%dx%d) must be a vector",rz,cz)); |
|
42 elseif(!(is_vector(pol) | isempty(pol)) ) |
|
43 error(sprintf("pol(%dx%d) must be a vector",rp,cp)); |
|
44 elseif(length(zer) > length(pol)) |
|
45 error(sprintf("zer(%dx%d) longer than pol(%dx%d)",rz,cz,rp,cp)); |
|
46 endif |
|
47 |
|
48 num = k; den = 1; # initialize converted polynomials |
|
49 |
|
50 # call zp2ssg2 if there are complex conjugate pairs left, otherwise |
|
51 # construct real zeros one by one. Repeat for poles. |
|
52 while(!isempty(zer)) |
|
53 if( max(abs(imag(zer))) ) [poly,zer] = zp2ssg2(zer); |
|
54 else poly = [1 -zer(1)]; |
|
55 zer = zer(2:length(zer)); endif |
|
56 num = conv(num,poly); |
|
57 endwhile |
|
58 |
|
59 while(!isempty(pol)) |
|
60 if( max(abs(imag(pol))) ) [poly,pol] = zp2ssg2(pol); |
|
61 else poly = [1 -pol(1)]; |
|
62 pol = pol(2:length(pol)); endif |
|
63 den = conv(den,poly); |
|
64 endwhile |
|
65 |
|
66 endfunction |