%% Normalized Coprime Stability Margin
% Consider an unstable first-order plant, p, stabilized by high-gain and low-gain controllers, cL and cH.

p = tf(4,[1 -0.001]); 	
cL = 1;				
cH = 10;

%
% Compute the stability margin of the closed-loop system with the low-gain controller.

[margL,~] = ncfmargin(p,cL)

%
% Similarly, compute the stability margin of the closed-loop system with the high-gain controller.

[margH,~] = ncfmargin(p,cH)

%
% The closed-loop systems with low-gain and high-gain controllers have normalized coprime stability margins of about 0.71 and 0.1, respectively. This result indicates that the closed-loop system with low-gain controller is more robust to unstructured perturbations than the system with the high-gain controller.
% To observe this difference in robustness, construct an uncertain plant, punc, that has additional unmodeled dynamics at high frequency compared to the nominal plant.

punc = p + ultidyn('uncstruc',[1 1],'Bound',1);
sigma(p,punc,'r--')

%
% Calculate the robust stability of the closed-loop systems formed by the uncertain plant and each controller.

[stabmargL,~] = robstab(feedback(punc,cL))

%

[stabmargH,~] = robstab(feedback(punc,cH))

% As expected, the robust stability analysis shows that the closed-loop system with low-gain controller is more robustly stable in the presence of the unmodeled LTI dynamics. In fact, this closed-loop system can tolerate almost 100% of the specified uncertainty. In contrast, closed-loop system with the high-gain controller can tolerate only about 10% of the specified uncertainty.
% Copyright 2012 The MathWorks, Inc.