function PSET12 % Coded by NFR on 12.4.2018 % This code solves some of the problems for the week % close all clc % Problem 2 - Practice with a smith predictor % Kp = 1.2; Tau1 = 10; Tau2 = 7; Kc = 1.7; TauI = 13.7; % s = tf('s'); Gc = Kc*(1+1/(TauI*s)); % % Part (a) figure theta = 0; Gp = Kp*exp(-theta*s)/(Tau1*s+1)/(Tau2*s+1); Gcl = (Gp*Gc/(1+Gp*Gc)); step(Gcl); xlabel('Time (min)') ylabel('Response'); hold on theta = 5; Gp = Kp*exp(-theta*s)/(Tau1*s+1)/(Tau2*s+1); Gcl = (Gp*Gc/(1+Gp*Gc)); step(Gcl); legend('No time delay','5 min time delay') title('Problem 2 - Part (a)') hold off % Part (b) - Multiple ways to solve this one, I will just increase theta % until it starts oscillating out of control. figure theta = 8; %<--- Looks like at 8min it will start going out of control Gp = Kp*exp(-theta*s)/(Tau1*s+1)/(Tau2*s+1); Gcl = (Gp*Gc/(1+Gp*Gc)); step(Gcl); xlabel('Time (min)') ylabel('Response'); title('Problem 2 - Part (b)') % % Smith predictor - let's do it with the case of the system being out of % control at theta = 8 min. Gc stays the same, but we break up Go Gstar = Kp/(Tau1*s+1)/(Tau2*s+1); Gcl = Gc*Gstar*exp(-theta*s)/(1+Gc*Gstar); figure step(Gcl); xlabel('Time (min)') ylabel('Response'); title('Problem 2 - Part (c)') % Whoa cool! it fixes the problem.... % % Problem 3 Gv = 5; Gp1 = 2/(10*s+1); Gm2 = 0.5/(0.5*s+1); Gm1 = 1/(5*s+1); Kc1 = 0.5; TI1 = 15; Kc2 = 1.0; Gp2 = 1; Gd1 = Gp1; Gd2 = Gp2; Gc1 = Kc1*(1+1/(TI1*s)); Gc2 = Kc2; % % Transfer function for disturbance D2 Gcl = Gp1*Gd2/(1+Gp2*Gv*Gc2*Gm2+Gp1*Gp2*Gv*Gc2*Gc1*Gm1); figure impulse(Gcl) hold on % Plot the second system, that has these changes Gm2 = 2/(5*s+1); Gm1 = 0.2/(5*s+1); Kc1 = 2.5; Kc2 = 0.25; Gc1 = Kc1*(1+1/(TI1*s)); Gc2 = Kc2; % % Transfer function for disturbance D2 Gcl = Gp1*Gd2/(1+Gp2*Gv*Gc2*Gm2+Gp1*Gp2*Gv*Gc2*Gc1*Gm1); impulse(Gcl) xlabel('Time (min)') ylabel('Response'); title('Problem 3') legend('System A', 'System B') % System A responds faster. This is to be expected, as inspection of the % transfer functions shows a faster inner loop (Gm2) for this system. % end