From 578b17713974c594c8092863e2c02c7899384e46 Mon Sep 17 00:00:00 2001 From: Stefan Kletzenbauer Date: Thu, 27 Apr 2023 18:08:12 +0200 Subject: [PATCH 1/2] added discrete2cont()-funciton to convert discrete LTI-systems back to continuous systems --- control/statesp.py | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/control/statesp.py b/control/statesp.py index 41f92ae21..9966469ae 100644 --- a/control/statesp.py +++ b/control/statesp.py @@ -164,7 +164,7 @@ def _f2s(f): class StateSpace(LTI): - r"""StateSpace(A, B, C, D[, dt]) + """StateSpace(A, B, C, D[, dt]) A class for representing state-space models. @@ -1988,3 +1988,41 @@ def linfnorm(sys, tol=1e-10): fpeak /= sys.dt return gpeak, fpeak + +def discrete2cont(sys, method='zoh'): + """ Transform a discrete state-space system to a continuous state-space system. + Parameters + ------ + sys : Discrete LTI (StateSpace or TransferFunction) system to transform + method: The method that was used for discretization + + Returns + ------ + sysc : Continuous LIT (StateSpace or TransferFunction) system depending on the input form. + """ + # check if system is of type state space and convert if not + #if sys. + + if not(isinstance(sys, StateSpace)): + sys = convert_to_statespace(sys) + was_tf = true + if method == 'zoh': + Ac = scipy.linalg.logm(sys.A)/sys.dt + Bc = np.linalg.inv(np.linalg.inv(Ac)@(sys.A-np.eye(np.shape(sys.A)[0])))@sys.B + + # remove small numbers + Ac = np.around(Ac/1e-6)*1e-6 + Bc = np.around(Bc/1e-6)*1e-6 + + # turn -0 to 0 + Ac[np.abs(Ac)<1e-6] = 0 + Bc[np.abs(Bc)<1e-6] = 0 + + sysc = StateSpace(Ac,Bc,sys.C,sys.D,0) + else: + raise NotImplementedError("Method: " + method + " is not implemented in this function!") + + if was_tf: + sysc = ss2tf(sysc) + + return sysc From ee22b8ab772b74c4506c516fb07a215001e2826a Mon Sep 17 00:00:00 2001 From: Stefan Kletzenbauer Date: Thu, 27 Apr 2023 18:36:01 +0200 Subject: [PATCH 2/2] Added function discrete2cont() to convert discrete LTI systems to continuous --- control/statesp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/control/statesp.py b/control/statesp.py index 9966469ae..ca6f99d86 100644 --- a/control/statesp.py +++ b/control/statesp.py @@ -164,7 +164,7 @@ def _f2s(f): class StateSpace(LTI): - """StateSpace(A, B, C, D[, dt]) + r"""StateSpace(A, B, C, D[, dt]) A class for representing state-space models. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy