home *** CD-ROM | disk | FTP | other *** search
- //-------------------------------------------------------------------------------
- //
- // zp2tf
- //
- // Syntax: A=zp2tf(z,p,k)
- //
- //
- // This routine performs the transfer function conversion from
- // a Zero-Pole configuration to a normal transfer function one
- // (numerator/denominator). Calling the routine as,
- //
- // A=zp2tf(z,p,k)
- //
- // where z is z vector of the zeros, p is the vector containing the
- // pole locations, and k is the scalar gain The routine returns the
- // following transfer function,
- //
- // NUM(s)
- // G(s) = --------
- // DEN(s)
- //
- // where NUM(s) is the numerator polynomial and DEN(s) is the denominator
- // polynomial. The polynomials are returned in a list:
- //
- // A.num = numerator coefficients
- // A.den = denominator doefficients
- //
- // ============================================================
- // Note: This routine will not work if p or z have elements not
- // in complex pairs.
- // ============================================================
- //
- // Copyright (C), by Jeffrey B. Layton, 1994
- // Version JBL 931020
- //-------------------------------------------------------------------------------
-
- rfile poly
-
- zp2tf = function(z,p,k)
- {
- local(j,zj,pj,num,den)
-
- // Check compatibility of dimensions of zeros (z) and gains (k)
- if (k.nr != z.nc) {
- error("zp2tf: K must have as many elements as Z has columns.");
- }
-
- // Check how poles (p) are input
- if (p.nc != 1) {
- error("zp2tf: P must only have 1 column.");
- }
-
- // Evaluate the polynomial at the pole locations using poly
- // to get the denominator polynomial
- den=real(poly(p));
-
- // Trap Case where there are no zeros (SIMO type)
- if (isempty(z)) {
- num=[zeros(k.nr,den.nc-1),k];
- }
-
- // Evaluate polynomial at zeros and apply the gains (SIMO type)
- for (j in 1:z.nc) {
- j=z[;j];
- pj=real(poly(zj)*k[j]);
- num[j;]=[zeros(1,den.nc-length(pj)),pj];
- }
-
- return << num=num; den=den >>
- };
-