## Modelica_LinearSystems2

Modelica_LinearSystems2 (2.2 Beta 1) - Analysis, Synthesis and Modeling of Continuous and Discrete Linear Systems

### Information

Library Modelica_LinearSystems2 is a Modelica package providing different representations of linear, time invariant differential and difference equation systems. For example, record StateSpace defines a linear time invariant differential equation system in state space form:

        der(x) = A * x + B * u
            y  = C * x + D * u

Operators are overloaded to work conveniently with these system descriptions in an interactive environment, e.g., to multiply transfer functions or to operate on complex numbers. About 180 functions are provided to operate on these data structures, e.g., to compute eigen values, zeros, step responses, to design pole-placement and LQG controllers, to plot step responses, frequency responses, eigen values, to convert between different description forms, or to generate a linear system description by linearization of a Modelica model.

Furthermore, in sublibrary Controller about 20 input/output blocks of linear systems are provided that are based on the different representation forms, e.g., PID, StateSpace, Filter blocks. A unique feature of these blocks is that it is very convenient to quickly switch between a continuous and a discrete block representation. Also, templates are provide to quickly built-up standard controller structures.

For an introduction, have especially a look at:

- Getting started provides an overview of the Library inside the Users Guide.
- Release Notes summarizes the changes of new versions of this package.
- Contact gives the contact information for this library.
- In an interactive environment, it is useful to run first the script "_abbreviations.mos" in directory "Modelica_LinearSystems2\Extras\Scripts" in order to set useful abbreviations: ss, tf, zp, poly, Complex, Plot, s, p, j.

It is planned to include this library in a future version of the Modelica Standard Library. Note, the library is not backwards compatible to the previous beta version 0.95, called "Modelica_LinearSystems", which was shipped with previous versions of Dymola. Since the differences are too large, no conversion scripts are provided, but different library names are used.

Licensed by DLR under the Modelica License 2
Copyright © 2005-2010, DLR Institute of Robotics and Mechatronics

This Modelica package is free software and the use is completely at your own risk; it can be redistributed and/or modified under the terms of the Modelica license 2, see the license conditions (including the disclaimer of warranty) here or at http://www.Modelica.org/licenses/ModelicaLicense2.

### Package Content

Name | Description
--- | ---
UsersGuide | Users Guide
DataDir=classDirectory() + "Extras/Data/" | Absolute path to directory containing utilitiy files for this package
Examples | Examples demonstrating the usage of this package
StateSpace | Continuous state space description of a linear, time invariant differential equation system (data + operations)
ZerosAndPoles | Continuous zeros and poles description of a single input, single output system (data + operations)
TransferFunction | Continuous transfer function description of a single input, single output system (data + operations)
DiscreteStateSpace | Discrete state space description of a linear, time invariant difference equation system (data + operations)
DiscreteZerosAndPoles | Discrete zeros and poles description of a single input, single output system (data + operations)
DiscreteTransferFunction | Discrete transfer function description of a single input, single output system (data + operations)
Controller | Continuous and discrete input/output blocks. Easy to switch from continuous to discrete representation.
Math | Additional functions for Modelica.Math
Utilities | Functions that shall be included in Modelica.Utilities
Types | Constants and types with choices, especially to build menus
WorkInProgress | Package for developments and internal models

## Modelica_LinearSystems2.StateSpace

Continuous state space description of a linear, time invariant differential equation system (data + operations)

### Information

This record defines a linear time invariant differential equation system in state space form:

        der(x) = A * x + B * u
            y  = C * x + D * u

with

- u - the input vector
- y - the output vector
- x - the state vector
- A,B,C,D - matrices of appropriate dimensions

Extends from Modelica.Icons.Record (Icon for records).

### Parameters

Name | Description
--- | ---
der(x) = A*x + B*u; y = C*x + D*u
A[:, size(A, 1)] |
B[size(A, 1), :] |
C[:, size(A, 1)] |
D[size(C, 1), size(B, 2)] |
Signal names
yNames[size(C, 1)] | Names of the output signals
xNames[size(A, 1)] | Names of the states
uNames[size(B, 2)] | Names of the input signals

## Modelica_LinearSystems2.ZerosAndPoles

Continuous zeros and poles description of a single input, single output system (data + operations)

### Information

This record defines a transfer function by its zeros, poles and a gain:

             product(p - z[i])
      y = k*------------------- * u
             product(p - n[i])

where z[:] is a Complex vector of zeros, n[:] is a Complex vector of poles and k is an additional multiplicative factor. The elements of the two Complex vectors must either be real numbers or conjugate complex pairs (in order that their product results in a polynomial with Real coefficients).

In the record, the zeros and poles are transformed into a product of first and second order polynomials. The data structure is especially useful in applications where first and second order polynomials are naturally occuring, e.g., as for filters. In fact, via function ZerosAndPoles.Design.filter, a ZeroAndPole transfer function is generated from low and high pass analog filters (CriticalDamping, Bessel, Butterworth, Chebyshev). The filters are available in normalized (default) and non-normalized form. In the normalized form, the amplitude of the filter transfer function at the cutoff frequency is 3 dB.

