System Functionals in Python
1) System Functionals in Python
System Functionals are rational polynomials in {\cal R} (the right-shift
operator). As such, when thinking about implementing system functionals, it
will be useful to have a nice representation for polynomials in Python. In
previous exercises, we have used lists of coefficients to represent
polynomials. However, from here moving forward, we will use a class called
Polynomial instead (so that it is always clear what that we are dealing with
polynomials, rather than arbitrary lists).
Polynomial instances will be initialized with a single argument (a list of
coefficients in the form we have seen in the past). They will provide mostly
the same operations you implemented in last week's Polynomial exercise, but
through a slightly different interface (see the documentation for more information)
We will represent system functionals as ratios of polynomials that are
described as instances of this Polynomial class. Thus, we will represent the
polynomial
3\mathcal{R}^2+4\mathcal{R}+17 as
poly1 = Polynomial([17, 4, 3])and the polynomial z^4+4z as
poly2 = Polynomial([0, 4, 0, 0, 1])
Create an instance of Polynomial called poly3
to represent the denominator of the system functional
{3\mathcal{R}+2\over 6\mathcal{R}^2+5\mathcal{R}+1}.
Create an
instance called poly4 to represent the denominator of the
corresponding system function {3z+2z^2\over 6+5z+z^2}.
poly4 =?
2) Implementation
System Functionals are a very useful representation for systems, and so we will use this exercise to build on the System class from an earlier exercise, expanding it to include a representation for system functionals, as well as some methods for manipulating systems in system functional form.
Because we will be dealing with polynomial math, you should import our implementation of the Polynomial class into your lti.py file by adding the following at the beginning of the file:
from lib601.poly import Polynomial
2.1) Including System Functional
We will start by making sure each instance of a System subclass includes within it a representation for that system's system functional. We will do this by adding two attributes to each subclass of System:
numeratorshould contain the numerator of the system functional (as a Polynomial in {\cal R}), represented as an instance of thePolynomialclass from last week's exercises.denominatorshould contain the denominator of the system functional, in the same form.
Modify the __init__ method for each of the system subclasses (R, Gain, FeedforwardAdd, Cascade, FeedbackAdd) so that it stores these two attributes, in addition to any other attributes it was storing before.
2.2) Additional Operations
Since we can now rely on instances of all subclasses having numerator and denominator attributes representing the system functional, we can implement a few helpful methods that rely on this information. Augment the base System class by adding the following methods:
poles(self):returns a list of the poles of the system.dominant_pole(self):returns one of the poles with greatest magnitude. If two or more poles have the same greatest magnitude, then any of these poles may be returned. If the system has no poles, the method should returnNone.
Note that if you are looking for ways to test your code, you should use it to find the poles (and dominant pole) of some systems of your own construction, or of the systems from the other exercises in this problem set (which you can solve by hand so you'll know what to expect!).
Submit your code for all of these changes by uploading your updated lti.py file below:
3) Mystery System
Use your Python framework to determine the poles of the following system.Enter the poles you found for the mystery system, as a Python list of (possibly complex) numbers: