---
title: "GainPhaseMargins"
language: "en"
type: "Symbol"
summary: "GainPhaseMargins[lsys] gives the gain and phase margins of the linear time-invariant system lsys."
keywords: 
- gain phase margins
- gain margin
- phase margin
- gain crossover frequency
- phase crossover frequency
- stability margins
- rolloff
- classical control
- control systems
- control theory
- margin
canonical_url: "https://reference.wolfram.com/language/ref/GainPhaseMargins.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Classical Analysis and Design"
    link: "https://reference.wolfram.com/language/guide/ClassicalAnalysisAndDesign.en.md"
related_functions: 
  - 
    title: "GainMargins"
    link: "https://reference.wolfram.com/language/ref/GainMargins.en.md"
  - 
    title: "PhaseMargins"
    link: "https://reference.wolfram.com/language/ref/PhaseMargins.en.md"
  - 
    title: "StabilityMargins"
    link: "https://reference.wolfram.com/language/ref/StabilityMargins.en.md"
  - 
    title: "BodePlot"
    link: "https://reference.wolfram.com/language/ref/BodePlot.en.md"
  - 
    title: "NyquistPlot"
    link: "https://reference.wolfram.com/language/ref/NyquistPlot.en.md"
  - 
    title: "NicholsPlot"
    link: "https://reference.wolfram.com/language/ref/NicholsPlot.en.md"
  - 
    title: "TransferFunctionModel"
    link: "https://reference.wolfram.com/language/ref/TransferFunctionModel.en.md"
---
# GainPhaseMargins

GainPhaseMargins[lsys] gives the gain and phase margins of the linear time-invariant system lsys.

## Details and Options

* The system ``lsys`` can be a ``TransferFunctionModel`` or a ``StateSpaceModel``.

* ``GainPhaseMargins`` returns ``{{{ωp1, g1}, {ωp2, g2}, …}, {{ωg1, p1}, {ωg2, p2}, …}}``, where the ``ωpi`` are the phase crossover frequencies, the ``gi`` are the gain margins, the ``ωgi`` are the gain crossover frequencies, and the ``pi`` are the phase margins.

* The gain margins ``gi`` are absolute values and the phase margins ``pi`` are in radians.

* The gain margins are the reciprocals of the magnitude of ``lsys`` at the phase crossover frequencies.

* At the phase crossover frequencies, ``lsys`` has phase $-180 {}^{\circ}$.

* The phase margins are phase lags needed to make the phase $-180 {}^{\circ}$ at the gain crossover frequencies.

* At the gain crossover frequencies, the gain of ``lsys`` is unity.

* The following options can be given:

|                |            |                     |
| -------------- | ---------- | ------------------- |
| FeedbackType   | "Negative" | the feedback type   |
| Method         | Automatic  | method to use       |
| SamplingPeriod | None       | the sampling period |

* Explicit settings for the ``Method`` option include ``"Solve"`` and ``"NSolve"``. In each case the methods of ``Solve`` or ``NSolve`` can be specified as suboptions. The default setting of ``Automatic`` switches between these methods, depending on whether ``lsys`` is exact or inexact.

* ``GainPhaseMargins`` has the attribute ``Listable``.

---

## Examples (9)

### Basic Examples (1)

The gain and phase margins of a system:

```wl
In[1]:=
GainPhaseMargins[TransferFunctionModel[{{{10}}, (1 + s)*(2 + s)*(3 + s)}, 
 s]]

Out[1]= {{{Sqrt[11], 6}}, {{1, (π/2)}}}
```

### Scope (3)

A system with multiple crossover frequencies:

```wl
In[1]:=
tfm = TransferFunctionModel[
 {{{85*(43.25 + 45.25*s + 3*s^2 + s^3)}}, 
  8282*s^2 + 366*s^3 + 187*s^4 + 4*s^5 + 
   s^6}, s];

In[2]:= {gm, pm} = GainPhaseMargins[tfm]

Out[2]= {{{10.3431, 1.26245}}, {{0.743648, 0.641179}, {9.83883, 0.682599}, {9.45112, 1.25977}}}
```

The number of gain crossover frequencies:

```wl
In[3]:= Length[pm]

Out[3]= 3
```

---

A discrete-time system:

```wl
In[1]:=
GainPhaseMargins[TransferFunctionModel[{{{2 + z}}, 0.88 - z + z^2}, 
 z, SamplingPeriod -> 2]]

Out[1]= {{{0.540753, 0.06}}, {{1.00754, -1.43336}}}
```

---

Margins of a time-delay system:

```wl
In[1]:= GainPhaseMargins[TransferFunctionModel[{{{-6}}, E^s*(-1 + s^2)}, s]]
```

Mod::indet: Indeterminate expression Mod[0,0] encountered.

```wl
Out[1]= {{{All, Indeterminate}}, {{None, ∞}}}
```

### Generalizations & Extensions (1)

