Skip to content

Discrete to continuous #888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions control/statesp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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