MATLAB: Does “margin” return one gain margin value when there are multiple and how does it choose which one to return

Control System Toolbox

Using the below transfer function:
>> num = [10 1];
>> den = [1 10 0 0];
>> sys = tf(num,den);
If I execute the "margin" function to obtain the Gain Margin "Gm":
>> [Gm,Pm,Wcg,Wcp] = margin(sys);
It returns the Gain Margin "Gm = 0" (in absolute units) and the phase crossover frequency is "w = 0 rad/s". In dB, the Gain Margin is – Inf dB.
But if you take a look at the bode plot of the transfer function:

You will notice a certain symmetry in the phase vs frequency plot. This indicates that there is a high probability that if phase crossover occurred at "w = 0 rad/s", another one will occur at "w = Inf rad/s". To confirm this hypothesis analytically, you can replace the "s" symbol in the Transfer Function with "w*j" such that "w" is the frequency and "j" is the unit imaginary number. As "w" goes to 0 or + Infinity, the phase is -180 degrees and the gain margin is 0 (- Inf) and + Inf (+ Inf) respectively. Basically, the above transfer function acts as "1/s^2" as "w" approaches both zero and Infinity.
So, why does "margin" only display the gain margin equal to – Inf? What can I do to get more information in situations like this when I have multiple gain margins? 

Best Answer

Indeed, two phase crossovers are occurring. The first phase crossover is at w = 0 rad/s with Gm = - Inf dB and the second is at w = + Inf rad/s with Gm = + Inf dB.
When there are multiple gain and/or phase margins for a certain transfer function, use of the function "allmargin" is advised. If you execute "allmargin", you get the below output:
 
>> allmargin(sys)
ans =
struct with fields:
GainMargin: [0 Inf]
GMFrequency: [0 Inf]
PhaseMargin: 78.5788
PMFrequency: 1
DelayMargin: 1.3715
DMFrequency: 1
Stable: 1
In the above output, "allmargin" returns both Gain Margins [0 Inf] (in absolute units) and their respective crossover frequencies [0 Inf].
The reason why "margin" only returns Gain Margin equal to 0 is due to the following:
In situations where there are two gain margins, "margin" returns the smallest gain change needed to cause instability, which is the value closest to Gain = 1 (i.e., no change). So if "allmargin" returns [0.9 1.5], for example, 0.9 wins because it is a smaller relative change (-10%) than 1.5 (+50%). The function was designed in this way under the assumption that, in most instances, control systems designers are usually interested in how close/far they are from instability. So, the lower gain margin value indicates the smallest margin to instability.
In the example transfer function we are dealing with in this post, there are two crossovers frequencies (0 and +Inf) with corresponding factors Gm = 0 and Gm = Inf. Both are equally far from Gain = 1 in log scale so it is a tie. "margin" could theoretically return -Inf dB or +Inf dB. But, since it is a tie, the algorithm returned the lower value in absolute terms. In these situations, the use of "allmargin" is ideal as it is meant to give the fuller picture.