@@ -164,7 +164,7 @@ def _f2s(f):
164164
165165
166166class StateSpace (LTI ):
167- r """StateSpace(A, B, C, D[, dt])
167+ """StateSpace(A, B, C, D[, dt])
168168
169169 A class for representing state-space models.
170170
@@ -1988,3 +1988,41 @@ def linfnorm(sys, tol=1e-10):
19881988 fpeak /= sys .dt
19891989
19901990 return gpeak , fpeak
1991+
1992+ def discrete2cont (sys , method = 'zoh' ):
1993+ """ Transform a discrete state-space system to a continuous state-space system.
1994+ Parameters
1995+ ------
1996+ sys : Discrete LTI (StateSpace or TransferFunction) system to transform
1997+ method: The method that was used for discretization
1998+
1999+ Returns
2000+ ------
2001+ sysc : Continuous LIT (StateSpace or TransferFunction) system depending on the input form.
2002+ """
2003+ # check if system is of type state space and convert if not
2004+ #if sys.
2005+
2006+ if not (isinstance (sys , StateSpace )):
2007+ sys = convert_to_statespace (sys )
2008+ was_tf = true
2009+ if method == 'zoh' :
2010+ Ac = scipy .linalg .logm (sys .A )/ sys .dt
2011+ Bc = np .linalg .inv (np .linalg .inv (Ac )@(sys .A - np .eye (np .shape (sys .A )[0 ])))@sys .B
2012+
2013+ # remove small numbers
2014+ Ac = np .around (Ac / 1e-6 )* 1e-6
2015+ Bc = np .around (Bc / 1e-6 )* 1e-6
2016+
2017+ # turn -0 to 0
2018+ Ac [np .abs (Ac )< 1e-6 ] = 0
2019+ Bc [np .abs (Bc )< 1e-6 ] = 0
2020+
2021+ sysc = StateSpace (Ac ,Bc ,sys .C ,sys .D ,0 )
2022+ else :
2023+ raise NotImplementedError ("Method: " + method + " is not implemented in this function!" )
2024+
2025+ if was_tf :
2026+ sysc = ss2tf (sysc )
2027+
2028+ return sysc
0 commit comments