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

  1. function [a,b,c,d] = feedback(a1,b1,c1,d1,a2,b2,c2,d2,e,f)
  2. %FEEDBACK Feedback connection of two systems. 
  3. %              u-->O-->[System1]---+--->y
  4. %                  |               |
  5. %                  +---[System2]<--+
  6. %    [A,B,C,D] = FEEDBACK(A1,B1,C1,D1,A2,B2,C2,D2,SIGN) produces an 
  7. %       aggregate state-space system consisting of the feedback connection
  8. %    of the two systems 1 and 2.  Typically, system 1 is a plant and 
  9. %    system 2 is a compensator.   If SIGN=1 then positive feedback is
  10. %    used. If SIGN=-1 then negative feedback is used.  In all cases, 
  11. %    the resulting system has the same inputs and outputs as system 1.
  12. %
  13. %    [A,B,C,D] = FEEDBACK(A1,B1,C1,D1,A2,B2,C2,D2,INPUTS1,OUTPUTS1) 
  14. %    produces the feedback system formed by feeding all the outputs of
  15. %    system 2 into the inputs of system 1 specified by INPUTS1 and by 
  16. %    feeding the outputs of system 1 specified by OUTPUTS1 into all the
  17. %    inputs of system 2.  Positive feedback is assumed.  To connect 
  18. %    with negative feedback, use negative values in the vector INPUTS1.
  19. %
  20. %    [NUM,DEN] = FEEDBACK(NUM1,DEN1,NUM2,DEN2,SIGN) produces the SISO
  21. %    closed loop system in transfer function form obtained by 
  22. %    connecting the two SISO transfer function systems in feedback 
  23. %    with the sign SIGN.  
  24. %    See also: CLOOP, PARALLEL, SERIES, and CONNECT.
  25.  
  26. %    Clay M. Thompson 6-26-90
  27. %    Copyright (c) 1986-93 by the MathWorks, Inc.
  28.  
  29. error(nargchk(4,10,nargin));
  30.  
  31. % --- Determine which syntax is being used ---
  32. if (nargin == 4)  % T.F. w/o sign -- Assume negative feedback
  33.   [num1,den1] = tfchk(a1,b1); [num2,den2] = tfchk(c1,d1); sgn = -1;
  34. end
  35. if (nargin == 5)  % Transfer function form with sign
  36.   [num1,den1] = tfchk(a1,b1); [num2,den2] = tfchk(c1,d1); sgn = sign(a2);
  37. end
  38.  
  39. % --- Form Feedback connection of T.F. system ---
  40. if (nargin==4)|(nargin==5)
  41.     a = conv(num1,den2);
  42.     b = conv(den1,den2) - sgn*conv(num1,num2);
  43.  
  44. elseif (nargin==6) | (nargin==7)
  45.   error('Wrong number of input arguments.');
  46.  
  47. elseif (nargin >= 8)  % State space systems
  48.   error(abcdchk(a1,b1,c1,d1));
  49.   error(abcdchk(a2,b2,c2,d2));
  50.   [ny1,nu1] = size(d1);
  51.   [ny2,nu2] = size(d2);
  52.   if (nargin == 8) % systems w/o sign -- assume negative feedback
  53.     inputs1 = -[1:nu1];     outputs1 = [1:ny1];
  54.     inputs2 =  [1:nu2]+nu1; outputs2 = [1:ny2]+ny1; 
  55.   end
  56.   if (nargin == 9) % State space systems with sign
  57.     inputs1 = [1:nu1]*sign(e); outputs1 = [1:ny1];
  58.     inputs2 = [1:nu2]+nu1;     outputs2 = [1:ny2]+ny1;
  59.   end
  60.   if (nargin == 10) % State space systems w/selection vectors
  61.     inputs1 = e;           outputs1 = f;
  62.     inputs2 = [1:nu2]+nu1; outputs2 = [1:ny2]+ny1;
  63.   end
  64.  
  65.   % Check sizes
  66.   if (length(outputs1)~=length(inputs2)) | (length(outputs2)~=length(inputs1))
  67.     error('Feedback connection sizes don''t match.'); end
  68.  
  69.   % --- Form Closed-Loop Feedback System ---
  70.   [a,b,c,d] = append(a1,b1,c1,d1,a2,b2,c2,d2);
  71.   [a,b,c,d] = cloop(a,b,c,d,[outputs1,outputs2],[inputs2,inputs1]); % close loops
  72.   [a,b,c,d] = ssselect(a,b,c,d,[1:nu1],[1:ny1]);
  73. end
  74.