---
url: /dyad/stable/analyses/closed_loop.md
description: >-
  Analyze the closed-loop properties of a feedback interconnection through
  linearization and frequency-domain analysis.
---

# Closed-Loop Analysis {#ClosedLoopAnalysis}

Download as a Dyad projectClosedLoopExample.zipOpen in Dyad Studio›

The Closed-Loop Analysis computes and visualizes the frequency- and time-domain properties of a feedback system by linearizing the model around an operating point. This analysis is useful for assessing stability, robustness, and performance of the closed-loop system.

## Method Overview {#Method-Overview}

The analysis considers the standard feedback interconnection:

```
              d             
     ┌─────┐  │  ┌─────┐    
r  e │     │u ▼  │     │ y  
──+─►│  C  ├──+─►│  P  ├─┬─►
  ▲  │     │     │     │ │  
 -│  └─────┘     └─────┘ │  
  │                      │  
  └──────────────────────┘  
```

where `C` is the controller, `P` is the plant, `r` is the reference, `d` is an input disturbance, `y` is the measured output, and `u` is the control input.

The analysis linearizes the model and computes:

* Closed-loop transfer functions:
  * Sensitivity: $S = 1/(1+PC)$. For MIMO systems, the output sensitivity is computed.

  * Complementary sensitivity: $T = PC/(1+PC)$

  * Controller sensitivity: $C/(1+PC)$

  * Plant sensitivity: $P/(1+PC)$

* Robustness margins:
  * Disk margin (combined gain and phase margin). For MIMO systems, the simultaneous margin at the output is computed.

  * Classical gain and phase margins

* Step responses to reference and disturbance inputs

## Example Definition {#Example-Definition}

This example is a continuation of the [DC Motor Control](/tutorials/standard-libraries#tutorial-dc-motor) tutorial. We will analyze the closed-loop properties of the transfer function from load disturbance (entering at the plant input `u`) to output `y`.

Since the closed-loop analysis internally opens the loop at both the measurement `y` and control input `u` (in addition to the specified `r`), the variables `controller.u_s`, `controller.u_m`, and `source.V` are disconnected during linearization. We provide initial conditions so that the operating point is well-defined:&#xA;

```dyad
component DCMotorForClosedLoop
  extends DyadExampleComponents.TestDCMotorLoadControlled(w_motor = 0)
relations
  guess controller.u_s = 0
  guess controller.u_m = 0
  guess source.V = 0
  guess motor.R1.v = 0
  guess motor.emf.tau = 0
  guess motor.emf.rotor.tau = 0
  guess motor.emf.rotor.phi = 0
  guess motor.emf.p.i = 0
  guess motor.friction.phi_rel = 0
  guess load.phi = 0
  guess controller.add_pid.y = 0
  guess controller.derivative.y = 0
end

analysis DCMotorClosedLoopAnalysis
  extends DyadControlSystems.ClosedLoopAnalysis(
    measurement   = ["y"],
    control_input = ["u"],
    loop_openings = ["r"],
    wl = 1.0,
    wu = 1e4,
    t = 0.0,
    num_frequencies = 300,
    pos_feedback = true,
    duration = 2.0
  )
  model = DCMotorForClosedLoop()
end
```

```julia
using DyadInterface: artifacts
asol = DCMotorClosedLoopAnalysis()
```

```ansi
ClosedLoopAnalysisSolution
Phase margin (disk based): 67.3°
Gain margin (disk based): ["0.2", "5.0"]

```

```julia
using Plots
plot!(artifacts(asol, :all); size=(1200,1200))
```

![](doffbrl.svg)

## Analysis Arguments {#Analysis-Arguments}

The following arguments define a ClosedLoopAnalysis:

#### Required Arguments {#Required-Arguments}

* `model`: The model to be analyzed.

* `measurement::Vector{String}`: Name of the measurement signal analysis points (plant outputs).

* `control_input::Vector{String}`: Name of the control input signal analysis points.

#### Optional Arguments {#Optional-Arguments}

* `loop_openings::Vector{String} = String[]`: Names of additional analysis points at which the loop is opened during linearization (e.g. the reference input `"r"`).

* `wl::Real = -1`: Lower frequency bound for analysis (set to -1 for automatic selection).

* `wu::Real = -1`: Upper frequency bound for analysis (set to -1 for automatic selection).

* `num_frequencies::Int = 300`: Number of frequency points.

* `t::Real = 0.0`: Time at which the model is linearized for the analysis.

* `pos_feedback::Bool = true`: Whether the feedback is positive (default is true; negative feedback is often built into the model).

* `duration::Real = -1.0`: Duration of the step-response simulation (set to -1 for automatic selection).

## Artifacts {#Artifacts}

A ClosedLoopAnalysis returns the following artifacts:

#### Standard Plots {#Standard-Plots}

* `all`: Combined plot showing:
  * Bode plots of $S$, $T$, $C/(1+PC)$, $P/(1+PC)$

  * Disk margin and classical margins

  * Step responses to reference and disturbance steps

## Further Reading {#Further-Reading}

* [ControlSystems.jl documentation](https://juliacontrol.github.io/ControlSystems.jl/dev/)

* [Disk margin (RobustAndOptimalControl.jl)](https://juliacontrol.github.io/RobustAndOptimalControl.jl/dev/)

* [Feedback control (Wikipedia)](https://en.wikipedia.org/wiki/Feedback)

## Notes about MIMO Systems {#Notes-about-MIMO-Systems}

When MIMO systems are analyzed, some sensitivity functions are drawn as Sigma plots rather than Bode plots. The disk margin is in this case computed for the output loop-transfer function $L_o = PC$, that is, the margin for simultaneous output-perturbations is analyzed. This is generally a conservative analysis. All computed sensitivity functions are computed at the plant output (using the loop-transfer function $L_o = PC$ rather than $L_i = CP$).
