## Modelica_LinearSystems2.Examples.ZerosAndPoles

### Package Content

Name | Description
--- | ---
analysisZerosAndPoles | Compute zeros and poles of a ZerosAndPoles transfer function
conversionToStateSpace | Transform a transfer function from zeros and poles representation into a StateSpace description
plotPolesAndZeros | Example for plotting poles and zeros of a ZerosAndPoles transfer function
plotBode1 | Construct a ZerosAndPoles system and plot the Bode diagram with automatic determination of the frequency range to plot
plotBode2 | Bode plot of PT2 transfer function with zero damping
plotBode3 | Construct a ZerosAndPoles system and plot the Bode diagram with automatic determination of the frequency range to plot
plotBodeFilter1 | Compute filter and plot frequency response of filter
plotBodeFilter2 | Show low pass filters of all filter types
plotBodeFilter3 | Show high pass filters of all filter types
plotStep | Step plot example

## Modelica_LinearSystems2.Examples.ZerosAndPoles.analysisZerosAndPoles

Compute zeros and poles of a ZerosAndPoles transfer function

### Outputs

Type | Name | Description
--- | --- | ---
Boolean | ok |

### Modelica definition

    encapsulated function analysisZerosAndPoles
      "Compute zeros and poles of a ZerosAndPoles transfer function"
      import Modelica;
      import Modelica.Utilities.Streams.print;
      import Modelica_LinearSystems2;
      import Modelica_LinearSystems2.Math.Complex;
      import Modelica_LinearSystems2.ZerosAndPoles;
      import Modelica_LinearSystems2.Internal.printComplexVector;

      output Boolean ok;
    protected
      Complex j = Modelica_LinearSystems2.Math.Complex.j();
      Complex numeratorZeros1[1]={-1+0*j};
      Complex denominatorZeros1[3]={1+0*j,2+3*j,2-3*j};
      Complex numeratorZeros3[4]={-1+j,-1-j,1+0*j,1+0*j};
      Complex denominatorZeros3[6]={1+0*j,2+0*j,2+3*j,2-3*j,3+4*j,3-4*j};

      ZerosAndPoles zp=ZerosAndPoles(z=numeratorZeros1, p=
          denominatorZeros1);
      ZerosAndPoles zp2=ZerosAndPoles(z=numeratorZeros3, p=
          denominatorZeros3);
      Complex numeratorZeros2[:];
      Complex denominatorZeros2[:];
      Real k;

    algorithm
      (numeratorZeros2,denominatorZeros2,k) := ZerosAndPoles.Analysis.zerosAndPoles(zp);

      Modelica.Utilities.Streams.print("ZerosAndPoles-TransferFunction1 = " +
        String(zp));
      Modelica.Utilities.Streams.print("ZerosAndPoles-TransferFunction2 = " +
        String(zp2));
      printComplexVector("numeratorZeros1", numeratorZeros1);
      printComplexVector("\nnumeratorZeros2", numeratorZeros2);

      printComplexVector("\ndenominatorZeros1", denominatorZeros1);
      printComplexVector("\ndenominatorZeros2", denominatorZeros2);

      ok := true;
    end analysisZerosAndPoles;

## Modelica_LinearSystems2.Examples.ZerosAndPoles.conversionToStateSpace

Transform a transfer function from zeros and poles representation into a StateSpace description

### Inputs