A ZeroAndPole transfer function is internally stored by the coefficients of first and second order polynomials, and by an additional multiplicative factor k:

             product(p + n1[i]) * product(p^2 + n2[i,1]*p + n2[i,2])
      y = k*---------------------------------------------------------
             product(p + d1[i]) * product(p^2 + d2[i,1]*p + d2[i,2])

Note, the degrees of the numerator and denominator polynomials are given as:

       degree of numerator   = size(n1,1) + 2*size(n2,1);
       degree of denominator = size(d1,1) + 2*size(d2,1);

Example:

                              (p+1)
      zp = 4* -------------------------------------
               (p - 1)*(p - (2+j*3))*(p - (2-j*3))

with j=sqrt(-1), is defined as

       import Modelica_LinearSystems2.Math.Complex;
       import Modelica_LinearSystems2.ZerosAndPoles;

       zp = ZerosAndPoles(z = {Complex(-1,0)},
                          p = {Complex(1,0),
                               Complex(2,3),
                               Complex(2,-3)},
                               k=4);

Extends from Modelica.Icons.Record (Icon for records).

### Parameters

Name | Description
--- | ---
y = k*(product(p+n1[i]) * product(p^2+n2[i,1]*p+n2[i,2])) / (product(p+d1[i])*product(p^2+d2[i,1]*p+d2[i,2])) *u
k | Multiplicative factor of transfer function
n1[:] | [p^0] coefficients of 1st order numerator polynomials
n2[:, 2] | [p,p^0] coefficients of 2nd order numerator polynomials
d1[:] | [p^0] coefficients of 1st order denominator polynomials
d2[:, 2] | [p,p^0] coefficients of 2nd order denominator polynomials
Signal names
uName | Name of input signal
yName | Name of output signal

## Modelica_LinearSystems2.TransferFunction

Continuous transfer function description of a single input, single output system (data + operations)

### Information

This record defines the transfer function between the input signal u and the output signal y by the coefficients of the numerator and denominator polynomials n(s) and d(s) respectively:

            n(s)
       y = ------ * u
            d(s)

The order of the numerator polynomial can be larger as the order of the denominator polynomial (in such a case, the transfer function can not be transformed to a StateSpace system, but other operations are possible).

Example: The transfer function

                 2*s+3
       y = ----------------- * u
            4*s^2 + 5*s + 6

is transformed in the following way in a TransferFunction record:

       import Modelica_LinearSystems2.TransferFunction;
       import Modelica.Utilities.Streams;
       TransferFunction tf(n={2,3}, d={4,5,6});
       print("y = " + TransferFunction.'String'(tf) + " * u");
       // prints the following string to the output window:
       //   y = (2*s + 3) / (4*s^2 + 5*s + 6) * u

Extends from Modelica.Icons.Record (Icon for records).

### Parameters

Name | Description
--- | ---
y = n*{s^m, ... , s, 1} / (d*{s^r, ... , s, 1}) * u
n[:] | Coefficients of numerator polynomial (in descending order)
d[:] | Coefficients of denominator polynomial (in descending order)
Signal names
uName | Name of input signal
yName | Name of output signal

## Modelica_LinearSystems2.DiscreteStateSpace

Discrete state space description of a linear, time invariant difference equation system (data + operations)

### Information

This record defines a linear time invariant difference equation system in state space form:

         x(Ts*(k+1)) = A * x(Ts*k) + B * u(Ts*k)
         y(Ts*k)     = C * x(Ts*k) + D * u(Ts*k)
         x_continuous(Ts*k) = x(Ts*k) + B2 * u(Ts*k)

with

- Ts - the sample time
- k - the index of the actual sample instance (k=0,1,2,3,...)
- t - the time
- u(t) - the input vector,
- y(t) - the output vector,
- x(t) - the discrete state vector (x(t=Ts*0) is the initial state),
- x_continuous(t) - the state vector of the continuous system from which the discrete block has been derived (details see below),
- A,B,C,D,B2 - matrices of appropriate dimensions.

