Exemple #1
0
 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
Exemple #2
0
 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.")
Exemple #3
0
 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
Exemple #4
0
def ss2zpk(A, B, C, D, input=0):
    """State-space representation to zero-pole-gain representation.

    Inputs:

      A, B, C, D -- state-space matrices.
      input -- for multiple-input systems, the input to use.

    Outputs:

      z, p, k -- zeros and poles in sequences and gain constant.
    """
    return tf2zpk(*ss2tf(A, B, C, D, input=input))
Exemple #5
0
def ss2zpk(A,B,C,D,input=0):
    """State-space representation to zero-pole-gain representation.

    Inputs:

      A, B, C, D -- state-space matrices.
      input -- for multiple-input systems, the input to use.

    Outputs:

      z, p, k -- zeros and poles in sequences and gain constant.
    """
    return tf2zpk(*ss2tf(A,B,C,D,input=input))
Exemple #6
0
    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.")
Exemple #7
0
    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.")
Exemple #8
0
def ss2zpk(A, B, C, D, input=0):
    """State-space representation to zero-pole-gain representation.

    Parameters
    ----------
    A, B, C, D : ndarray
        State-space representation of linear system.
    input : int, optional
        For multiple-input systems, the input to use.

    Returns
    -------
    z, p : sequence
        Zeros and poles.
    k : float
        System gain.

    """
    return tf2zpk(*ss2tf(A, B, C, D, input=input))
Exemple #9
0
def ss2zpk(A, B, C, D, input=0):
    """State-space representation to zero-pole-gain representation.

    Parameters
    ----------
    A, B, C, D : ndarray
        State-space representation of linear system.
    input : int, optional
        For multiple-input systems, the input to use.

    Returns
    -------
    z, p : sequence
        Zeros and poles.
    k : float
        System gain.

    """
    return tf2zpk(*ss2tf(A, B, C, D, input=input))
Exemple #10
0
 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