---
url: /dyad/stable/analyses/closed_loop_sensitivity.md
description: >-
  Analyze the closed-loop sensitivity function S = 1/(1+PC) at one or several
  specified analysis points.
---

# Closed-Loop Sensitivity Analysis {#ClosedLoopSensitivityAnalysis}

Download as a Dyad projectClosedLoopSensitivityExample.zipOpen in Dyad Studio›

The Closed-Loop Sensitivity Analysis computes and visualizes the [sensitivity function](https://en.wikipedia.org/wiki/Sensitivity_\(control_systems\)) $S = 1/(1+PC)$ at one or several specified analysis points in a feedback system. This is useful for assessing the robustness of the closed-loop system to disturbances and model uncertainties.

## Method Overview {#Method-Overview}

The sensitivity function $S(s)$ is the fundamental closed-loop transfer function. In the block diagram

```
         ▲
         │e₁
         │  ┌─────┐
d₁────+──┴──►  P  ├─────┬──►e₄
      │     └─────┘    y│
      │u                │
      │     ┌─────┐    -│
 e₂◄──┴─────┤  C  ◄──┬──+───d₂
            └─────┘  │
                     │e₃
                     ▼
```

performing a sensitivity analysis at the analysis point `y` computes the *output* sensitivity function $S_o = 1/(1+PC)$ which is the transfer function between d₂ and e₃, while an analysis in the analysis point `u` computes the *input* sensitivity function $S_i = 1/(1+CP)$, which is the transfer function between d₁ and e₁. For SISO systems, $S_o = S_i$. The relationship between the sensitivity function and the complementary sensitivity $T$ function is given by $S + T = I$.

This analysis linearizes the model and computes the sensitivity function at the specified analysis point or points, optionally breaking feedback loops as needed.

The peak value of $|S(i\omega)|$ (the $H\_\infty$ norm) is related to classical robustness margins such as gain and phase margin. The margin bounds derived from this peak are shown in the Bode plot legend.

## 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 sensitivity function $S(s)$ at the plant output `y`.

We set `w_motor` to zero so the controller does not saturate at the linearization point. Since the analysis opens the loop at `r`, the connection to `controller.u_s` is broken during linearization. We provide an initial condition so the operating point is well-defined:&#xA;

```dyad
component DCMotorForSensitivity
  extends DyadExampleComponents.TestDCMotorLoadControlled(w_motor = 0)
relations
  guess controller.u_s = 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.proportional.y = 0
  guess controller.add_pid.y = 0
  guess controller.derivative.y = 0
end

analysis DCMotorClosedLoopSensitivityAnalysis
  extends DyadControlSystems.ClosedLoopSensitivityAnalysis(
    analysis_points = ["y"],
    loop_openings = ["r"],
    wl = 1.0,
    wu = 1e4,
    t = 0.0
  )
  model = DCMotorForSensitivity()
end
```

```julia
using DyadInterface: artifacts
using Plots
asol = DCMotorClosedLoopSensitivityAnalysis()
```

```ansi
ClosedLoopSensitivityAnalysisSolution
Analysis points: ["y"]
Loop openings: ["r"]
Frequency bounds: [1.0, 10000.0]
H∞ norm ||S(s)||: 1.9
Phase margin lower bound: 31.0°
Gain margin lower bound: 2.1

```

```julia
fig = artifacts(asol, :BodePlot)
plot!(legend = :bottomright)
```

![](slkgeoz.svg)

## Analysis Arguments {#Analysis-Arguments}

The following arguments define a ClosedLoopSensitivityAnalysis:

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

* `model`: The model to be analyzed.

* `analysis_points::Vector{String}`: Name of the analysis points where sensitivity is computed.

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

* `loop_openings::Vector{String} = []`: Names of loop openings to break feedback if present.

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

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

## Artifacts {#Artifacts}

A ClosedLoopSensitivityAnalysis returns the following artifact:

#### Standard Plot {#Standard-Plot}

* `BodePlot`: [Bode plot](https://en.wikipedia.org/wiki/Bode_plot) of the closed-loop sensitivity function $S(s)$. The plot includes the $H\_\infty$ norm (maximum value), and the corresponding minimum gain and phase margins. For MIMO analysis, the plot shows the singular values of the sensitivity function as a function of frequency.

## Further Reading {#Further-Reading}

* [Sensitivity (control systems) (Wikipedia)](https://en.wikipedia.org/wiki/Sensitivity_\(control_systems\))

* [Bode plot (Wikipedia)](https://en.wikipedia.org/wiki/Bode_plot)

* [Robustness (control theory) (Wikipedia)](https://en.wikipedia.org/wiki/Robust_control)

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