A discrete system is usually derived by discretization from a continuous block, e.g., by function LinearSystems.DiscreteStateSpace.fromStateSpace. If the discretization method, e.g., the trapezoidal method, accesses actual and past values of the input u (e.g. u(Ts*k), u(Ts*(k-1), u(Ts*(k-2))), a state transformation is needed to get the difference equation above where only the actual value u(Ts*k) is accessed.

If the original continuous state vector should be computed from the sampled data system above, the matrices of this transformation have to be known. For simplicity and efficiency, here only the specific transformation used by function LinearSystems.DiscreteStateSpace.fromStateSpace is stored in the data record of the discrete system via matrix B2. Therefore, the state vector of the underlying continuous system can be calculated by adding the term B2*u to the state vector of the discretized system.

In Modelica notation, the difference equation above can be implemented as:

         when {initial(), sample(Ts,Ts)} then
            new_x = A * x + B * u;
                y = C * x + D * u;
                x = pre(new_x);
            x_continuous = x + B2 * u;
         end when;

Since no "next value" operator is available in Modelica, an auxiliary variable new_x stores the value of x for the next sampling instant. The relationship between new_x and x is defined via equation "x = pre(new_x)".

The body of the when-clause is active during initialization and at the next sample instant t=Ts. Note, the when-equation is not active after the initialization at t=0 (due to sample(Ts,Ts)), since the state x of the initialization has to be used also at t=0.

In library Blocks.Controller additional equations are added for the initialization to uniquely compute the initial vector x:

      initial equation
         if init == InitialState then
            x = x_start;
         elseif init == SteadyState then
            x = new_x;
         end if;

Optionally, x is set to a given start vector x_start. As default initialization, the equation "x = new_x" is added that defines steady state initialization for the discrete system. As a consequence, the output y(Ts*k), k=0,1,2,.., remains constant after this initialization, provided the input vector u(Ts*k) remains constant.

Extends from Modelica.Icons.Record (Icon for records).

### Parameters

Name | Description
--- | ---
new_x = A*x + B*u; y = C*x + D*u; x_cont = x + B2*u
A[:, size(A, 1)] |
B[size(A, 1), :] |
C[:, size(A, 1)] |
D[size(C, 1), size(B, 2)] |
Data used to construct discrete from continuous system
Ts | Sample time [s]
B2[size(B, 1), size(B, 2)] | Reconstruct continuous state
method | Discretization method

## Modelica_LinearSystems2.DiscreteZerosAndPoles

Discrete zeros and poles description of a single input, single output system (data + operations)

### Information

This record defines a discrete transfer function by its zeros, poles and a gain:

             product(q - z[i])
      y = k*------------------- * u
             product(q - n[i])

where z[:] is a Complex vector of zeros, n[:] is a Complex vector of poles and k is an additional multiplicative factor. The elements of the two Complex vectors must either be real numbers or conjugate complex pairs (in order that their product results in a polynomial with Real coefficients).

In the record, the zeros and poles are transformed into a product of first and second order polynomials.

A DiscreteZeroAndPole transfer function is internally stored by the coefficients of first and second order polynomials, and by an additional multiplicative factor k:

             product(q + n1[i]) * product(q^2 + n2[i,1]*q + n2[i,2])
      y = k*---------------------------------------------------------
             product(q + d1[i]) * product(q^2 + d2[i,1]*q + d2[i,2])

Note, the degrees of the numerator and denominator polynomials are given as:

       degree of numerator   = size(n1,1) + 2*size(n2,1);
       degree of denominator = size(d1,1) + 2*size(d2,1);

Example:

                              (q+0.5)
      dzp = 4* -------------------------------------
               (p - 0.5)*(p - (0.6+j*0.3))*(p - (0.6-j*0.3))

with j = Complex.j(); is defined as

       import Modelica_LinearSystems2.Math.Complex;
       import Modelica_LinearSystems2.DiscreteZerosAndPoles;
       j = Complex.j();

       dzp = ZerosAndPoles(z = {Complex(-0.5)},
                           p = {Complex(0.5),
                                0.6+j*0.3,
                                0.6-j*0.3},
                                k=4);

Extends from Modelica.Icons.Record (Icon for records).

### Parameters

Name | Description
--- | ---
y = k*(product(p+n1[i]) * product(p^2+n2[i,1]*p+n2[i,2])) / (product(p+d1[i])*product(p^2+d2[i,1]*p+d2[i,2])) *u
k | Multiplicative factor of transfer function
n1[:] | [p^0] coefficients of 1st order numerator polynomials
n2[:, 2] | [p,p^0] coefficients of 2nd order numerator polynomials
d1[:] | [p^0] coefficients of 1st order denominator polynomials
d2[:, 2] | [p,p^0] coefficients of 2nd order denominator polynomials
Data used to construct discrete from continuous system
Ts | Sample time [s]
method | Discretization method
Signal names
uName | Name of input signal
yName | Name of output signal

## Modelica_LinearSystems2.DiscreteTransferFunction

Discrete transfer function description of a single input, single output system (data + operations)

### Information

Extends from Modelica.Icons.Record (Icon for records).

### Parameters

Name | Description
--- | ---
y = n*{z^m, ... , z, 1} / (d*{z^r, ... , z, 1}) * u
n[:] | Coefficients of numerator polynomial (in descending order)
d[:] | Coefficients of denominator polynomial (in descending order)
Data used to construct discrete from continuous system
Ts | Sample time [s]
method | Discretization method
Signal names
uName | Name of input signal
yName | Name of output signal