# -

CHAPTER

23

Development of DiscreteTime Models

Digital control systems inherently involve the processing of sampled signals. Thus, unless the sampling period is very small, it is more appropriate and convenient to perform the design and analysis of digital control systems using discrete-time models rather than continuous-time models. In this chapter we present several approaches for converting dynamic models based on differential equations to discrete-time models described by difference equations. We also consider a method for developing discrete-time models from experimental data. This method is analogous to the empirical approach for developing continuous-time models that was discussed in Chapter 7.

23.1

FINITE DIFFERENCE MODELS

A digital computer by its very nature deals internally with discrete data or numerical values of functions. To perform analytical operations such as differentiation and integration, numerical approximations must be utilized. Fortunately, formulas for such approximations are well established in the field of numerical analysis [1]. One way of converting continuous-time models to discrete-time form is to use finite difference techniques. In general, a nonlinear differential equation,
dy(t)

dt

=

fey,

x)

(23-1 )

where y is the output variable and x is the input variable, can be numerically integrated (although with some error) by introducing a finite difference approximation for the derivative. For example, the first-order, backward difference approximation to the derivative at time t = 11M is [1]
dy

= y"

-

dt -

M

Yl/-l

where 6.t is the integration interval that is specified by the user, y" is the value of yet) at t = 116.t and Yl/-l denotes the value at the previous sampling instan1 t = (11-1)6.t. Substituting (23-2) into (23-1) and evaluating function fey, x) at the previous values of y and x (i.e., y,,-1 and X,,-I) gives
y" Yl/-l M
==

f(y"-b

X,,-I)

549

550 or

DEVELOPMENT

OF DISCRETE-TIME

MODELS

(23-4)

Equation 23-4 is a first-order difference equation that can be used to predict the value of Y at time step n based on information at the previous time step (n-1), namely, YII_I and f(YII-b XII-I)' This type of expression is called a recurrence relation. It can be used to numerically integrate Eq. 23-1 by calculating y" for n = 0,1,2,3, ... starting from known initial conditions, y(O) and x(O). In general, the resulting numerical solution, {Y,,, n = 1, 2, 3, ... }, becomes more accurate and approaches the correct solution yet) as t1t decreases. However, for extremely small values of t1t, computer roundoff errors can be a significant source of error [1,2]. Equation 23-4 is the simplest numerical integration scheme and is referred to as Euler integration. The algorithm for Euler integration can also be expressed in the analogous form,
(23-5)

that results from using a forward difference approximation to the derivative rather than the backward difference in Eqn. (23-3):
dy
dt

= Y"+l
-

- YII
D.t

(23-6)

Equation 23-4 can then be derived from Eq. 23-3 by evaluating f(y, x) at the nth time step, followed by shifting all indices back one step. The forward difference derivation is the standard approach presented in numerical analysis books (e.g., [1]). An important application of Eq. 23-4 in digital control is that it can be used as an approximate process model if the input and output signals are sampled. In this case, t::..t is interpreted as the sampling period rather than the integration interval.
EXAMPLE 23.1

Develop a difference equation that approximates the differential equation,
T

d~~t)

+

yet)

=

x(t)

(23-7)

or equivalently,
dy (t) dt
Solution

1
-T

yet)

1 + - x(t) 'T

(23-8)

Note that if the initial condition is zero, that is, if y(O) = 0, these equations correspond to the first-order transfer function with unity gain:
yes) Xes)

=

_1
TS

+ 1

(23-9)

Using a backward difference approximation for the derivative and substitutingy"_1 for yet) and X,,_I for x(t) in Eq. 23-8, we obtain
T(y" - YII-l)

t1t

+

y,,-I

=

XII-I

23.1 Finite Difference

Models

551

Table 23.1

The Elfect of Integration Interval on the Step Response of a First-Order Model (,- = 1) 1.968 0.1 !:::.t ilt 0.900== 0.25 .990 .684 .997 0 0.985 0.958 0.879 0.651 0.995 0.410 0.438 Numerical
solution,
y"
!:::.t

Exact solution

= 0.01
o

yet)

o

0.395 0.634 0.866 0.951 0.982 0.993

0.393 0.632 0.865 0.951 0.982 0.993

Rearranging gives
Yll
'T = (1 - M)

YIl-\

+ M Xll-l
"i

(23-10)

