wB=10;     % desired closed-loop bandwidth
A=1e-4;  % desired disturbance attenuation inside bandwidth
M=1.7;      % desired bound on hinfnorm(S) & hinfnorm(T)
n=1;    % the slope of the weight function
WP=zpk([-wB*M^(1/n)*ones(n,1)],[-wB*A^(1/n)*ones(n,1)],1/M);
WT=zpk([-wB/(M^(1/n))*ones(n,1)],[-wB/(A^(1/n))*ones(n,1)],1/A);

 WU=zpk([],[],1/3);
% WU=WT;

G=tf([10],[0.1 1 1]);
Gd=0.56*G;

[K,CL,GAM,INFO]=mixsyn(G,WP,WU,WT);
Unit=zpk([],[],1);
L=series(G,K*1.1);
T=L/(1+L);
S=1-T;

figure(1);
bodemag(1/WP);
hold on;
bodemag(1/WT);
hold off;
title('Weight functions 1/W_P and 1/W_T')

figure(2);
bodemag(1/WP);
hold on;
bodemag(S);
hold off;
title('Sensitivity function S(s) vs 1/W_P')

figure(3);
bodemag(1/WT);
hold on;
bodemag(T);
hold off;
title('Sensitivity function T(s) vs 1/W_T')

figure(4);
bode(K);
title('Controller freq response')

figure(5);
margin(L);

figure(6);
step(T);
title('Step reference response');

figure(7);
step(S*Gd);
title('Step disturbance response');

figure(8);
bode(G);
title('Plant freq response')

figure(9);
step(S*K);

% figure(10);
% bodemag(S*K);
% hold on;
% bodemag(1/WU);
% hold off;
% title('Input function S(s)K(s) vs 1/W_U')




