|
14 | 14 |
|
15 | 15 | from numpy import absolute, real |
16 | 16 |
|
| 17 | +__all__ = ['issiso', 'timebase', 'timebaseEqual', 'isdtime', 'isctime', |
| 18 | + 'pole', 'zero', 'evalfr', 'freqresp'] |
| 19 | + |
17 | 20 | class LTI: |
18 | 21 | """LTI is a parent class to linear time-invariant (LTI) system objects. |
19 | 22 |
|
@@ -189,3 +192,164 @@ def isctime(sys, strict=False): |
189 | 192 |
|
190 | 193 | # Got passed something we don't recognize |
191 | 194 | return False |
| 195 | + |
| 196 | +def pole(sys): |
| 197 | + """ |
| 198 | + Compute system poles. |
| 199 | +
|
| 200 | + Parameters |
| 201 | + ---------- |
| 202 | + sys: StateSpace or TransferFunction |
| 203 | + Linear system |
| 204 | +
|
| 205 | + Returns |
| 206 | + ------- |
| 207 | + poles: ndarray |
| 208 | + Array that contains the system's poles. |
| 209 | +
|
| 210 | + Raises |
| 211 | + ------ |
| 212 | + NotImplementedError |
| 213 | + when called on a TransferFunction object |
| 214 | +
|
| 215 | + See Also |
| 216 | + -------- |
| 217 | + zero |
| 218 | +
|
| 219 | + Notes |
| 220 | + ----- |
| 221 | + This function is a wrapper for StateSpace.pole and |
| 222 | + TransferFunction.pole. |
| 223 | +
|
| 224 | + """ |
| 225 | + |
| 226 | + return sys.pole() |
| 227 | + |
| 228 | + |
| 229 | +def zero(sys): |
| 230 | + """ |
| 231 | + Compute system zeros. |
| 232 | +
|
| 233 | + Parameters |
| 234 | + ---------- |
| 235 | + sys: StateSpace or TransferFunction |
| 236 | + Linear system |
| 237 | +
|
| 238 | + Returns |
| 239 | + ------- |
| 240 | + zeros: ndarray |
| 241 | + Array that contains the system's zeros. |
| 242 | +
|
| 243 | + Raises |
| 244 | + ------ |
| 245 | + NotImplementedError |
| 246 | + when called on a TransferFunction object or a MIMO StateSpace object |
| 247 | +
|
| 248 | + See Also |
| 249 | + -------- |
| 250 | + pole |
| 251 | +
|
| 252 | + Notes |
| 253 | + ----- |
| 254 | + This function is a wrapper for StateSpace.zero and |
| 255 | + TransferFunction.zero. |
| 256 | +
|
| 257 | + """ |
| 258 | + |
| 259 | + return sys.zero() |
| 260 | + |
| 261 | +def evalfr(sys, x): |
| 262 | + """ |
| 263 | + Evaluate the transfer function of an LTI system for a single complex |
| 264 | + number x. |
| 265 | +
|
| 266 | + To evaluate at a frequency, enter x = omega*j, where omega is the |
| 267 | + frequency in radians |
| 268 | +
|
| 269 | + Parameters |
| 270 | + ---------- |
| 271 | + sys: StateSpace or TransferFunction |
| 272 | + Linear system |
| 273 | + x: scalar |
| 274 | + Complex number |
| 275 | +
|
| 276 | + Returns |
| 277 | + ------- |
| 278 | + fresp: ndarray |
| 279 | +
|
| 280 | + See Also |
| 281 | + -------- |
| 282 | + freqresp |
| 283 | + bode |
| 284 | +
|
| 285 | + Notes |
| 286 | + ----- |
| 287 | + This function is a wrapper for StateSpace.evalfr and |
| 288 | + TransferFunction.evalfr. |
| 289 | +
|
| 290 | + Examples |
| 291 | + -------- |
| 292 | + >>> sys = ss("1. -2; 3. -4", "5.; 7", "6. 8", "9.") |
| 293 | + >>> evalfr(sys, 1j) |
| 294 | + array([[ 44.8-21.4j]]) |
| 295 | + >>> # This is the transfer function matrix evaluated at s = i. |
| 296 | +
|
| 297 | + .. todo:: Add example with MIMO system |
| 298 | + """ |
| 299 | + if issiso(sys): |
| 300 | + return sys.horner(x)[0][0] |
| 301 | + return sys.horner(x) |
| 302 | + |
| 303 | +def freqresp(sys, omega): |
| 304 | + """ |
| 305 | + Frequency response of an LTI system at multiple angular frequencies. |
| 306 | +
|
| 307 | + Parameters |
| 308 | + ---------- |
| 309 | + sys: StateSpace or TransferFunction |
| 310 | + Linear system |
| 311 | + omega: array_like |
| 312 | + List of frequencies |
| 313 | +
|
| 314 | + Returns |
| 315 | + ------- |
| 316 | + mag: ndarray |
| 317 | + phase: ndarray |
| 318 | + omega: list, tuple, or ndarray |
| 319 | +
|
| 320 | + See Also |
| 321 | + -------- |
| 322 | + evalfr |
| 323 | + bode |
| 324 | +
|
| 325 | + Notes |
| 326 | + ----- |
| 327 | + This function is a wrapper for StateSpace.freqresp and |
| 328 | + TransferFunction.freqresp. The output omega is a sorted version of the |
| 329 | + input omega. |
| 330 | +
|
| 331 | + Examples |
| 332 | + -------- |
| 333 | + >>> sys = ss("1. -2; 3. -4", "5.; 7", "6. 8", "9.") |
| 334 | + >>> mag, phase, omega = freqresp(sys, [0.1, 1., 10.]) |
| 335 | + >>> mag |
| 336 | + array([[[ 58.8576682 , 49.64876635, 13.40825927]]]) |
| 337 | + >>> phase |
| 338 | + array([[[-0.05408304, -0.44563154, -0.66837155]]]) |
| 339 | +
|
| 340 | + .. todo:: |
| 341 | + Add example with MIMO system |
| 342 | +
|
| 343 | + #>>> sys = rss(3, 2, 2) |
| 344 | + #>>> mag, phase, omega = freqresp(sys, [0.1, 1., 10.]) |
| 345 | + #>>> mag[0, 1, :] |
| 346 | + #array([ 55.43747231, 42.47766549, 1.97225895]) |
| 347 | + #>>> phase[1, 0, :] |
| 348 | + #array([-0.12611087, -1.14294316, 2.5764547 ]) |
| 349 | + #>>> # This is the magnitude of the frequency response from the 2nd |
| 350 | + #>>> # input to the 1st output, and the phase (in radians) of the |
| 351 | + #>>> # frequency response from the 1st input to the 2nd output, for |
| 352 | + #>>> # s = 0.1i, i, 10i. |
| 353 | + """ |
| 354 | + |
| 355 | + return sys.freqresp(omega) |
0 commit comments