Toolvito

Works on this device

Gain Margin Calculator

Type the open-loop transfer function G(s) of a feedback loop, or points from its Bode plot. The calculator finds where the phase is −180° and how much the gain can rise there before the closed loop reaches the edge of stability.

Enter your values

Type the open-loop transfer function G(s) = K × N(s) ÷ D(s), with a time delay if there is one.

Your values

A polynomial in s. You can multiply brackets, such as 2(s + 3) or (0.5s + 1)^2.

A polynomial in s, such as s(s + 1)(s + 5) or s^3 + 6s^2 + 5s.

A number that multiplies N(s) ÷ D(s). Keep 1 when the gain is already in N(s).

A dead time e^(−sT) in the loop. Keep 0 when there is none.

More options

Leave both frequencies empty for a range chosen from the poles, zeros and crossovers.

Your values are worked out in this browser. They are not sent to a server.

Your result will show here

Fill in the values, then choose Calculate.

How to use this calculator

  1. Choose Gain margin of a transfer function G(s).
  2. Type the numerator N(s) and the denominator D(s) as polynomials in s, such as 10 and s(s + 1)(s + 5). You can also choose to type lists of coefficients, highest power first.
  3. Type the gain K and, if the loop has a dead time, the time delay T.
  4. Choose Calculate. The result gives the gain margin in dB and as a ratio, the phase crossover frequency, the phase margin, every crossover in a table, the poles and zeros, and the Bode magnitude and phase charts.
  5. If you only have measured points, choose Gain margin from frequency response points and type or paste frequency, magnitude and phase on each line.

The formulas

  • The loop transfer function is G(s) = K × N(s) ÷ D(s) × e^(−sT). The frequency response is G(jω), with ω in rad/s.
  • Phase crossover frequency ω_pc: the frequency where the phase of G(jω) is −180° (modulo 360°), so G(jω_pc) is a negative real number.
  • Gain margin: GM = 1 ÷ |G(jω_pc)| as a ratio, or GM = −20 log10 |G(jω_pc)| in dB.
  • Gain at the edge of stability: K × GM. With this gain the Nyquist curve passes through the point −1.
  • Phase margin (also shown): PM = 180° + the phase of G(jω_gc), where |G(jω_gc)| = 1 (0 dB). The Phase Margin Calculator explains it.
  • Delay margin: PM in radians ÷ ω_gc, the extra dead time that would use up the phase margin.

How the crossovers are found

Write N(jω) = A(ω²) + jω B(ω²) and D(jω) = C(ω²) + jω E(ω²). With x = ω², the gain crossovers are the roots of P(x) = K²(A² + xB²) − (C² + xE²), and without a time delay the phase crossovers are the roots of R(x) = BC − AE where the real part of G is negative. Both are exact polynomials. The calculator isolates their real roots with a Sturm sequence in exact fractions and narrows each root by bisection until the interval is narrower than 2^−52 of x.

A time delay e^(−sT) is used exactly: it keeps |G| and turns the phase by −ωT radians. Then the phase crossovers are found by a scan of the continuous phase over the frequency range of the charts, followed by bisection to 10^−13 of ω. A common factor of N(s) and D(s) is cancelled first.

Worked example

Take G(s) = 10 ÷ (s(s + 1)(s + 5)). Its phase is −90° − arctan ω − arctan(ω ÷ 5). It is −180° when arctan ω + arctan(ω ÷ 5) = 90°, that is when ω × ω ÷ 5 = 1, so ω_pc = √5 = 2.236 rad/s.

There |G| = 10 ÷ (√5 × √6 × √30) = 10 ÷ 30 = 1/3. So the gain margin is 3, or 20 log10 3 = 9.54 dB. The gain can be 3 times larger before the closed loop is at the edge of stability.

The gain crossover is at ω_gc = 1.227 rad/s, where the phase is −154.6°, so the phase margin is 25.4° and the delay margin is 0.361 s.

Limits you should know

  • The margins describe a loop closed with negative feedback (−1). They tell you how close the closed loop is to instability only when G(s) has no poles in the right half-plane and the usual Bode reading holds. The result counts the right half-plane poles and warns you; otherwise use the Nyquist test.
  • Polynomials up to degree 12 are accepted. Roots of N and D come from a floating-point iteration, so a root that lies within 10^−7 of its size from an axis is read as lying on that axis.
  • With a time delay there are endless phase crossovers. Only those in the range of the charts are looked for, and at most 100 are listed. You can widen the range under More options.
  • From points, the crossovers come from straight lines between neighbouring points against log10 of the frequency, so they are only as good as the points.
  • This is a study and design aid. It does not replace tests of the real system.

Related tools