Week 5 - GSoC 2020

This blog post describes my progress in Week 5 of Google Summer of Code 2020!

I ended up Week 4 by adding unit tests and a rough draft for Series and Parallel classes. Now in this week, to complete the implementation, we decided to add another class TransferFunctionExpr (like there is MatrixExpr class in the matrices module of sympy) which would be the super class for Series, Parallel, and TransferFunction. So, in the initial days, I added a rough implementation of that class! But soon after that, Ishan and I analysed that there’s no need to add a new class :p, because transfer function operations could be represented by just overriding add, mul, and sub operators in Series and Parallel classes. It was that simple!!

I have almost completed the implementation of both these classes by now. Basic transfer function operations like tf2 + tf3 + tf2*tf1 + tf5 now give Parallel(tf2, tf3, Series(tf2, tf1), tf5).

Something is still missing… Guess what? It is div operator! Well, we had a discussion on this topic in the PR and on the Gitter channel. The thing is that “pure division” won’t usually come up with transfer functions. The only way division comes into picture is through the use of feedback interconnections (i.e. solving an algebraic equation). So, we decided to introduce a new Feedback object so that we don’t have to actually divide TransferFunction with Parallel or Series with Parallel objects.

I’ll show you how! Consider this block diagram with a negative feedback. Solving algebraic equations for Y(s) in terms of R(s) gives:

Y(s) = H(s) * R(s)

where H(s) is (P(s)*C(s)) / (1 + P(s)*C(s)*F(s))

API for Feedback class looks like this:

>>> H = Feedback(tf1, tf2*tf3) # tf1, tf2, and tf3 are transfer functions.
>>> H.num # gives back the numerator
>>> H.den # gives the denominator. In this case, it's a *Series* object
Series(tf2, tf3)
>>> H.var # gives back the variable which is used by all the transfer functions.
>>> H.doit() # gives the resultant transfer function

I have also added the unit tests for Feedback class, will complete the implementation soon after the unit tests are finalized.

It was one of the most chaotic weeks till now, if not the most chaotic! That’s all I had for this week, folks!!