Mercurial > octave-nkf
comparison scripts/control/system/zp2tf.m @ 7125:f084ba47812b
[project @ 2007-11-08 02:29:23 by jwe]
author | jwe |
---|---|
date | Thu, 08 Nov 2007 02:29:24 +0000 |
parents | a1dbe9d80eee |
children | 59dcf01bb3e3 |
comparison
equal
deleted
inserted
replaced
7124:d07cb867891b | 7125:f084ba47812b |
---|---|
35 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu> | 35 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu> |
36 ## (With help from students Ingram, McGowan.) | 36 ## (With help from students Ingram, McGowan.) |
37 | 37 |
38 function [num, den] = zp2tf (zer, pol, k) | 38 function [num, den] = zp2tf (zer, pol, k) |
39 | 39 |
40 if (nargin != 3) | |
41 print_usage (); | |
42 endif | |
43 | |
40 ## Find out whether data was entered as a row or a column vector and | 44 ## Find out whether data was entered as a row or a column vector and |
41 ## convert to a column vector if necessary. | 45 ## convert to a column vector if necessary. |
42 | 46 |
43 [rp,cp] = size(pol); | 47 [rp, cp] = size (pol); |
44 [rz,cz] = size(zer); | 48 [rz, cz] = size (zer); |
45 | 49 |
46 if(!(isvector(zer) | isempty(zer)) ) | 50 if (! (isvector (zer) || isempty (zer))) |
47 error(sprintf("zer(%dx%d) must be a vector",rz,cz)); | 51 error ("zer(%dx%d) must be a vector", rz, cz); |
48 elseif(!(isvector(pol) | isempty(pol)) ) | 52 elseif(! (isvector (pol) || isempty (pol))) |
49 error(sprintf("pol(%dx%d) must be a vector",rp,cp)); | 53 error ("pol(%dx%d) must be a vector", rp, cp); |
50 elseif(length(zer) > length(pol)) | 54 elseif (length (zer) > length (pol)) |
51 error(sprintf("zer(%dx%d) longer than pol(%dx%d)",rz,cz,rp,cp)); | 55 error ("zer(%dx%d) longer than pol(%dx%d)", rz, cz, rp, cp); |
52 endif | 56 endif |
53 | 57 |
54 ## initialize converted polynomials | 58 ## initialize converted polynomials |
55 | 59 |
56 num = k; den = 1; | 60 num = k; den = 1; |
57 | 61 |
58 ## call __zp2ssg2__ if there are complex conjugate pairs left, otherwise | 62 ## call __zp2ssg2__ if there are complex conjugate pairs left, otherwise |
59 ## construct real zeros one by one. Repeat for poles. | 63 ## construct real zeros one by one. Repeat for poles. |
60 | 64 |
61 while(!isempty(zer)) | 65 while(! isempty (zer)) |
62 if( max(abs(imag(zer))) ) [poly, zer] = __zp2ssg2__ (zer); | 66 if (max (abs (imag (zer)))) |
63 else poly = [1, -zer(1)]; | 67 [poly, zer] = __zp2ssg2__ (zer); |
64 zer = zer(2:length(zer)); endif | 68 else |
65 num = conv(num,poly); | 69 poly = [1, -zer(1)]; |
70 zer = zer(2:length(zer)); | |
71 endif | |
72 num = conv (num, poly); | |
66 endwhile | 73 endwhile |
67 | 74 |
68 while(!isempty(pol)) | 75 while (! isempty (pol)) |
69 if( max(abs(imag(pol))) ) [poly, pol] = __zp2ssg2__ (pol); | 76 if (max (abs (imag (pol)))) |
70 else poly = [1, -pol(1)]; | 77 [poly, pol] = __zp2ssg2__ (pol); |
71 pol = pol(2:length(pol)); endif | 78 else |
72 den = conv(den,poly); | 79 poly = [1, -pol(1)]; |
80 pol = pol(2:length(pol)); | |
81 endif | |
82 den = conv (den, poly); | |
73 endwhile | 83 endwhile |
74 | 84 |
75 endfunction | 85 endfunction |