%% Maximum Loop Gain Tuning Goal
% Create a tuning goal that limits the maximum open-loop gain of a feedback loop to a specified profile.
% Suppose that you are tuning a control system that has a loop-opening location identified by PILoop. Limit the open-loop gain measured at that location to 1 (0 dB) at 1 rad/s, rolling off at a rate of -20 dB/dec up to 10 rad/s, and a rate of -40 dB/dec at higher frequencies. Use an frd model to sketch this gain profile.

loopgain = frd([1 1e-1 1e-3],[1 10 100]);
Req = TuningGoal.MaxLoopGain('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 gain profile. The shaded region indicates where the tuning goal is violated, except that gain values greater than 1 are not enforced. Therefore, this tuning goal only specifies minimum roll-off rates at frequencies above 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.