``GainPhaseMargins[TransferFunctionModel[g, var]]`` equals ``GainPhaseMargins[g]`` :

```wl
In[1]:= g = (6/6 + 3 s + 4 s^2 + s^3);

In[2]:= GainPhaseMargins[TransferFunctionModel[g, s]] == GainPhaseMargins[g]

Out[2]= True
```

### Options (2)

#### FeedbackType (2)

The system is assumed to be the loop transfer function of a negative-feedback system:

```wl
In[1]:=
lsys = N[TransferFunctionModel[{{{6}}, (2 + s)*(2 + 2*s + s^2)}, 
 s]];

In[2]:= GainPhaseMargins[lsys]

Out[2]= {{{2.44949, 3.33333}}, {{1.25284, 1.18129}}}
```

Specify the system as part of a positive-feedback system:

```wl
In[3]:= GainPhaseMargins[SystemsModelSeriesConnect[TransferFunctionModel[{{{-1}}, 1}, s], lsys], FeedbackType -> "Positive"]

Out[3]= {{{2.44949, 3.33333}}, {{1.25284, 1.18129}}}
```

Specify the system as a closed-loop system:

```wl
In[4]:= GainPhaseMargins[SystemsModelFeedbackConnect[lsys], FeedbackType -> None]

Out[4]= {{{2.44949, 3.33333}}, {{1.25284, 1.18129}}}
```

---

A positive-feedback system:

```wl
In[1]:=
GainPhaseMargins[N[TransferFunctionModel[{{{-10000}}, (-5 + s)*(20 + s)*
   (50 + s)}, s]], FeedbackType -> "Positive"]

Out[1]= {{{0., 0.5}, {25.4951, 4.725}}, {{7.74164, 0.474405}}}
```

### Properties & Relations (2)

The gain and phase margins can be visualized on all the frequency response plots:

```wl
In[1]:=
tfm = TransferFunctionModel[{{{10.}}, (1 + s)*(2 + s)*(3 + s)}, 
 s];

In[2]:= {gm, pm} = GainPhaseMargins[tfm]

Out[2]= {{{3.31662, 6.}}, {{1., 1.5708}}}
```

The Bode plot:

```wl
In[3]:= BodePlot[tfm, StabilityMargins -> {gm, pm}, StabilityMarginsStyle -> {Red, Green}, ImageSize -> Small]

Out[3]=
|         |
| ------- |
| [image] |
| [image] |
```

The Nyquist plot:

```wl
In[4]:= NyquistPlot[tfm, StabilityMargins -> {gm, pm}, StabilityMarginsStyle -> {Directive[Red, Thick], Directive[Green, Thick]}]

Out[4]= [image]
```

The Nichols plot:

```wl
In[5]:= NicholsPlot[tfm, StabilityMargins -> {gm, pm}, StabilityMarginsStyle -> {Red, Green}]

Out[5]= [image]
```

The gain margins in decibels:

```wl
In[6]:= gm /. {f_, m_} :> {f, 20 Log10[m]}

Out[6]= {{3.31662, 15.563}}
```

The phase margins in degrees:

```wl
In[7]:= pm /. {f_, m_} :> {f, (m/Degree)}

Out[7]= {{1., 90.}}
```

If the crossover frequencies are in radians/second, they can be converted to hertz as follows:

```wl
In[8]:= Replace[{gm, pm}, {f_, m_} :> {(f/2π), m}, {2}]

Out[8]= {{{0.527857, 6.}}, {{0.159155, 1.5708}}}
```

---

The setting ``StabilityMargins -> True`` computes and draws the gain and phase margins:

```wl
In[1]:=
BodePlot[TransferFunctionModel[{{{-10}}, (1 + 0.2*s)*(1 + 0.5*s)*s^2*
   (1 + s)*(5 + s)}, s], {0.5, 10}, StabilityMargins -> True, ImageSize -> Small]

Out[1]=
|         |
| ------- |
| [image] |
| [image] |
```

## See Also

* [`GainMargins`](https://reference.wolfram.com/language/ref/GainMargins.en.md)
* [`PhaseMargins`](https://reference.wolfram.com/language/ref/PhaseMargins.en.md)
* [`StabilityMargins`](https://reference.wolfram.com/language/ref/StabilityMargins.en.md)
* [`BodePlot`](https://reference.wolfram.com/language/ref/BodePlot.en.md)
* [`NyquistPlot`](https://reference.wolfram.com/language/ref/NyquistPlot.en.md)
* [`NicholsPlot`](https://reference.wolfram.com/language/ref/NicholsPlot.en.md)
* [`TransferFunctionModel`](https://reference.wolfram.com/language/ref/TransferFunctionModel.en.md)

## Related Guides

* [Classical Analysis and Design](https://reference.wolfram.com/language/guide/ClassicalAnalysisAndDesign.en.md)

## History

* [Introduced in 2010 (8.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn80.en.md)