% DS rldesign.22

G = zpk([-20], [-10, -4, -1], 10)

Tr = 0.2;
OS = 25;

zeta = -log(OS / 100) / sqrt(pi^2 + log(OS / 100)^2)

%% From table exact.2

wn = 1.25 / Tr

wd = wn * sqrt(1 - zeta^2);

phi = -zeta * wn + wd * i

%% Proportional Control Design

rlocus(G, 0:0.02:2)

K1 = 1.03;

%% Derivative Control Design

theta_c = pi - angle(evalfr(G, phi))
zc = real(phi) - imag(phi) / tan(theta_c)

Gc = zpk([zc], [], 1)

rlocus(Gc * K1 * G, 0:0.002:0.5)

K2 = 0.102

%% Simulation

G_cl = feedback(K2 * Gc * K1 * G, 1);
[y, t] = step(G_cl);
plot(t, y)

stepinfo(y, t)

pole(G_cl)