Understanding Matlab's Automatic Gain Control function I am trying to understand the automatic gain control block provided by the communications toolbox. The documentation is here: Documentation

My questions are in regards to two of the configurable parameters, the
DesiredOutputPower and MaxPowerGain.

Given a value X for DesiredOutputPower, how does one compute what the reference value A is?

Given a value X for MaxPowerGain, how does one compute what the upper limit for g is?

For example:

If DesiredOutputPower = 2 then A = 0.693147180559945

If DesiredOutputPower = 6 then A = 1.791759469228055

And

If MaxPowerGain = 10 then the upper limit for g is 1.15129255

If MaxPowerGain = 60 then the upper limit for g is 6.90775527

The documentation in regard to DesiredOutputPower states: 


  Specify the desired output power level as a real positive scalar. The
  power is measured in Watts referenced to 1 ohm. The default is 1.


And in regard to MaxPowerGain:


  Maximum power gain in decibels
  
  Specify the maximum gain of the AGC in decibels as a positive scalar.
  The default is 60.


How are these numbers determined? 
What are the formulas? I've been trying to apply the formulas I read here:
The dB in Communications
but I havent been able to figure it out, please help.

Thank you!
From the diagram in the Algorithms section of the documentation you can see how the different quantities are computed:


Note that $z$ in the diagram is an estimate of the output power.$^1$ The error signal $e$ is computed by comparing the reference value $A$ to $\ln(z)$. So if you choose $$A=\ln(P)\tag{1}$$ then the average output power will be adjusted to the specified value $P$.

Concerning the maximum gain, note that the input is multiplied by $\tilde{g}=e^g$. If $G$ is the maximum gain in dB, you have the following relationship:

$$G=20\log_{10}(\tilde{g})\tag{2}$$

i.e.,

$$\tilde{g}=10^{G/20}\tag{3}$$

and, consequently,

$$g=\ln(\tilde{g})=G\cdot \frac{\ln(10)}{20}\approx G\cdot  0.11513\tag{4}$$


1. There is an error in the diagram: the output of the detector must be multiplied by the square of the gain (because it's an estimate of the power). This is correctly represented by the equations below the diagram in the documentation.