aprsc7

Assignment2

Jan 25th, 2021
425
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. clear
  2. clc
  3.  
  4. %% Input:
  5.  
  6. numg = 5; % Define numerator of G(s)
  7. deng = poly([0.4 0.8 5]); % Define denominator of G(s)
  8. Ts = 600;   % Time settling
  9. Os = 5;    % Overshoot (%)
  10.  
  11. %% Process
  12. syms s k1 k2 k3 ke;
  13.  
  14. G = tf(numg,deng)   % Generate transfer function G(s)
  15. [Ac Bc Cc Dc] = tf2ss(numg,deng);
  16. P = flip(eye(order(G)));
  17. A = inv(P)*Ac*P
  18. B = inv(P)*Bc
  19. C = Cc*P
  20. D = Dc
  21.  
  22. Cm = det(ctrb(A,B))      % Controlbility
  23.  
  24. zeta = (-log(Os/100))/(sqrt(pi^2+log(Os/100)^2));
  25. Wn = 4/(zeta*Ts); % pi/(Tp*sqrt(1-zeta^2))
  26.  
  27. %% state-feedback control
  28.  
  29. pole1 = s^2 + 2*zeta*Wn*s + Wn^2;
  30. pole2 = s+50
  31.  
  32. Anew = A-(B*[k1 k2 k3])
  33.  
  34. Ds = expand(pole1*pole2)
  35. Ts = det(s*eye(3)-Anew)
  36.  
  37. % Solve
  38. Dsm = coeffs(Ds,s);
  39. Tsm = coeffs(Ts,s);
  40. k = vpa(struct2cell((solve(Dsm==Tsm))))
  41.  
  42. %% Plot
  43.  
  44. % Subs k into transfer function
  45. Ts = subs(Ts,k1,k(1));
  46. Ts = subs(Ts,k2,k(2));
  47. Ts = subs(Ts,k3,k(3));
  48.  
  49. % Form transfer function
  50. dent = double(flip(coeffs(Ts,s)));
  51. Tsc = tf(numg,dent)
  52.  
  53. % Plot
  54. step(Tsc);
  55. title('State Feedback Controller');
  56.  
  57.  
  58.  
RAW Paste Data