Automating the Equating of Transfer Functions with Symbolic Representations Using SymPy.jl

I am currently working on a project where I need to equate a transfer function with its symbolic representations using real components (some resistors and capacitors). Up to this point, I have been manually performing this task using SymPy, specifically employing the Eq function (e.g., exp1 = Eq(x, y)) and solving for variables (e.g., solve(exp1, C)).

I chose SymPy.jl due to some challenges I encountered with the current development state of Symbolics.jl (for reference, please see Feature Completeness Against SymPy Β· Issue #59 Β· JuliaSymbolics/Symbolics.jl Β· GitHub. However, I am finding the manual assignment of terms to be quite tedious and time-consuming.

Therefore, I am considering automating this process, but I ran into issues when trying to use the method outlined in this article Extracting All Coefficients in Sympy Using Python 3 - DNMTechs - Sharing and Storing Technology Knowledge. Unfortunately, it did not yield the expected results (see below screenshot).

Could you please advise me on what I might be doing wrong? Additionally, is there a more efficient way to achieve my goal of automating the equating of transfer functions with their symbolic representations?

Thank you for your help.

1 Like

It’s not 100% clear to me what you are trying to do when you say

are you trying to solve for the parameters, C_1, R_1,... etc., given a numeric transfer function?

There are some utilities for working with SymPy symbolic transfer functions here

1 Like

Your understanding is correct, i.e. I am trying to solve for the parameters C1, R1 given a numeric transfer function.

The below first screenshot shows the symbolic and numeric transfer functions. The symbolic transfer function being of type Sym{PyCall.PyObject}.

I then manually assign each symbolic term to its corresponding numerical term (see below), which is a bit tedious.

If you have a symbolic transfer function and have loaded SymbolicControlSystems, you should be able to call tf(symbolic_tf)

julia> symbolic_tf = w^2 / (s^2 + 2*d*w*s + w^2) # Define symbolic expression
         2       
        w        
─────────────────
           2    2
2β‹…dβ‹…sβ‹…w + s  + w 

julia> G = tf(symbolic_tf) # Convert symbolic expression to TransferFunction
TransferFunction{Continuous, SisoRational{Sym}}
         w^2
---------------------
1*s^2 + 2*d*w*s + w^2

and then obtain the coefficients using ControlSystemsBase.numpoly(G) or ControlSystemsBase.numvec(G) (and denpoly, denvec for denominator).

You can see how this is done under the hood here

1 Like