Type | Name | Default | Description
--- | --- | --- | ---
ZerosAndPoles | zpi | ZerosAndPoles(k=1, n1={1}, n... |

### Outputs

Type | Name | Description
--- | --- | ---
Boolean | ok |

### Modelica definition

    function conversionToStateSpace
      "Transform a transfer function from zeros and poles representation into a StateSpace description"
      import Modelica_LinearSystems2.StateSpace;
      import Modelica_LinearSystems2.ZerosAndPoles;

      input ZerosAndPoles zpi=ZerosAndPoles(k=1, n1={1}, n2=fill(0,0,2),d1=fill(0,0),d2=[1,1]);

      output Boolean ok;

    protected
      StateSpace ss1=ZerosAndPoles.Conversion.toStateSpace(zpi);      //explicit conversion
      StateSpace ss2=StateSpace(zpi);                                 //short conversion using overloadig
      ZerosAndPoles zpo1=StateSpace.Conversion.toZerosAndPoles(ss1);  //explicit conversion

    algorithm
       Modelica.Utilities.Streams.print("zpi = " + String(zpi));
       Modelica.Utilities.Streams.print("ss1 = " + String(ss1,6,"ss1"));
       Modelica.Utilities.Streams.print("ss2 = " + String(ss2,6,"ss2"));
       Modelica.Utilities.Streams.print("zpo1 = " + String(zpo1));

       ok := true;

    end conversionToStateSpace;

## Modelica_LinearSystems2.Examples.ZerosAndPoles.plotPolesAndZeros

Example for plotting poles and zeros of a ZerosAndPoles transfer function

### Modelica definition

    function plotPolesAndZeros
      "Example for plotting poles and zeros of a ZerosAndPoles transfer function"

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

    protected
      TransferFunction s = TransferFunction.s();
      TransferFunction tf = (s^3 + 4*s + 1)/(s^4 + 2*s^3 + 3*s^2 + 4*s);
      ZerosAndPoles zp = ZerosAndPoles(tf);
    algorithm
      Modelica_LinearSystems2.ZerosAndPoles.Plot.polesAndZeros(
        zp=zp,
     defaultDiagram=Modelica_LinearSystems2.Internal.DefaultDiagramPolesAndZeros(
          heading="Poles and zeros of " + String(tf)),
          device=Modelica_LinearSystems2.Utilities.Plot.Records.Device(xTopLeft=50, yTopLeft=30));

    end plotPolesAndZeros;

## Modelica_LinearSystems2.Examples.ZerosAndPoles.plotBode1

Construct a ZerosAndPoles system and plot the Bode diagram with automatic determination of the frequency range to plot

### Inputs

Type | Name | Default | Description
--- | --- | --- | ---
Frequency | f_cut | 100 | PT1 with cut-off frequency f_cut [Hz]

### Outputs

Type | Name | Description
--- | --- | ---
Boolean | ok |

### Modelica definition

    function plotBode1
      "Construct a ZerosAndPoles system and plot the Bode diagram with automatic determination of the frequency range to plot"
      import Modelica.Utilities.Streams.print;
      import Modelica_LinearSystems2.TransferFunction;
      import Modelica_LinearSystems2.ZerosAndPoles;
      import Modelica_LinearSystems2.Math.Complex;

      input Modelica.SIunits.Frequency f_cut=100 "PT1 with cut-off frequency f_cut";
      output Boolean ok;
    protected
      Modelica.SIunits.AngularVelocity w=2*Modelica.Constants.pi*f_cut;
      TransferFunction tf=TransferFunction(n={w}, d={1,w});
      ZerosAndPoles zp=ZerosAndPoles(tf);
    algorithm
      Modelica_LinearSystems2.ZerosAndPoles.Plot.bode(    zp);
      ok := true;

    equation

    end plotBode1;

## Modelica_LinearSystems2.Examples.ZerosAndPoles.plotBode2

Bode plot of PT2 transfer function with zero damping

### Inputs

Type | Name | Default | Description
--- | --- | --- | ---
Frequency | f_cut | 10 | Cut-off frequency of denominator PT2 [Hz]
Real | D | 0 | Damping of denominator PT2
Real | k | 1 | Gain
Integer | nPoints | 1000 |

### Outputs

Type | Name | Description
--- | --- | ---
Boolean | ok |

### Modelica definition

    function plotBode2
      "Bode plot of PT2 transfer function with zero damping"
      import Modelica_LinearSystems2.Math.Complex;
      import Modelica.Utilities.Streams.print;
      import Modelica_LinearSystems2.TransferFunction;
      import Modelica_LinearSystems2.ZerosAndPoles;

      input Modelica.SIunits.Frequency f_cut=10
        "Cut-off frequency of denominator PT2";
      input Real D=0 "Damping of denominator PT2";
      input Real k=1 "Gain";
      input Integer nPoints=1000;
      output Boolean ok;
    protected
      Modelica.SIunits.AngularVelocity w=2*Modelica.Constants.pi*f_cut;
      TransferFunction tf=TransferFunction(n={k*w^2}, d={1,2*D*w,w*w});
      ZerosAndPoles zp=ZerosAndPoles(tf);
    algorithm
      Modelica_LinearSystems2.ZerosAndPoles.Plot.bode(
                                      zp, nPoints);
      ok := true;

    end plotBode2;

## Modelica_LinearSystems2.Examples.ZerosAndPoles.plotBode3

Construct a ZerosAndPoles system and plot the Bode diagram with automatic determination of the frequency range to plot

### Inputs

Type | Name | Default | Description
--- | --- | --- | ---
Frequency | f_cut_num | 100 | Cut-off frequency of numerator PT2 and PT1 [Hz]
Real | D_num | 0.1 | Damping of numerator PT2
Frequency | f_cut_den | 10 | Cut-off frequency of denominator PT2 and PT1 [Hz]
Real | D_den | 0.1 | Damping of denominator PT2
Real | k | 1 | Gain

### Outputs

Type | Name | Description
--- | --- | ---
Boolean | ok |

### Modelica definition

    function plotBode3
      "Construct a ZerosAndPoles system and plot the Bode diagram with automatic determination of the frequency range to plot"
      import Modelica.Utilities.Streams.print;
      import Modelica_LinearSystems2.ZerosAndPoles;
      import Modelica_LinearSystems2.TransferFunction;
      import Modelica_LinearSystems2.Math.Polynomial;

      input Modelica.SIunits.Frequency f_cut_num=100
        "Cut-off frequency of numerator PT2 and PT1";
      input Real D_num=0.1 "Damping of numerator PT2";
      input Modelica.SIunits.Frequency f_cut_den=10
        "Cut-off frequency of denominator PT2 and PT1";
      input Real D_den=0.1 "Damping of denominator PT2";
      input Real k=1 "Gain";
      output Boolean ok;
    protected
      Modelica.SIunits.AngularVelocity w1=2*Modelica.Constants.pi*f_cut_num;
      Modelica.SIunits.AngularVelocity w2=2*Modelica.Constants.pi*f_cut_den;

      Polynomial pn1=Polynomial(k/w1^3*{1,w1});
      Polynomial pn2=Polynomial({1,2*D_num*w1,w1*w1});
      Polynomial pn3=pn1*pn2;
      Polynomial pd1=Polynomial({1,w2});
      Polynomial pd2=Polynomial({1,2*D_den*w2,w2*w2});
      Polynomial pd3=pd1*pd2;

      TransferFunction tf1=TransferFunction(n=pn3, d=Polynomial({1}));
      TransferFunction tf2=TransferFunction(n=Polynomial({k*w2^3}), d=pd3);
      TransferFunction tf3=tf1*tf2;

      ZerosAndPoles zp1=ZerosAndPoles(tf1);
      ZerosAndPoles zp2=ZerosAndPoles(tf2);
      ZerosAndPoles zp3=ZerosAndPoles(tf3);

      Modelica.SIunits.Frequency f_min=2;
      Modelica.SIunits.Frequency f_max=200;
    algorithm
      Modelica_LinearSystems2.ZerosAndPoles.Plot.bode(
        zp1,
        autoRange=false,
        f_min=f_min,
        f_max=f_max);
      Modelica_LinearSystems2.ZerosAndPoles.Plot.bode(
        zp2,
        autoRange=false,
        f_min=f_min,
        f_max=f_max);
      Modelica_LinearSystems2.ZerosAndPoles.Plot.bode(
        zp3,
        autoRange=false,
        f_min=f_min,
        f_max=f_max);
       ok := true;

    end plotBode3;

## Modelica_LinearSystems2.Examples.ZerosAndPoles.plotBodeFilter1

Compute filter and plot frequency response of filter

### Inputs

Type | Name | Default | Description
--- | --- | --- | ---
AnalogFilter | analogFilter | Types.AnalogFilter.CriticalD... | Analog filter characteristics (CriticalDamping/Bessel/Butterworth/Chebyshev)
Integer | order | 2 |
Frequency | f_cut | 10 | [Hz]

### Outputs

Type | Name | Description
--- | --- | ---
Boolean | ok |

### Modelica definition

    function plotBodeFilter1
      "Compute filter and plot frequency response of filter"
      import Modelica;
      import Modelica_LinearSystems2.ZerosAndPoles;
      import Modelica_LinearSystems2.Types;

      input Types.AnalogFilter analogFilter=Types.AnalogFilter.CriticalDamping
        "Analog filter characteristics (CriticalDamping/Bessel/Butterworth/Chebyshev)";
      input Integer order=2;
      input Modelica.SIunits.Frequency f_cut=10;
      output Boolean ok;
    protected
      ZerosAndPoles tf_filter=ZerosAndPoles.Design.filter(
          order=order,
          f_cut=f_cut,
          analogFilter=analogFilter);

    algorithm
      Modelica_LinearSystems2.ZerosAndPoles.Plot.bode(
                                      tf_filter);
      ok := true;
    equation

    end plotBodeFilter1;

## Modelica_LinearSystems2.Examples.ZerosAndPoles.plotBodeFilter2

Show low pass filters of all filter types

### Inputs

Type | Name | Default | Description
--- | --- | --- | ---
Integer | order | 4 | Order of filter
Frequency | f_cut | 1 | Cut-off frequency [Hz]
Real | A_ripple | 3 | Pass band ripple for Chebyshev filter (otherwise not used) [dB]
Frequency | f_min | 0.1 | Minimum frequency value [Hz]
Frequency | f_max | 10 | Maximum frequency value [Hz]

### Outputs

Type | Name | Description
--- | --- | ---
Boolean | ok |

### Modelica definition

    function plotBodeFilter2 "Show low pass filters of all filter types"
      import Modelica;
      import Modelica_LinearSystems2.ZerosAndPoles;
      import AF = Modelica_LinearSystems2.Types.AnalogFilter;

      input Integer order(min=1) = 4 "Order of filter";
      input Modelica.SIunits.Frequency f_cut=1 "Cut-off frequency";
      input Real A_ripple(unit="dB") = 3
        "Pass band ripple for Chebyshev filter (otherwise not used)";
      input Modelica.SIunits.Frequency f_min(min=0) = 0.1 "Minimum frequency value";
      input Modelica.SIunits.Frequency f_max(min=0) = 10 "Maximum frequency value";
      output Boolean ok;
    protected
      ZerosAndPoles tf1=ZerosAndPoles.Design.filter(
          analogFilter=AF.CriticalDamping,
          order=order,
          f_cut=f_cut,
          A_ripple=A_ripple);
      ZerosAndPoles tf2=ZerosAndPoles.Design.filter(
          analogFilter=AF.Bessel,
          order=order,
          f_cut=f_cut,
          A_ripple=A_ripple);
      ZerosAndPoles tf3=ZerosAndPoles.Design.filter(
          analogFilter=AF.Butterworth,
          order=order,
          f_cut=f_cut,
          A_ripple=A_ripple);
      ZerosAndPoles tf4=ZerosAndPoles.Design.filter(
          analogFilter=AF.Chebyshev,
          order=order,
          f_cut=f_cut,
          A_ripple=A_ripple);
    algorithm
      Modelica_LinearSystems2.ZerosAndPoles.Plot.bode(
        tf1,
        autoRange=false,
        f_min=f_min,
        f_max=f_max);
      Modelica_LinearSystems2.ZerosAndPoles.Plot.bode(
        tf2,
        autoRange=false,
        f_min=f_min,
        f_max=f_max);
      Modelica_LinearSystems2.ZerosAndPoles.Plot.bode(
        tf3,
        autoRange=false,
        f_min=f_min,
        f_max=f_max);
      Modelica_LinearSystems2.ZerosAndPoles.Plot.bode(
        tf4,
        autoRange=false,
        f_min=f_min,
        f_max=f_max);

      ok := true;

    end plotBodeFilter2;

## Modelica_LinearSystems2.Examples.ZerosAndPoles.plotBodeFilter3

Show high pass filters of all filter types

### Inputs

Type | Name | Default | Description
--- | --- | --- | ---
Integer | order | 4 | Order of filter
Frequency | f_cut | 1 | Cut-off frequency [Hz]
Real | A_ripple | 3 | Pass band ripple for Chebyshev filter (otherwise not used) [dB]
Frequency | f_min | 0.1 | Minimum frequency value [Hz]
Frequency | f_max | 10 | Maximum frequency value [Hz]

### Outputs

Type | Name | Description
--- | --- | ---
Boolean | ok |

### Modelica definition

    function plotBodeFilter3 "Show high pass filters of all filter types"
      import Modelica_LinearSystems2.ZerosAndPoles;
      import AF = Modelica_LinearSystems2.Types.AnalogFilter;
      import FT = Modelica_LinearSystems2.Types.FilterType;

      input Integer order(min=1) = 4 "Order of filter";
      input Modelica.SIunits.Frequency f_cut=1 "Cut-off frequency";
      input Real A_ripple(unit="dB") = 3
        "Pass band ripple for Chebyshev filter (otherwise not used)";
      input Modelica.SIunits.Frequency f_min(min=0) = 0.1 "Minimum frequency value";
      input Modelica.SIunits.Frequency f_max(min=0) = 10 "Maximum frequency value";
      output Boolean ok;
    protected
      ZerosAndPoles tf1=ZerosAndPoles.Design.filter(
          analogFilter=AF.CriticalDamping,
          order=order,
          f_cut=f_cut,
          A_ripple=A_ripple,
          filterType=FT.HighPass);
      ZerosAndPoles tf2=ZerosAndPoles.Design.filter(
          analogFilter=AF.Bessel,
          order=order,
          f_cut=f_cut,
          A_ripple=A_ripple,
          filterType=FT.HighPass);
      ZerosAndPoles tf3=ZerosAndPoles.Design.filter(
          analogFilter=AF.Butterworth,
          order=order,
          f_cut=f_cut,
          A_ripple=A_ripple,
          filterType=FT.HighPass);
      ZerosAndPoles tf4=ZerosAndPoles.Design.filter(
          analogFilter=AF.Chebyshev,
          order=order,
          f_cut=f_cut,
          A_ripple=A_ripple,
          filterType=FT.HighPass);
    algorithm
      Modelica_LinearSystems2.ZerosAndPoles.Plot.bode(
        tf1,
        autoRange=false,
        f_min=f_min,
        f_max=f_max);
      Modelica_LinearSystems2.ZerosAndPoles.Plot.bode(
        tf2,
        autoRange=false,
        f_min=f_min,
        f_max=f_max);
      Modelica_LinearSystems2.ZerosAndPoles.Plot.bode(
        tf3,
        autoRange=false,
        f_min=f_min,
        f_max=f_max);
      Modelica_LinearSystems2.ZerosAndPoles.Plot.bode(
        tf4,
        autoRange=false,
        f_min=f_min,
        f_max=f_max);

      ok := true;

    end plotBodeFilter3;

## Modelica_LinearSystems2.Examples.ZerosAndPoles.plotStep

Step plot example

### Information

Computes the impulse response of the system tf =1/s^2 + s + 1.

### Modelica definition

    function plotStep "Step plot example"

      import Modelica_LinearSystems2.ZerosAndPoles;

    protected
      ZerosAndPoles zp=ZerosAndPoles(k=1,n1=fill(0,0),d2=[1,1]);

    algorithm
     Modelica_LinearSystems2.ZerosAndPoles.Plot.step(        zp=zp, dt=0.1, tSpan=10);

    end plotStep;