The new value Yll is a weighted sum of the previous value YIl-l and the previous input, Note that the digital filter derived in Chapter 22 differs from (23-10) because f is evaluated at the nth time step. This is because the filter is employed for smoothing the current measurement whereas (23-10) is used for prediction. As D.t becomes infinitesimally small, the finite difference relation in Eq. 23-10 becomes a better approximation of the differential equation in (23-8). If Eq. 2310 is used to numerically integrate (23-8) to t = 5 (nearly steady state) for a unit step change in x(t), the integration error becomes substantial as D.t becomes quite large compared to,-, the time constant. Table 23.1 compares the analytical solution of (23-8) with the numerical solution obtained using (23-10) for T = 1 and various integration intervals.
XI1-].

The previous example has shown that a discrete-time version of a first-order differential equation can be derived using a backward difference approximation. Alternative discrete-time models can be obtained by using other finite difference approximations. Next we consider how discrete-time models can be derived for higher-order differential equations.

EXAMPLE

23.2

Develop a finite difference approximation for the second-order differential equation, (23-11)
Solution

The second-order derivative at the nth time step can be approximated by the finite difference approximation [1]:
2YIl-l

+

YIl-2

(D.tf

(23-12)

552

DEVELOPMENT

OF DISCRETE-TIME

MODELS

Substituting (23-12) and (23-2) into (23-11), replacing and rearranging yields

Y

and x by

Y 1/-1

and

XI/-I>

[ (M)2 + t::.t 1 al]

Yn

= [2 (M)2 +

t::.t a]] -

ao

YI/-I

-

(t::.tf YI/-2 1

+

(23-13)
XI/-l

All of the terms on the right side of (23-13) involve past information. Alternative discrete-time models can be obtained by other finite difference approximations, as discussed by Davis [1].

23.2

EXACT DISCRETIZATION

FOR LINEAR SYSTEMS

For a process described by a linear differential equation, an alternative discretetime model can be derived based on the analytical solution for a piecewise constant input. This approach yields an exact discrete-time model if the input variable is actually constant between sampling instants. Thus, this analytical approach eliminates the discretization error inherent in finite difference approximations for the important practical situation where the digital computer output (process input) is held constant between sampling instants. This signal is piecewise constant if the DAC acts as a zero-order hold, as discussed in Chapters 21 and 22. As an illustrative example, consider the first-order system in Eq. 23-7. Assume that x(t) is constant such that x(t) = x(O), and that y(O) #- O. Taking the Laplace transform of (23-8) gives

1
sY(s) y(O)

_:.

Y(s)

+

l

T x(O) S

(23-14)

Solving for

Y(s),

Y(s)

= s +1liT

[l -s- +
T

x(O)

y(O) ]

(23-15)

and taking inverse Laplace transforms gives
y(t)

=

x(O)

(1 -

e-tl,)

+

y(O) e-tl,

(23-16)

Equation 23-16 is valid for all values of t. Thus, after one sampling period, t = t::.t, and we have (23-17) Next, we can generalize the analysis by considering the time interval, (n-1) to nt::.t. For an initial condition y[(n-1)M] and a constant input, x(t) x[(n-1) t::.t] for (n-1) M t < nt::.t, the analytical solution to (23-7) is
t::.t

s

=

y(nM)

=

x[(n-1)t::.t](1

-

e-:::.tl,)

+

y[(n-1)M]e-,-,tl,

(23-18)

Note that the exponential terms are the same as for Eq. 23-17. Equation 23-18 can be written more compactly as
Yl/

-

e -MI, YI/_]

+ (1 -

e -MI.). XI/_]

(23-19)

Equation 23-19 is the exact solution to (23-7) providing that x(t) is constant over each sampling period of length t::.t. If Eq. 23-19 had been used in Example 23.1 to obtain the step response, the analytical solution y(t) would have resulted for any sampling period (no integration error for the constant input).

552

DEVELOPMENT

OF DISCRETE-TIME

MODELS

Substituting (23-12) and (23-2) into (23-11), replacing and rearranging yields

Y and x by YIl-l

and Xll-],

[ (~t)2 + 1

~t ] Yll a]

= [2 (~t)2 +

~t a]]

ao

Yll-]

-

(M)" 1

YIl-2

+

(23-13)
Xll-l

All of the terms on the right side of (23-13) involve past information. Alternative discrete-time models can be obtained by other finite difference approximations, as discussed by Davis [1].

23.2

EXACT DISCRETIZATION

FOR LINEAR SYSTEMS

For a process described by a linear differential equation, an alternative discretetime model can be derived based on the analytical solution for a piecewise constant input. This approach yields an exact discrete-time model if the input variable is actually constant between sampling instants. Thus, this analytical approach eliminates the discretization error inherent in finite difference approximations for the important practical situation where the digital computer output (process input) is held constant between sampling instants. This signal is piecewise constant if the DAC acts as a zero-order hold, as discussed in Chapters 21 and 22. As an illustrative example, consider the first-order system in Eq. 23-7. Assume that x(t) is constant such that x(t) = x(O), and that y(O) oF- O. Taking the Laplace transform of (23-8) gives

1
sY(s) Solving for Y(s), y(O)

_:.

yes)

+ ~ x(O) T S

(23-14)

yes)

= =

+ liT _1_
s

T S [~X_-(_O)

+

Y(O)]

(23-15)

and taking inverse Laplace transforms
yet) x(O)

gives
e-II,)

(1 -

+

y(O) e-II,

(23-16)

Equation

t

= ~t,

23-16 is valid for all values and we have

of

t. Thus, after one sampling period,
(23-17)

Next, we can generalize the analysis by considering the time interval, (n-1) to n~t. For an initial condition y[(n-1)~t] and a constant input, x(t) x[(n -1) M] for (n -1) M:s t < n~t, the analytical solution to (23-7) is
y(n~t)

~t

=

=

x[(n -1)~t](l

-

e-MI,)

+

y[(n-1)M]e-..'.II,

(23-18)

Note that the exponential terms are the same as for Eq. 23-17. Equation be written more compactly as
Yll e -6.11, Yll-]

23-18 can (23-19)

+ (1 -

e -..'.11,)_XIl-]

Equation 23-19 is the exact solution to (23-7) providing that x(t) is constant over each sampling period of length ~t. If Eq. 23-19 had been used in Example 23.1 to obtain the step response, the analytical solution yet) would have resulted for any sampling period (no integration error for the constant input).

23.4

Fitting Discrete-Time

Equations to Process Data

553

23.3

HIGHER-ORDER

SYSTEMS

To derive a discrete-time version of a higher-order differential equation, we can use the analytical solution and proceed as in the previous section. An alternative approach based on z-transforms will be presented in Chapter 24. A linear differential equation of order p, when converted to discrete time, yields a linear difference equation also of order p. For example, consider the secondorder system:
Y(s) .
K(TaS

G(s)

= X(s)

= hs

+ 1) + l)(Tzs + 1)

(23-20)

Using the analytical solution for a constant input provides the corresponding difference equation:
Yn

+

ajYn-j e-flt/T2

+

aZYn-Z

bjxn-j

+

bzxn-z

(23-21) (23-22) (23-23) (23-24)

where

aj

_e-M/T1 e-M/Tle-M/T2

az -

(23-25)
In Eq. 23-21 the new value of Y depends on the values of Y and x at the two previous sampling instants; hence it is a second-order difference equation. If T2 = Ta = 0 and K = 1 in Eq. 23-21 through 23-25, the first-order difference equation in (2319) results. The steady-state gain of the second-order difference equation model can be found by considering steady-state conditions. Let x denote a step change in x and y the resulting steady-state change in y. At steady state, Xn-] = Xn-Z = x and Yn = YIl-j = Yn-Z = Y. Substituting these values into (23-21) gives
y

+

