%% Smallest Disk-Based Gain Margin Corresponding to Gain and Phase Margins
% Find the smallest disk-based gain margin that represents relative a gain variation of ±6 dB relative to the nominal value and phase variation of ±40°. Convert the gain variation into absolute units.

GM = db2mag(6)
PM = 40;
DGM = getDGM(GM,PM,'tight')

% DGM describes a disk that models both gain and phase variations. The values in DGM represent the range of gain variation in the absence of phase variation. Note that the DGM range is slightly larger than the specified [1/GM,GM] range as the phase margin requirement is more stringent and determines the disk size. Visualize the full range of gain and phase variations represented by DGM.

diskmarginplot(DGM)

% The 'tight' constraint computes the smallest disk that delivers both target gain and phase variations, which does not necessarily represent a symmetric gain range. In this case, the disk represents gain that can decrease somewhat more than it can increase. Examine the disk of uncertainty defined by this particular DGM.

diskmarginplot(DGM,'disk')

% To enforce symmetric gain variation, use the 'balanced' option.
% Copyright 2019 The MathWorks, Inc.