Created
April 27, 2021 21:52
-
-
Save brilliant-ember/df96b551873a2b8a605099f8285369f5 to your computer and use it in GitHub Desktop.
How to do inverse Z transform with python, this function will break up the partial fraction assuming Z transform. Note that it doesn't handle complex roots, if you have complex roots use the scipy residuez function to find the poles and coefficients.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Solving Z domain partial fraction with sympy | |
from sympy import * | |
z = symbols('z') | |
def inverse_z(h): | |
'''finds X(z)/z for the inverse z transform table look up | |
''' | |
h = h/z | |
h = h.apart() * z | |
return expand(h) | |
n = z**2 + z + (z/(z-1)) | |
d = z**2 - 3*z/2 + 1/2 | |
a = n/d | |
a = inverse_z(a) | |
print(a) | |
#a | |
# a.cancel().apart() | |
''' | |
Note, whenever you try to do partial fractions for z inv, you must first divide the system by z | |
and then multiply the partial fraction result by z. So you perform partials on X(z)/z = LHS/z, and answer after partial will be multiplied by z so that your final answer is X(z) | |
''' |
Author
brilliant-ember
commented
Apr 27, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment