Last active
December 15, 2015 22:08
-
-
Save crabmusket/5330410 to your computer and use it in GitHub Desktop.
Step responses of LTI systems in Python for AMME3500.
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
# Step response graphs | |
# Python 2.7 with numpy, scipy, and matplotlib | |
# Based on https://gist.github.com/ofan666/1882562 | |
from numpy import min as nmin | |
from scipy import linspace | |
from scipy.signal import lti, step | |
from matplotlib import pyplot as p | |
def plotLTI(num, den, n = 200): | |
# Create an LTI transfer function from coefficients | |
tf = lti(num, den) | |
# Step response (redo it to get better resolution) | |
t, s = step(tf) | |
t, s = step(tf, T = linspace(nmin(t), min(20, t[-1]), n)) | |
# Plotting stuff | |
p.plot(t, s) | |
p.xlabel('Time / s') | |
p.ylabel('Displacement / m') | |
p.show() | |
def a(): | |
plotLTI([1, 5], [1, 10, 44, 120]) | |
def b(): | |
plotLTI([1, 5], [1, 26, 175, 150]) | |
def c(): | |
plotLTI([1, 3], [1, -2, 5]) | |
def d(): | |
plotLTI([1, 3], [1, 1, 16, 16]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment