c2d

Convert model from continuous to discrete time

Syntax

sysd = c2d(sys,Ts)
sysd = c2d(sys,Ts,method)
sysd = c2d(sys,Ts,opts)
[sysd,G] = c2d(sys,Ts,method)
[sysd,G] = c2d(sys,Ts,opts)

Description

sysd = c2d(sys,Ts) discretizes the continuous-time dynamic system model sys using zero-order hold on the inputs and a sample time of Ts seconds.

sysd = c2d(sys,Ts,method) discretizes sys using the specified discretization method method.

sysd = c2d(sys,Ts,opts) discretizes sys using the option set opts, specified using the c2dOptions command.

[sysd,G] = c2d(sys,Ts,method) returns a matrix, G that maps the continuous initial conditions x0 and u0 of the state-space model sys to the discrete-time initial state vector x [0]. method is optional. To specify additional discretization options, use [sysd,G] = c2d(sys,Ts,opts).

Input Arguments

sys

Continuous-time dynamic system model (except frequency response data models). sys can represent a SISO or MIMO system, except that the 'matched' discretization method supports SISO systems only.

sys can have input/output or internal time delays; however, the 'matched' and 'impulse' methods do not support state-space models with internal time delays.

The following identified linear systems cannot be discretized directly:

  • idgrey models with FcnType is 'c'. Convert to idss model first.

  • idproc models. Convert to idtf or idpoly model first.

For the syntax [sysd,G] = c2d(sys,Ts,opts), sys must be a state-space model.

Ts

Sample time.

method

String specifying a discretization method:

  • 'zoh' — Zero-order hold (default). Assumes the control inputs are piecewise constant over the sampling period Ts.

  • 'foh' — Triangle approximation (modified first-order hold). Assumes the control inputs are piecewise linear over the sampling period Ts.

  • 'impulse' — Impulse invariant discretization.

  • 'tustin' — Bilinear (Tustin) method.

  • 'matched' — Zero-pole matching method.

For more information about discretization methods, see Continuous-Discrete Conversion Methods.

opts

Discretization options. Create opts using c2dOptions.

Output Arguments

sysd

Discrete-time model of the same type as the input system sys.

When sys is an identified (IDLTI) model, sysd:

  • Includes both measured and noise components of sys. The innovations variance λ of the continuous-time identified model sys, stored in its NoiseVarianceproperty, is interpreted as the intensity of the spectral density of the noise spectrum. The noise variance in sysd is thus λ/Ts.

  • Does not include the estimated parameter covariance of sys. If you want to translate the covariance while discretizing the model, use translatecov.

G

Matrix relating continuous-time initial conditions x0 and u0 of the state-space model sys to the discrete-time initial state vector x [0], as follows:

x[0]=G[x0u0]

For state-space models with time delays, c2d pads the matrix G with zeroes to account for additional states introduced by discretizing those delays. See Continuous-Discrete Conversion Methods for a discussion of modeling time delays in discretized systems.

Examples

Discretize a Transfer Function

Discretize the following continuous-time transfer function:

$$H\left( s \right) = e^{-0.3s}\frac{{s - 1}}{{{s^2} + 4s + 5}}.$$

This system has an input delay of 0.3 s. Discretize the system using the triangle (first-order-hold) approximation with sample time Ts = 0.1 s.

H = tf([1 -1],[1 4 5],'InputDelay', 0.3);
Hd = c2d(H,0.1,'foh');

Compare the step responses of the continuous-time and discretized systems.

step(H,'-',Hd,'--')

Discretize Model with Fractional Delay Asborbed into Coefficients

Discretize the following delayed transfer function using zero-order hold on the input, and a 10-Hz sampling rate.

$$H\left( s \right) = {e^{ - 0.25s}}\frac{{10}}{{{s^2} + 3s + 10}}.$$

h = tf(10,[1 3 10],'iodelay',0.25);
hd = c2d(h, 0.1)
hd =
 
           0.01187 z^2 + 0.06408 z + 0.009721
  z^(-3) * ----------------------------------
                 z^2 - 1.655 z + 0.7408
 
Sample time: 0.1 seconds
Discrete-time transfer function.

In this example, the discretized model hd has a delay of three sampling periods. The discretization algorithm absorbs the residual half-period delay into the coefficients of hd.

Compare the step responses of the continuous-time and discretized models.

step(h,'--',hd,'-')

Discretize Model With Approximated Fractional Delay

Discretize a state-space model with time delay, using a Thiran filter to model fractional delays:

sys = ss(tf([1, 2], [1, 4, 2]));  %  create a state-space model
sys.InputDelay = 2.7              %  add input delay

This command creates a continuous-time state-space model with two states, as the output shows:

a = 
       x1  x2
   x1  -4  -2
   x2   1   0
 
b = 
       u1
   x1   2
   x2   0
 
c = 
        x1   x2
   y1  0.5    1
 
d = 
       u1
   y1   0
 
Input delays (listed by channel): 2.7 
 
Continuous-time model.

Use c2dOptions to create a set of discretization options, and discretize the model. This example uses the Tustin discretization method.

opt = c2dOptions('Method', 'tustin', 'FractDelayApproxOrder', 3);
sysd1 = c2d(sys, 1, opt)     % 1s sampling time 

These commands yield the result

a = 
              x1         x2         x3         x4         x5
   x1    -0.4286    -0.5714   -0.00265    0.06954      2.286
   x2     0.2857     0.7143  -0.001325    0.03477      1.143
   x3          0          0    -0.2432     0.1449    -0.1153
   x4          0          0       0.25          0          0
   x5          0          0          0      0.125          0
 
b = 
             u1
   x1  0.002058
   x2  0.001029
   x3         8
   x4         0
   x5         0
 
c = 
              x1         x2         x3         x4         x5
   y1     0.2857     0.7143  -0.001325    0.03477      1.143
 
d = 
             u1
   y1  0.001029
 
Sampling time: 1
Discrete-time model.

The discretized model now contains three additional states x3, x4, and x5 corresponding to a third-order Thiran filter. Since the time delay divided by the sampling time is 2.7, the third-order Thiran filter (FractDelayApproxOrder = 3) can approximate the entire time delay.

Discretized Identified Model

Discretize an identified, continuous-time transfer function and compare its performance against a directly estimated discrete-time model

Estimate a continuous-time transfer function and discretize it.

load iddata1
sys1c = tfest(z1,2);
sys1d = c2d(sys1c,0.1,'zoh');

Estimate a second order discrete-time transfer function.

sys2d = tfest(z1,2,'Ts',0.1); 

Compare the two models.

compare(z1,sys1d,sys2d)

The two systems are virtually identical.

Build Predictor Model

Discretize an identified state-space model to build a one-step ahead predictor of its response.

load iddata2
sysc = ssest(z2,4);
sysd = c2d(sysc,0.1,'zoh');
[A,B,C,D,K] = idssdata(sysd);
Predictor = ss(A-K*C,[K B-K*D],C,[0 D],0.1);

The Predictor is a two input model which uses the measured output and input signals ([z1.y z1.u]) to compute the 1-step predicted response of sysc.

More About

expand all

Tips

  • Use the syntax sysd = c2d(sys,Ts,method) to discretize sys using the default options for method. To specify additional discretization options, use the syntax sysd = c2d(sys,Ts,opts).

  • To specify the tustin method with frequency prewarping (formerly known as the 'prewarp' method), use the PrewarpFrequency option of c2dOptions.

Algorithms

For information about the algorithms for each c2d conversion method, see Continuous-Discrete Conversion Methods.

Was this topic helpful?