Accelerating the pace of engineering and science

Documentation

Discrete-Time Model Creation

How to create discrete-time models.

Discrete-Time Transfer Function Model

This example shows how to create a discrete-time transfer function model using tf.

Create the transfer function $G\left(z\right)=\frac{z}{{z}^{2}-2z-6}$ with a sampling time of 0.1 s.

```num = [1 0];
den = [1 -2 -6];
Ts = 0.1;
G = tf(num,den,Ts)
```

num and den are the numerator and denominator polynomial coefficients in descending powers of z. G is a tf model object.

 Tip   Create a discrete-time zpk, ss, and frd models in a similar way by appending a sampling period to the input arguments. For examples, see the reference pages for those commands.

The sampling time is stored in the Ts property of G. Access Ts, using dot notation:

`G.Ts`

Discrete-Time Proportional-Integral-Derivative (PID) Controller

Discrete-Time PID Controller Representations

Discrete-time PID controllers are expressed by the following formulas.

FormFormula
Parallel

$C={K}_{p}+{K}_{i}IF\left(z\right)+\frac{{K}_{d}}{{T}_{f}+DF\left(z\right)},$

where:

• Kp = proportional gain

• Ki = integrator gain

• Kd = derivative gain

• Tf = derivative filter time

Standard

$C={K}_{p}\left(1+\frac{1}{{T}_{i}}IF\left(z\right)+\frac{{T}_{d}}{\frac{{T}_{d}}{N}+DF\left(z\right)}\right),$

where:

• Kp = proportional gain

• Ti = integrator time

• Td = derivative time

• N = derivative filter constant

IF(z) and DF(z) are the discrete integrator formulas for the integrator and derivative filter, respectively. Use the IFormula and DFormula properties of the pid or pidstd model objects to set the IF(z) and DF(z) formulas. The next table shows available formulas for IF(z) and DF(z). Ts is the sample time.

IFormula or DFormulaIF(z) or DF(z)
ForwardEuler (default)

$\frac{{T}_{s}}{z-1}$

BackwardEuler

$\frac{{T}_{s}z}{z-1}$

Trapezoidal

$\frac{{T}_{s}}{2}\frac{z+1}{z-1}$

If you do not specify a value for IFormula, DFormula, or both, ForwardEuler is used by default.

Create Discrete-Time Standard-Form PID Controller

This example shows how to create a standard-form discrete-time Proportional-Integral-Derivative (PID) controller that has Kp = 29.5, Ti = 1.13, Td = 0.15 N = 2.3, and sample time Ts  0.1 :

```C = pidstd(29.5,1.13,0.15,2.3,0.1,...
'IFormula','Trapezoidal','DFormula','BackwardEuler')```

This command creates a pidstd model with $IF\left(z\right)=\frac{{T}_{s}}{2}\frac{z+1}{z-1}$ and $DF\left(z\right)=\frac{{T}_{s}z}{z-1}$.

You can set the discrete integrator formulas for a parallel-form controller in the same way, using pid.