%% Modeling Gain and Phase Variations
% Both umargin and diskmargin represent gain and phase variation as a multiplicative complex factor F(s), replacing the nominal open-loop response L(s) with L(s)*F(s). The factor F takes values in a disk that includes the nominal value F = 1. This multiplicative factor models both gain and phase variations. For instance, the following plot shows one such disk in the complex plane.
%

DGM = [0.6,1.7];
diskmarginplot(DGM,'disk')

% The values in this disk encompass relative gain-only variations in the range DGM = [0.6,1.7], or ±4 dB. They also represent absolute phase-only variations of DPM = [–29,29], or  ±29°. Consider the following closed-loop system, with nominal loop transfer L and unit feedback.
%
% If this feedback loop remains stable for all values of F in the disk shown in the previous plot, then the disk-based gain margin of L is at least DGM, and the disk-based phase margin is at least DPM.
%
% Both umargin and diskmargin model gain and phase uncertainty with a family of disks described by two parameters, α and σ. For SISO systems, the disk is parameterized by:
% F=\frac{1+\alpha \left\lbrack \left(1-\sigma \right)/2\right\rbrack \delta }{1-\alpha \left\lbrack \left(1+\sigma \right)/2\right\rbrack \delta }\ldotp
% In this model,
% δ is the normalized uncertainty (an arbitrary complex value in the unit disk |δ| < 1).
% α sets the amount of gain and phase variation modeled by F. For fixed σ, the parameter α controls the size of the disk. For α = 0, the multiplicative factor is 1, corresponding to the nominal L.
% σ, called the skew, biases the modeled uncertainty toward gain increase or gain decrease.
% Each α,σ pair corresponds to a disk that models a particular gain-variation range DGM = [gmin,gmax], given by the points where the disk intercepts the real (x) axis. The corresponding phase variation DPM is determined by the angle between the real axis and a line through the origin and tangent to the disk. Thus you can describe a modeled set of gain and phase variations entirely by either the two values α,σ or the two values DGM = [gmin,gmax]. σ = 0 models a balanced gain variation with [gmin,gmax] such that gmin = 1/gmax. When σ < 0, then F represents a larger gain decrease than increase (gmin < 1/gmax). Conversely σ > 0 represents a larger gain increase than decrease. For instance, consider the disks parameterized by α = 0.5 and three different skews, σ = –2, 0, and 2.

diskmarginplot(0.5,[-2 0 2],'disk')

%
% Each  α,σ pair corresponds to a disk that models a different gain-variation range DGM = [gmin,gmax]. Examine the gain variations that correspond to each of these three disks.

Ranges = dm2gm(0.5,[-2  0 2])
diskmarginplot(Ranges)

% The balanced σ = 0 range is symmetric around the nominal value, allowing the gain to increase or decrease by a factor of about 1.67. The negative σ value corresponds to more gain decrease than increase, while positive σ gives more increase than decrease.
% The umargin control design block uses this model to represent gain and phase uncertainty in a feedback loop, setting α and σ from the gain and phase margin values you specify when you create the block. The diskmargin command uses this model to compute disk-based gain and phase margins as discussed in the next section.
%
% Copyright 2019 The MathWorks, Inc.