home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / r / rlab / CTB / zp2tf < prev   
Encoding:
Text File  |  1995-11-15  |  1.9 KB  |  71 lines

  1. //-------------------------------------------------------------------------------
  2. //
  3. // zp2tf
  4. //
  5. // Syntax: A=zp2tf(z,p,k)
  6. //
  7. //
  8. // This routine performs the transfer function conversion from
  9. // a Zero-Pole configuration to a normal transfer function one
  10. // (numerator/denominator). Calling the routine as,
  11. //
  12. //     A=zp2tf(z,p,k)
  13. //
  14. // where z is z vector of the zeros, p is the vector containing the
  15. // pole locations, and k is the scalar gain The routine returns the
  16. // following transfer function,
  17. //
  18. //                NUM(s)
  19. //        G(s) = -------- 
  20. //                DEN(s)
  21. //
  22. // where NUM(s) is the numerator polynomial and DEN(s) is the denominator
  23. // polynomial. The polynomials are returned in a list:
  24. //
  25. //      A.num = numerator coefficients
  26. //      A.den = denominator doefficients
  27. //
  28. //     ============================================================
  29. //     Note: This routine will not work if p or z have elements not
  30. //           in complex pairs.
  31. //     ============================================================
  32. //
  33. // Copyright (C), by Jeffrey B. Layton, 1994
  34. // Version JBL 931020
  35. //-------------------------------------------------------------------------------
  36.  
  37. rfile poly
  38.  
  39. zp2tf = function(z,p,k)
  40. {
  41.    local(j,zj,pj,num,den)
  42.  
  43. // Check compatibility of dimensions of zeros (z) and gains (k)
  44.    if (k.nr != z.nc) {
  45.        error("zp2tf: K must have as many elements as Z has columns.");
  46.    }
  47.  
  48. // Check how poles (p) are input
  49.    if (p.nc != 1) {
  50.        error("zp2tf: P must only have 1 column.");
  51.    }
  52.  
  53. // Evaluate the polynomial at the pole locations using poly
  54. // to get the denominator polynomial
  55.    den=real(poly(p));
  56.  
  57. // Trap Case where there are no zeros (SIMO type)
  58.    if (isempty(z)) {
  59.        num=[zeros(k.nr,den.nc-1),k];
  60.    }
  61.  
  62. // Evaluate polynomial at zeros and apply the gains (SIMO type)
  63.    for (j in 1:z.nc) {
  64.         j=z[;j];
  65.         pj=real(poly(zj)*k[j]);
  66.         num[j;]=[zeros(1,den.nc-length(pj)),pj];
  67.    }
  68.  
  69.    return << num=num; den=den >>
  70. };
  71.