%% Minimum Loop Gain Tuning Goal
% Create a tuning goal that boosts the open-loop gain of a feedback loop to at least a specified profile.
% Suppose that you are tuning a control system that has a loop-opening location identified by PILoop. Specify that the open-loop gain measured at that location exceeds a minimum gain of 10 (20 dB) below 0.1 rad/s, rolling off at a rate of -20 dB/dec at higher frequencies. Use an frd model to sketch this gain profile.

loopgain = frd([10 10 0.1],[0 1e-1 10]);
Req = TuningGoal.MinLoopGain('PILoop',loopgain);

%
% The software converts loopgain into a smooth function of frequency that approximates the piecewise-specified gain profile. Display the tuning goal using viewGoal.

viewGoal(Req)

% The dashed line shows the specified the gain profile. The shaded region indicates where the tuning goal is violated, except that gain values less than 1 are not enforced. Therefore, this tuning goal only specifies a minimum gain at frequencies below 1 rad/s.
% You can use Req as an input to looptune or systune when tuning the control system. Then use viewGoal(Req,T) to compare the tuned loop gain to the minimum gain specified in the tuning goal, where T represents the tuned control system.
% Copyright 2012 The MathWorks, Inc.