def __setattr__(self, attr, val): if attr in ['num', 'den']: self.__dict__[attr] = val self.__dict__['zeros'], self.__dict__['poles'], \ self.__dict__['gain'] = \ tf2zpk(self.num, self.den) self.__dict__['A'], self.__dict__['B'], \ self.__dict__['C'], \ self.__dict__['D'] = \ tf2ss(self.num, self.den) elif attr in ['zeros', 'poles', 'gain']: self.__dict__[attr] = val self.__dict__['num'], self.__dict__['den'] = \ zpk2tf(self.zeros, self.poles, self.gain) self.__dict__['A'], self.__dict__['B'], \ self.__dict__['C'], \ self.__dict__['D'] = \ zpk2ss(self.zeros, self.poles, self.gain) elif attr in ['A', 'B', 'C', 'D']: self.__dict__[attr] = val self.__dict__['zeros'], self.__dict__['poles'], \ self.__dict__['gain'] = \ ss2zpk(self.A, self.B, self.C, self.D) self.__dict__['num'], self.__dict__['den'] = \ ss2tf(self.A, self.B, self.C, self.D) else: self.__dict__[attr] = val
def __init__(self, *args, **kwords): """Initialize the LTI system using either: (numerator, denominator) (zeros, poles, gain) (A, B, C, D) -- state-space. """ N = len(args) if N == 2: # Numerator denominator transfer function input self.__dict__["num"], self.__dict__["den"] = normalize(*args) self.__dict__["zeros"], self.__dict__["poles"], self.__dict__["gain"] = tf2zpk(*args) self.__dict__["A"], self.__dict__["B"], self.__dict__["C"], self.__dict__["D"] = tf2ss(*args) self.inputs = 1 if len(self.num.shape) > 1: self.outputs = self.num.shape[0] else: self.outputs = 1 elif N == 3: # Zero-pole-gain form self.__dict__["zeros"], self.__dict__["poles"], self.__dict__["gain"] = args self.__dict__["num"], self.__dict__["den"] = zpk2tf(*args) self.__dict__["A"], self.__dict__["B"], self.__dict__["C"], self.__dict__["D"] = zpk2ss(*args) self.inputs = 1 if len(self.zeros.shape) > 1: self.outputs = self.zeros.shape[0] else: self.outputs = 1 elif N == 4: # State-space form self.__dict__["A"], self.__dict__["B"], self.__dict__["C"], self.__dict__["D"] = abcd_normalize(*args) self.__dict__["zeros"], self.__dict__["poles"], self.__dict__["gain"] = ss2zpk(*args) self.__dict__["num"], self.__dict__["den"] = ss2tf(*args) self.inputs = self.B.shape[-1] self.outputs = self.C.shape[0] else: raise ValueError("Needs 2, 3, or 4 arguments.")
def zpk2ss(z,p,k): """Zero-pole-gain representation to state-space representation Inputs: z, p, k -- zeros, poles (sequences), and gain of system Outputs: A, B, C, D -- state-space matrices. """ return tf2ss(*zpk2tf(z,p,k))
def __init__(self, *args, **kwords): """ Initialize the LTI system using either: - (numerator, denominator) - (zeros, poles, gain) - (A, B, C, D) : state-space. """ N = len(args) if N == 2: # Numerator denominator transfer function input self.__dict__['num'], self.__dict__['den'] = normalize(*args) self.__dict__['zeros'], self.__dict__['poles'], \ self.__dict__['gain'] = tf2zpk(*args) self.__dict__['A'], self.__dict__['B'], \ self.__dict__['C'], \ self.__dict__['D'] = tf2ss(*args) self.inputs = 1 if len(self.num.shape) > 1: self.outputs = self.num.shape[0] else: self.outputs = 1 elif N == 3: # Zero-pole-gain form self.__dict__['zeros'], self.__dict__['poles'], \ self.__dict__['gain'] = args self.__dict__['num'], self.__dict__['den'] = zpk2tf(*args) self.__dict__['A'], self.__dict__['B'], \ self.__dict__['C'], \ self.__dict__['D'] = zpk2ss(*args) # make sure we have numpy arrays self.zeros = numpy.asarray(self.zeros) self.poles = numpy.asarray(self.poles) self.inputs = 1 if len(self.zeros.shape) > 1: self.outputs = self.zeros.shape[0] else: self.outputs = 1 elif N == 4: # State-space form self.__dict__['A'], self.__dict__['B'], \ self.__dict__['C'], \ self.__dict__['D'] = abcd_normalize(*args) self.__dict__['zeros'], self.__dict__['poles'], \ self.__dict__['gain'] = ss2zpk(*args) self.__dict__['num'], self.__dict__['den'] = ss2tf(*args) self.inputs = self.B.shape[-1] self.outputs = self.C.shape[0] else: raise ValueError("Needs 2, 3, or 4 arguments.")
def zpk2ss(z, p, k): """Zero-pole-gain representation to state-space representation Parameters ---------- z, p : sequence Zeros and poles. k : float System gain. Returns ------- A, B, C, D : ndarray State-space matrices. """ return tf2ss(*zpk2tf(z, p, k))
def __setattr__(self, attr, val): if attr in ["num", "den"]: self.__dict__[attr] = val self.__dict__["zeros"], self.__dict__["poles"], self.__dict__["gain"] = tf2zpk(self.num, self.den) self.__dict__["A"], self.__dict__["B"], self.__dict__["C"], self.__dict__["D"] = tf2ss(self.num, self.den) elif attr in ["zeros", "poles", "gain"]: self.__dict__[attr] = val self.__dict__["num"], self.__dict__["den"] = zpk2tf(self.zeros, self.poles, self.gain) self.__dict__["A"], self.__dict__["B"], self.__dict__["C"], self.__dict__["D"] = zpk2ss( self.zeros, self.poles, self.gain ) elif attr in ["A", "B", "C", "D"]: self.__dict__[attr] = val self.__dict__["zeros"], self.__dict__["poles"], self.__dict__["gain"] = ss2zpk( self.A, self.B, self.C, self.D ) self.__dict__["num"], self.__dict__["den"] = ss2tf(self.A, self.B, self.C, self.D) else: self.__dict__[attr] = val