%% Loop Shape and Crossover Tolerance
% Create a target gain profile requirement for the following control system. Specify integral action, gain crossover at 1, and a roll-off requirement of 40 dB/decade.
%
% The requirement should apply to the open-loop response measured at the AnalysisPoint block X. Specify a crossover tolerance of 0.5 decades.

LS = frd([100 1 0.0001],[0.01 1 100]);
Req = TuningGoal.LoopShape('X',LS,0.5);

%
% The software converts LS into a smooth function of frequency that approximates the piecewise-specified requirement. Display the requirement using viewGoal.

viewGoal(Req)

% The green and red regions indicate the bounds for the inverse sensitivity, inv(S) = 1-G*C, and the complementary sensitivity, T = 1-S, respectively. The gap between these regions at 0 dB gain reflects the specified crossover tolerance, which is half a decade to either side of the target loop crossover.
% When you use viewGoal(Req,CL) to validate a tuned closed-loop model of this control system, CL, the tuned values of S and T are also plotted.
% Copyright 2012 The MathWorks, Inc.