Daniele
Daniele

Reputation: 480

How to create a scipy.lti object for a discrete LTI system?

As in subject, I'm using python/numpy/scipy to do some data analysis, and I'd like to create an object of class LTI for a discrete system, specifying (num, den, dt) or (zeros, poles, gain, dt), or even (A, B, C, D, dt), but the documentation never mentions how to do that.

There are nevertheless functions like dsim/dstep/dimpulse that will take a LTI object and do things with it, so I guess it's possible. Once I have it, I'd like to do things like convert from one representation to another (num/den -> zpk -> A,B,C,D), plot the Bode diagram, etc.

Also, it's completely not clear to me if a (num, den, dt) representation would use coefficient for z or z^-1, as I don't think there is a clear standard.

Upvotes: 4

Views: 2457

Answers (2)

Juan Osorio
Juan Osorio

Reputation: 380

I think there is a bit of inconsistency here in scipy. On one hand you can define a lti system using something like:

>> sys = sig.lti([1],[1,1])

The type of this system is:

>> type(sys)
scipy.signal.ltisys.lti

Many of the procedures for analog system that are under scipy.signal.ltisys work well for these type of systems but is not the case for the ones you find in flat scipy. There you can also define a system differently by using:

sys_ss = scipy.signal.tf2ss([1],[1,2])
sysd_ss = scipy.signal.cont2discrete(sys_ss,1.0/10)
t,y = scipy.signal.dstep(sysd_ss)

and to plot it you can do something like:

plt.plot(t,y[0])

The object created by signal.tf2ss is just a tuple with the state-space matrix. Either I don't understand it well (I happen to have not so much experience in python) or it is quite messy.

Upvotes: 0

silvado
silvado

Reputation: 18187

It seems the scipy.signal.lti class is only meant for continuous time systems. Checking the documentation of for example scipy.signal.dstep, one gets:

system : a tuple describing the system.
    The following gives the number of elements in the tuple and
    the interpretation.
      * 3: (num, den, dt)
      * 4: (zeros, poles, gain, dt)
      * 5: (A, B, C, D, dt)

So the argument system cannot by an object of class lti. While the documentation of scipy.signal.dlsim does state that it accepts LTI instances, I think this is wrong. At least with scipy 0.10.0, I get:

TypeError: object of type 'lti' has no len()

So apparently also dlsim expects the system argument to be a tuple.

Upvotes: 2

Related Questions