0
$\begingroup$

I'm doing some control system work. I was shocked* -- shocked to learn that while Scipy has some nice linear systems classes, they don't extend to computing the cascades or paralleling of two systems.

I.e., in Scilab if you have system H and system G, you can express their parallel as HpG = H + G, or their cascade as HcG = H * G -- in other words, just do the intuitive thing as if you were manipulating transfer functions.

Is there a commonly-used Python package that offers this convenience?

* After years of using Python for signal processing -- it's been a while since I've done serious control systems work.

$\endgroup$
1
  • 1
    $\begingroup$ Yes, this arguably belongs in stackoverflow. I felt my hit rate with people who use Python and could answer the question "what is a transfer function" would be much higher here. $\endgroup$
    – TimWescott
    Feb 10 at 18:44

1 Answer 1

3
$\begingroup$

The Control System Library in Python handles all this quite well, and maps closely to the MATLAB Control Toolbox in functionality.

https://python-control.readthedocs.io/en/0.9.3.post2/

Demo:

import control as con
H = con.tf([1, 0], [1, -1, 1])
G = con.tf([1, 1], [1, -1])

print(H)
print(G)

     s
-----------
s^2 - s + 1


s + 1
-----
s - 1

print(H+G)

  s^3 + s^2 - s + 1
---------------------
s^3 - 2 s^2 + 2 s - 1


print(H*G)

       s^2 + s
---------------------
s^3 - 2 s^2 + 2 s - 1

Hint: be sure to use the control.minreal() function liberally when combining transfer functions (eliminates matching pole/zero pairs that wouldn't necessarily be automatically factored out). I typically wrap any operation that involves manipulating transfer functions with control.minreal() to keep orders as small as possible before then being combined / expanded with other higher levels, unless I am sure there are no common factors (such as in the example given above).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.