Skip to content

Instantly share code, notes, and snippets.

@crabmusket
Created April 8, 2013 04:40
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/5334278 to your computer and use it in GitHub Desktop.
Save crabmusket/5334278 to your computer and use it in GitHub Desktop.
Step response of a complex LTI system plotted with several parameter variations in Python.
# 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 create_tf(i):
num = [i.kw*i.kd, i.kw*i.ks]
den = [i.mc*i.mw, i.kd*(i.mc+i.mw), i.mc*(i.ks+i.kw)+i.ks*i.mw, i.kd*i.kw, i.kw*i.ks]
print den
return lti(num, den)
def plotLTI(i, n = 200):
tf = create_tf(i)
print tf
t, s = step(tf)
t, s = step(tf, T = linspace(nmin(t), t[-1], n))
p.plot(t, s * i.h)
p.xlabel('Time / s')
p.ylabel('Displacement / m')
p.show()
class Args(object):
pass
def tf_args(d):
a = Args()
a.__dict__.update(d)
return a
def d():
plotLTI(tf_args({
'h': 0.25,
'mw': 25.0,
'mc': 625.0,
'kw': 220000.0,
'kd': 8000.0,
'ks': 25000.0,
}))
def i():
plotLTI(tf_args({
'h': 0.25,
'mw': 25.0,
'mc': 625.0,
'kw': 220000.0,
'kd': 4000.0,
'ks': 25000.0,
}))
def ii():
plotLTI(tf_args({
'h': 0.25,
'mw': 25.0,
'mc': 625.0,
'kw': 220000.0,
'kd': 1000.0,
'ks': 25000.0,
}))
def iii():
plotLTI(tf_args({
'h': 0.25,
'mw': 25.0,
'mc': 625.0,
'kw': 220000.0,
'kd': 8000.0,
'ks': 12000.0,
}))
def iv():
plotLTI(tf_args({
'h': 0.25,
'mw': 25.0,
'mc': 625.0,
'kw': 220000.0,
'kd': 4000.0,
'ks': 12000.0,
}))
def v():
plotLTI(tf_args({
'h': 0.25,
'mw': 25.0,
'mc': 625.0,
'kw': 220000.0,
'kd': 1000.0,
'ks': 12000.0,
}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment