Skip to content

Instantly share code, notes, and snippets.

@crabmusket
Last active December 15, 2015 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crabmusket/5330410 to your computer and use it in GitHub Desktop.
Save crabmusket/5330410 to your computer and use it in GitHub Desktop.
Step responses of LTI systems in Python for AMME3500.
# 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