From: <mur...@us...> - 2013-07-15 04:40:20
|
Revision: 289 http://sourceforge.net/p/python-control/code/289 Author: murrayrm Date: 2013-07-15 04:39:59 +0000 (Mon, 15 Jul 2013) Log Message: ----------- Updated sample_system() function to check for proper version of SciPy. If cont2discrete is not avialable (requires scipy 0.10.0+), generate a warning. Modified Paths: -------------- trunk/ChangeLog trunk/src/dtime.py Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2013-06-25 06:07:45 UTC (rev 288) +++ trunk/ChangeLog 2013-07-15 04:39:59 UTC (rev 289) @@ -1,3 +1,9 @@ +2013-07-14 Richard Murray <murray@altura-2.local> + + * src/dtime.py (sample_system): added check to make sure + cont2discrete is available in scipy.signal + (sample_system): added docstring + 2013-06-24 Richard Murray <murray@altura-2.local> * tests/minreal_test.py (TestMinreal.testMinrealBrute), Modified: trunk/src/dtime.py =================================================================== --- trunk/src/dtime.py 2013-06-25 06:07:45 UTC (rev 288) +++ trunk/src/dtime.py 2013-07-15 04:39:59 UTC (rev 289) @@ -47,7 +47,7 @@ """ -from scipy.signal import zpk2tf, tf2zpk, cont2discrete +from scipy.signal import zpk2tf, tf2zpk import numpy as np from cmath import exp from warnings import warn @@ -57,8 +57,39 @@ # Sample a continuous time system def sample_system(sysc, Ts, method='matched'): - # TODO: add docstring + """Convert a continuous time system to discrete time + Creates a discrete time system from a continuous time system by + sampling. Multiple methods of conversion are supported. + + Parameters + ---------- + sysc : linsys + Continuous time system to be converted + Ts : real + Sampling period + method : string + Method to use for conversion: 'matched' (default), 'tustin', 'zoh' + + Returns + ------- + sysd : linsys + Discrete time system, with sampling rate Ts + + Notes + ----- + 1. The conversion methods 'tustin' and 'zoh' require the + cont2discrete() function, including in SciPy 0.10.0 and above. + + 2. Additional methods 'foh' and 'impulse' are planned for future + implementation. + + Examples + -------- + >>> sysc = TransferFunction([1], [1, 2, 1]) + >>> sysd = sample_system(sysc, 1, method='matched') + """ + # Make sure we have a continuous time system if not isctime(sysc): raise ValueError("First argument must be continuous time system") @@ -77,14 +108,22 @@ sysd = _c2dmatched(sysc, Ts) elif method == 'tustin': - sys = [sysc.num[0][0], sysc.den[0][0]] - scipySysD = cont2discrete(sys, Ts, method='bilinear') - sysd = TransferFunction(scipySysD[0][0], scipySysD[1], dt) - + try: + from scipy.signal import cont2discrete + sys = [sysc.num[0][0], sysc.den[0][0]] + scipySysD = cont2discrete(sys, Ts, method='bilinear') + sysd = TransferFunction(scipySysD[0][0], scipySysD[1], dt) + except ImportError: + raise TypeError("cont2discrete not found in scipy.signal; upgrade to v0.10.0+") + elif method == 'zoh': - sys = [sysc.num[0][0], sysc.den[0][0]] - scipySysD = cont2discrete(sys, Ts, method='zoh') - sysd = TransferFunction(scipySysD[0][0],scipySysD[1], dt) + try: + from scipy.signal import cont2discrete + sys = [sysc.num[0][0], sysc.den[0][0]] + scipySysD = cont2discrete(sys, Ts, method='zoh') + sysd = TransferFunction(scipySysD[0][0],scipySysD[1], dt) + except ImportError: + raise TypeError("cont2discrete not found in scipy.signal; upgrade to v0.10.0+") elif method == 'foh' or method == 'impulse': raise ValueError("Method not developed yet") |