% Bode Design
PM=45; ess=0.01;

numG=3*[1 3];
denG=conv([1 4],[1 3 20]);
G=tf(numG,denG);
bode(G); grid on; hold on;
[gainG,phaseG]=bode(G,20) % gain and phase at 20[rad/s]

% BW adjustment using gain
K=1/gainG
G1=K*G;
bode(G1); grid on; hold on;

% PM adjustment by a lead compensator
phi=PM-(180+phaseG)
% do offline: phi=atan(20/z)-atan(z/20) => find z=10.8
z=10.8; p=(20/sqrt(z))^2 % lead compensator pole and zero
CLe=tf([1 z],[1 p]);
[gainLe,phaseLe]=bode(CLe,20)
KLe=1/gainLe
G2=KLe*CLe*G1;
bode(G2); grid on; hold on;

% use lag CLa=(s+z)/(s+p) and evaluate E=1/(1+CLaG2) and find z/p>162.8
p=0.1; z=9.5*p;
CLa=tf([1 z],[1 p]);
G3=CLa*G2;
bode(G3);