2012-09-17 8 views
7

Funkcja transferu systemu LTI z opóźnieniem czasowym ma termin licznika exp (-Td * s), gdzie Td jest opóźnieniem czasowym. W Matlab można stworzyć taki system LTI na wiele sposobów (np. Używając operatora "s" i ustawiając wykładniczy termin bezpośrednio lub ustawiając obiekty inputdelayoutputdelay obiektów tf.) Jednak nie mogę znaleźć żadnego sposobu na zrobienie tego w Obiekty LTI Scipy Signal. Sprawdziłem również bibliotekę Python Control Systems, ale wciąż nie mogłem znaleźć sposobu.Jak zdefiniować systemy LTI z opóźnieniem w Scipy?

Nie chcę używać przybliżenia Pade'a dla opóźnienia czasowego i chcę ustawić dokładne opóźnienie czasowe dla systemu LTI.

Czy ktoś wie, jak to osiągnąć w Scipy lub w jakiejkolwiek innej zewnętrznej bibliotece Pythona?

Odpowiedz

4

Sprawdziłem moduł ltisys na github i próbowałem stworzyć klasę LTI z opóźnieniem. Myślę, że powinno być proste wprowadzenie opóźnienia wejściowego w równaniu stanu, jeśli zastąpimy BU (t) przez BU (t-Td), gdzie Td jest opóźnieniem czasowym. Następujące podejście działa dla pojedynczego wejścia systemu pojedynczego wyjścia. Nie może być wolny od błędów, ale rozwiązał mój cel.

#Inherit the parent LTI class to create LTI class with time delay 


class ltidelay(lti): 
    def __init__(self,inputdelay,*args,**kwargs): 
     super(ltidelay,self).__init__(*args,**kwargs)  
     self.d =inputdelay 

#define a method to simulate LTI with time delay . just copied lsim2 and made 2 changes. 1. passed the delay from the `ltidelay` object and 2. modified the state equation. 


def lsim3(system , U=None, T=None,X0=None, **kwargs): 
    if isinstance(system,lti): 
     sys = system 
    else: 
     sys = lti(*system) 
    delay = sys.d 
    if X0 is None: 
     X0 = zeros(sys.B.shape[0],sys.A.dtype)   
    if T is None: 
     T = linspace(0,10,101) 
    T = atleast_1d(T) 
    if len(T.shape) != 1: 
     raise ValueError("T must be a rank1 array") 
    if U is not None: 
     U = atleast_1d(U) 
     if len(U.shape)==1: 
      U=U.reshape(-1,1) 
     sU = U.shape 
     if sU[0] != len(T): 
      raise ValueError("U must have the same number of rows as elements in T") 
     if sU[1] != sys.inputs: 
      raise ValueError("The number of inputs in U is not compatible") 
     ufunc = interpolate.interp1d(T, U, kind ='linear',axis =0,bounds_error =False) 
     def fprime(x,t,sys,ufunc): 
      return dot(sys.A,x)+squeeze(dot(sys.B,nan_to_num(ufunc([t-delay])))) 
     xout = odeint(fprime,X0,T,args=(sys,ufunc),**kwargs) 
     yout = dot(sys.C,transpose(xout)) 
    else: 
     def fprime(x,t,sys): 
      return dot(sys.A,x) 
     xout = odeint(fprime,X0,T,args=(sys,),**kwargs) 
     yout = dot(sys.C, transpose(xout)) 
    return T , squeeze(transpose(yout)),xout 

#create an LTI system with delay 10 

tf = ltidelay(10,2,[4,1]) 

#create a step signal and time vector to simulate the LTI and check 


u = linspace(0,0,100) 

u[50:100] = 1 

t = linspace(1,100,100) 

#check the simulation 
y = lsim3(tf,u,t,X0 =0) 

plot(y[1]) 

enter image description here

# compare with LTI without time delay 
y1 =lsim2(tf, u,t, X0=0) 

plot(y1[1]) 

enter image description here

#delay works