% In-class demo/exercise
% 28 October 2019

s = tf('s');

% System example from FPE 5.4
G = 1 / (s*(s+1));
rlocus(G);

%% We can add a zero with PD control
C = 2+s; % kP = 2*kD
rlocus(C*G);

% K = 5;
% figure;
% step(feedback(C*G, K));

% But the control effort might be a problem, so use lead compensation
hold on;
C = (2+s)/(s+15);
rlocus(C*G);

%% We can also do lag compensation
C = (s+0.05)/(s+0.01);
rlocus(C*G);

% K = 90;
% figure;
% step(feedback(C*G, K));

%% What do these look like in the frequency domain?

T = 1;
alpha = 0.1;
lead = (T*s + 1) / (T*alpha*s + 1); % This is a high-pass filter with limited gain

bode(lead);
