Zero gain margin for an stable system from both allmargin and margin

Hi there,
I have the following open-loop transfer function
s=tf('s');
OL_tf = (5.782*s^2 + 1.395*s + 0.1361)/(s^3 + 4*s^2);
margin_numbers = allmargin(OL_tf);
gain_margin = margin_numbers.GainMargin
CL_tf = minreal(OL_tf/(1+OL_tf));
CL_poles = roots(CL_tf.den{1})
margin_numbers.Stable
You can see that gain_margin = 0 while CL_poles are stable, also margin_numbers.Stable = 1 means that it is stable. The closed-loop is definitely stable, what should we say about the commands in this case?
Thanks,
Dave

Answers (1)

I believe that allmargin yields a result that a user could incorrectly interpret for this example.
Define the open-loop transfer function and call allmargin
s=tf('s');
OL_tf = (5.782*s^2 + 1.395*s + 0.1361)/(s^3 + 4*s^2);
margin_numbers = allmargin(OL_tf)
margin_numbers = struct with fields:
GainMargin: 0 GMFrequency: 0 PhaseMargin: 130.4460 PMFrequency: 4.1776 DelayMargin: 0.5450 DMFrequency: 4.1776 Stable: 1
allmargin claims the gain margin is zero at zero rad/sec. The user might interpret that to mean that if the DC gain were to be made zero then the closed loop system would become unstable. But that interpretation would be incorrect.
Plot the Bode plot of the open loop transfer function.
w = logspace(-2,2,100);
[m,p] = bode(OL_tf,w);m = squeeze(m);p = squeeze(p);
figure
subplot(211),semilogx(w,db(m)),hold on;semilogx(w(1),db(m(1)),'rd');ylabel('dB'),grid
subplot(212),semilogx(w,p),hold on;semilogx(w(1),p(1),'rd');,grid,yline(-180),ylabel('deg');xlabel('rad/sec')
As expected, the phase approaches -180 deg as omega goes towards zero due to the double pole at the origin. allmargin hunts for frequencies where the phase crosses +-180 deg and employs special logic at omega = 0 for poles at the origin. In this example, that logic sets the phase = -180 at omega = 0 and declares a phase crossover frequency at omega = 0, then computes the gain margin as 1/OL_tf(0) = 1/inf = 0 because the gain is infinite due to poles at s = 0.
However, this approach is incorrect for computing the gain margin because the Nyquist contour cannot include the origin. Rather, the Nyquist contour must make a small, semi-circular indentation around the origin (in the right-half-plane by convention) and so the Nyquist plot itself never actually crosses the negative real axis where the phase would be 180 deg. Instead, the Nyquist plot only approaches the negative real axis in the limit as the radius of the indentation gets smaller. Consequently there is no phase crossover and, therefore, a gain margin does not exist.
Define a portion of the Nyquist contour that starts on the negative imaginary axis, travels up towards the origin, indents around to the right of the origin, and continues up the positive imaginary axis
theta = linspace(-1/2,1/2,100)*pi;
s = [fliplr(-1j*w),w(1)*exp(1j*theta),1j*w];
Compute and plot the portion of the Nyquist plot that corresponds to this portion of the contour. The red diamond corresponds to the same on the Bode plot above.
h = squeeze(freqresp(OL_tf,s));
figure
plot(real(h),imag(h)),grid
hold on
plot(real(h(201)),imag(h(201)),'rd')
The -1 point is safely tucked away inside that open wedge on the left (it's hard to show the -1 point on this scale). The large, circular arc results from the double pole at the origin. The red diamond corner point would extend farther to the left and get closer to the negative real axis if we made w(1) smaller for this analysis, but the Nyquist plot would never cross the negative real axis.
There is no gain that can be applied to OL_tf that would cause an encirclement of the -1 point, hence a gain margin does not exist.
All allmargin does is look for frequencies where the phase curve crosses or approaches 180 deg, and then computes the gain "margin" at those frequencies. However, applying those margins at those frequencies might not change the number of encirclements of the -1 point by the Nyquist plot, as is the case here. Hence, the term "margins" might be misleading in this situation.

Products

Release

R2015a

Asked:

on 7 Oct 2019

Edited:

on 31 Mar 2026 at 21:43

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!