|
1 | 1 | """ |
2 | | -Plotting routines for the Matlab compatibility module |
| 2 | +Wrappers for the Matlab compatibility module |
3 | 3 | """ |
4 | 4 |
|
5 | 5 | import numpy as np |
| 6 | +from ..statesp import ss |
| 7 | +from ..xferfcn import tf |
| 8 | +from scipy.signal import zpk2tf |
6 | 9 |
|
7 | | -__all__ = ['bode', 'ngrid'] |
| 10 | +__all__ = ['bode', 'ngrid', 'dcgain'] |
8 | 11 |
|
9 | 12 | def bode(*args, **keywords): |
10 | 13 | """Bode plot of the frequency response |
@@ -103,3 +106,54 @@ def bode(*args, **keywords): |
103 | 106 | def ngrid(): |
104 | 107 | return nichols_grid() |
105 | 108 | ngrid.__doc__ = nichols_grid.__doc__ |
| 109 | + |
| 110 | +def dcgain(*args): |
| 111 | + ''' |
| 112 | + Compute the gain of the system in steady state. |
| 113 | +
|
| 114 | + The function takes either 1, 2, 3, or 4 parameters: |
| 115 | +
|
| 116 | + Parameters |
| 117 | + ---------- |
| 118 | + A, B, C, D: array-like |
| 119 | + A linear system in state space form. |
| 120 | + Z, P, k: array-like, array-like, number |
| 121 | + A linear system in zero, pole, gain form. |
| 122 | + num, den: array-like |
| 123 | + A linear system in transfer function form. |
| 124 | + sys: LTI (StateSpace or TransferFunction) |
| 125 | + A linear system object. |
| 126 | +
|
| 127 | + Returns |
| 128 | + ------- |
| 129 | + gain: ndarray |
| 130 | + The gain of each output versus each input: |
| 131 | + :math:`y = gain \cdot u` |
| 132 | +
|
| 133 | + Notes |
| 134 | + ----- |
| 135 | + This function is only useful for systems with invertible system |
| 136 | + matrix ``A``. |
| 137 | +
|
| 138 | + All systems are first converted to state space form. The function then |
| 139 | + computes: |
| 140 | +
|
| 141 | + .. math:: gain = - C \cdot A^{-1} \cdot B + D |
| 142 | + ''' |
| 143 | + #Convert the parameters to state space form |
| 144 | + if len(args) == 4: |
| 145 | + A, B, C, D = args |
| 146 | + return ss(A, B, C, D).dcgain() |
| 147 | + elif len(args) == 3: |
| 148 | + Z, P, k = args |
| 149 | + num, den = zpk2tf(Z, P, k) |
| 150 | + return tf(num, den).dcgain() |
| 151 | + elif len(args) == 2: |
| 152 | + num, den = args |
| 153 | + return tf(num, den).dcgain() |
| 154 | + elif len(args) == 1: |
| 155 | + sys, = args |
| 156 | + return sys.dcgain() |
| 157 | + else: |
| 158 | + raise ValueError("Function ``dcgain`` needs either 1, 2, 3 or 4 " |
| 159 | + "arguments.") |
0 commit comments