a[ y

+

a2Y

=

bjx

+

b2x

(23-26)

Since Y and x are deviation variables, the steady-state gain is simply ylx, the steadystate change in Y divided by the steady-state change in x. Rearranging (23-26) gives Gam = - =
x
. y
b[

+
aj

bo

1+

+

~

az

(23-27)

Substitution of Eqs. (23-22) through (23-25) into (23-27) gives, Gain K. This same result can be obtained by letting s --7 0 in (23-20). Thus the transfer function model in (23-20) and the corresponding discrete-time model in (23-21) have the same steady-state gains. This result also occurs for all other transfer function models. Sets of differential equations can be converted to a discrete-time, difference equation model by using a technique referred to as the transition matrix approach [2]. General results for converting second-order and third-order differential equations (transfer functions) to difference equations have been derived by Neuman and Baradello [3] and are presented in Chapter 24.
23.4 FITTING DISCRETE-TIME EQUATIONS TO PROCESS DATA

In Chapter 7 we discussed methods for fitting continuous-time models (transfer functions) to process data. If a discrete-time model is desired, one approach is to

554

DEVELOPMENT

OF DISCRETE-TIME

MODELS

fit a continuous-time model to experimental data and then to convert it to discrete form using the approach of Section 23.2. An alternative approach is to fit a discretetime model to the data directly without first obtaining a continuous-time model. An important advantage of the latter approach is that the model parameters can be calculated using the well-known linear regression technique (see Chapter 7). As a specific example, consider a rearranged version of the second-order difference equation (23-21). This model allows Y II to be predicted from data available at time (n-l), or (23-29) denotes the prediction of Y n that is made at time (n -1), G; = - G 1, and In developing a discrete-time model, model parameters GJ, G2, bJ, and b2 are treated as unknowns to be estimated by fitting the data. Note that the right side of (23-29) involves previous measurements of Y rather than previous predictions. In general, Yn 0/= Yn, due to a number of practical considerations which include model inaccuracy, unmeasured disturbances, and measurement noise. The objective of this parameter estimation problem is to determine numerical values for the unknown parameters so that the difference between the measurements and the predictions from Eq. 23-29 are as small as possible. The least-squares technique presented in Chapter 7 can be used here; the error criterion to be minimized is where
G2

Yn

=

-G2'

n~l

2:

(Yn

-

Yllf

(23-30)

where Yn is the nth data point, Yn is the corresponding prediction made with measured values of x and Y up to and including time (n -1), and r is the number of data points.
EXAMPLE

23.3

Consider the step response data {Yn} in Table 23.2 which were obtained from Example 7.3 and Fig. 7.8. At t = 0 a unit step change in x occurs, but the first output change is not observed until the next sampling instant. Fit the second-order difference equation (23-21) to the above input-output data using 6.t = 1. Compare
07 6 110 2 4 9 8 5 3
aM

=
1;

for

n

<

0,

y"

=

Table 23.2 x" = O.
O.

0.833 0.058 0.692 0.600 0.217 0.888 0.772 0.488 0.360 0 y" 9 8 7 1 5 4 3 10 6 2 0.925 Step0 Response Data"

and n

X1/-2 11 Yn 0.692 10.888 Yll-2 ,,-l 0.0580.772 0.217 0.360 0Xn-l 0.058 0.217 0 0.888Matrix 0.833 1 0.772 0 0.692 0.600 0.925 0.600 0.488 0.360 0.488 23.4 Fitting 555 Discrete-Time Equations DataY0.833 for Estimating Parameters in Eq. 23-21

to Process Data

these results with models obtained in Example 7.3 using Harriott's method and nonlinear regression.
Solution XII-I> XII-2),

For the linear regression problem, there are four independent variables (YII- [, YII-2, one dependent variable (YII)' and four unknown parameters (a;, a2, bj, b2). We structure the data as shown in Table 23.3 and, using the least squares equations, solve four linear algebraic equations in four unknowns. Table 23.4 compares the parameter values obtained by the three different approaches. The "Linear Regression" results were obtained by fitting a discretetime model so as to minimize Eq. 23-30. The results labeled "Harriott's method" and "Nonlinear Regression" were obtained by fitting a continuous-time model (second-order, overdamped) to the data to obtain time constants T) and T2 (see Example 7.3). In both cases, the model gain K was set equal to unity because the step responses were normalized. The continuous-time model was then converted to the corresponding discrete-time model via Eqs. 23-21 to 23-25. The parameters obtained from linear regression in Table 23.4 are similar to the results for the other two methods but the differences are noteworthy. Using linear regression, four parameters were fit independently; with nonlinear regression only two parameters, TI and T2, were estimated. Because the model gain was fixed at unity for nonlinear regression, this optimization method contained an implicit constraint. No such constraint was included in the linear regression approach. Consequently, the calculated model gain for linear regression, K = 1.168, is about 17% too large. This value was calculated from Eq. 23-27. Linear regression would yield model parameters closer to those for continuous time, nonlinear regression if 10 to 20 additional data points at or near the steady state were added to the data set. Alternatively, the values of a;, a2, b), and b2
Comparison of Estimated Model Parameters for Example 23.2
Linear Regression Harriott's Method 1.218 - 0.348 0.076 0.054 1. 000 Nonlinear Regression 1.310 - 0.425 0.066 0.050 1. 000

Table 23.4

a;

0.975 -0.112 0.058 0.102 1.168

I

a2

556
23.5

--

Ys YH Y 0.192 0.0580.058 0.2170.217 0.3600.365 0.6000.596 0.6920.690 0.8330.835 0.7720.767 0.8880.886 0.925 0.066 0.375 0.496 0.602 0.695 0.924 0.833 0.768 0.201 0.076 0.374 0.493 0.599 0.691 0.921 0 0.830 0.764 0.876 0.4880.487 0.880 DEVELOPMENT YL OFofDISCRETE-TIMEResponses MODELS Comparison.932 Simulated

for Various Difference Equation Models"

"y, exact response for continuous system; Y L, linear regression;

.v H'

Harriott's method; ,I's. nonlinear

regression.

could be optimized subject to the constraint that the process gain in Eq. 23-27 is unity; however, this would require a modified linear regression approach. Table 23.5 compares the simulated responses for the three empirical models. Linear regression gives the best predictions because it fits the most parameters. Most of the differences among the models occur for the initial response en < 2). In this particular example, it is difficult to distinguish graphically among the three models and the step response data for n > 2.

The above example has shown how we can fit a second-order difference equation model to data directly. The linear regression approach can also be used for higher-order models, provided that the parameters still appear linearly in the model. It is important to note that the calculated parameter values depend on the sampling period that is selected, which in turn may be determined by the frequency of data collection. In general, changing will result in different parameter estimates. An attractive feature of linear regression is that it is not necessary to make a step change in x to estimate model parameters. An arbitrary input variation over a limited period of time would suffice. In particular, we need not force the system to a new steady state, a beneficial feature for industrial applications. However, as noted above, enough data should be taken to give an accurate steady-state gain.
I:::.t I:::.t

SUMMARY In this chapter we have presented several methods for developing discrete-time

process models in the form of linear difference equations. If a continuous-time process model is available as one or more linear differential equations, then the corresponding discrete-time model can be derived analytically. This approach yields an exact discrete-time model provided that the process inputs are piecewise constant over the sampling period. An alternative approach is to use finite difference techniques to develop approximate discrete-time models. This approach is used when the continuous-time model consists of nonlinear differential equations and the analytical solution is not available. An important advantage of discrete-time models is that they can be readily obtained by fitting experimental response data. Example 23.2 has illustrated that

Exercises

557

standard linear regression techniques can be employed to estimate the unknown model parameters in a linear difference equation model.

REFERENCES
1. Davis, M. E., Numerical Methods and Modeling for Chemical Engineers, Wiley, New York, 1984, Chapter 2. 2. Cadzow, J. A., and H. R. Martens, Discrete-Time and Computer Control Systems, Prentice-Hall, Englewood Cliffs, NJ, 1970. 3. Neuman, C. P., and C. S. Baradello, Digital Transfer Functions for Microcomputer Control. IEEE Trans. Systems. Man, Cybernetics SMC-9 (12), 856 (1979).

EXERCISES
23.1. Consider the first-order differential equation
dy 5 dt

+

Y = 6x

y(O)

= 3

where

x(t)

is piecewise constant and assumes the following values: x(3) = 1 x(O) = 0 x(4) = 0 x(l) = 3 for t > 4 x(t) =0 x(2) = 2
t:.t

Develop a difference equation for this ordinary differential equation using (a) exact discretization (b) finite difference Compare the integrated results for 0 s; the finite difference model.

= 1 and

t

s; 10. Examine whether

t:.t

= 0.1 improves

23.2. The following data were collected from a temperature sensor immersed in a gas stream. The input x is the flow rate deviation (in dimensionless units) and the sensor output y is given in millivolts. The flow (input) is piecewise constant over the intervals shown. The process is not at steady state initially, so y can change even though x = O.
Time (s) y3 0 6.493 1 3.000 2.456 5.243 6.404 4.293 2.877 2.356 5.274 3.514 1.929 0 2 x

Fit a first-order model, Yn = aiYn-I + b1xn-l' to the data using the least-squares approach. Plot the responses of the fitted mcdel and the actual data. Can you also find a first-order continuous transfer function to fit the data? 23.3. Fit a first-order discrete-time model to the step response data in Table 23.2. Compare your results with the graphical method for step response data, fitting the gain and time constant. Plot the two simulated step responses for comparison with the observed data.

558

DEVELOPMENT

OF DISCRETE-TIME

MODELS

23.4. A second-order differential equation is given as
d2y dt2

+ 3

dy dt

+

2y

=

x

For a unit step change in x (x changes from a to 1.0 at t = 0), calculate the responses (0:::; t:::; 5) for t:.t = 0.1 and M = 0.5. Perform the integration using the exact solution and a finite difference approximation (see Example 23.2). The initial conditions y and dy/dt are both zero at t = O.