home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 10.ddi / CONTROL.DI$ / TF2ZP.M < prev    next >
Encoding:
Text File  |  1993-03-11  |  1.6 KB  |  63 lines

  1. function [z,p,k] = tf2zp(num,den)
  2. %TF2ZP    Transfer function to zero-pole conversion.
  3. %    [Z,p,k] = TF2ZP(NUM,den)  finds the zeros, poles, and gains:
  4. %
  5. %                  (s-z1)(s-z2)...(s-zn)
  6. %        H(s) =  K ---------------------
  7. %                  (s-p1)(s-p2)...(s-pn)
  8. %
  9. %    from a SIMO transfer function in polynomial form:
  10. %
  11. %                NUM(s)
  12. %        H(s) = -------- 
  13. %                den(s)
  14. %
  15. %    Vector DEN specifies the coefficients of the denominator in 
  16. %    descending powers of s.  Matrix NUM indicates the numerator 
  17. %    coefficients with as many rows as there are outputs.  The zero
  18. %    locations are returned in the columns of matrix Z, with as many 
  19. %    columns as there are rows in NUM.  The pole locations are returned
  20. %    in column vector P, and the gains for each numerator transfer 
  21. %    function in vector K. 
  22. %    
  23. %    See also: ZP2TF.
  24.  
  25. %    Clay M. Thompson 11-6-90 
  26. %    Revised ACWG 1-17-90
  27. %    Copyright (c) 1986-93 by the Mathworks, Inc.
  28.  
  29. [num,den] = tfchk(num,den);
  30.  
  31. % Normalize transfer function
  32. if length(den)
  33.     coef = den(1);
  34. else
  35.     coef = 1;
  36. end
  37. if abs(coef)<eps,
  38.   error('Denominator must have non-zero leading coefficient.');
  39. end
  40. den = den./coef;
  41. num = num./coef;
  42.  
  43. % Remove leading columns of zeros from numerator
  44. if length(num)
  45.     while(all(num(:,1)==0) & length(num) > 1)
  46.         num(:,1) = [];
  47.     end
  48. end
  49. [ny,np] = size(num);
  50.  
  51. % Poles
  52. p  = roots(den);
  53.  
  54. % Zeros and Gain
  55. k = zeros(ny,1);
  56. z = Inf*ones(np-1,ny);
  57. for i=1:ny
  58.   zz = roots(num(i,:));
  59.   if length(zz), z(1:length(zz), i) = zz; end
  60.   ndx = find(num(i,:)~=0);
  61.   if length(ndx), k(i,1) = num(i,ndx(1)); end
  62. end
  63.