Extras: Difference Equations and System Representations


Difference equations

Whereas continuous-time systems are described by differential equations, discrete-time systems are described by difference equations. From the digital control schematic, we can see that a difference equation shows the relationship between an input signal e(k) and an output signal u(k) at discrete intervals of time where k represents the index of the sample. For example, if the sample time is a constant T, then e(k) represents the value of e at the time kT. Suppose we are interested in the kth output signal u(k). A computer can calculate the output signal u(k) based on the past and current input signals, e(0) to e(k), and past output signals, u(0) to u(k-1). Such a calculation can be expressed as a function of the following form.

(1)$$ u_{k} = f(e(0),...e(k);u(0),...,u(k-1)) $$

We will in general assume that the function f is linear and depends only on a finite number of signals, e(k) and u(k). Therefore, the basic structure of the difference equation can be written as follows.

(2)$$ u_{k} = -a_{k-1}u(k-1) - ... - a_{0}u(0) + b_{k}e(k-1) + ... + b_{0}e(0)$$

For example, the following difference equation calculates the output u(k) based on the current input e(k) and the input and output from the last time step, e(k-1) and u(k-1).

(3)$$ u(k) = 0.75u(k-1) + e(k) - 0.95e(k-1)\;\;\;\;(1)$$

Finding transfer function using the z-transform

Recall that a transfer function for a continuous system as we have considered so far is derived by first taking the Laplace transform of a set of differential equations and then rearranging the results into the form Output/Input. To derive the transfer function in discrete form, a mathematical tool very similar to the Laplace transform called the z-transform will be used.

The z-transform is defined by

(4)$$ Z\{f(k)\}=F(z)=\sum_{k=0}^{\infty} {f(k)z^{-k}}$$

where f(k) is the amplitude of a sample, and the values k = 0, 1, 2, 3, ..., are the index corresponding to the discrete sample time.

The above leads to the following relation where $z^{-m}$ can be thought of as a delay operator.

(5)$$ Z\{f(k-m)\}=z^{-m}F(z) $$

Employing these relations, we can easily find the discrete-time transfer function of a given difference equation.

Suppose we are going to find the transfer function of the system defined by the above difference equation (1). First, apply the above relations to each of u(k), e(k), u(k-1), and e(k-1) and you should arrive at the following.

(6)$$ U(z)= 0.75z^{-1}U(z)+E(z)-0.95z^{-1}E(z)$$

After few steps of algebra, you can rerrange this equation into the form Output\Input and you will have the following transfer function in discrete-time form as shown in equation (2).

(7)$$\frac{U(z)}{E(z)}= \frac{z-0.95}{z-0.75}\;\;\;\;(2) $$

Derivation of state-space from difference equations

As you see in the continuous modeling tutorial page, another way to represent a system is to use the state-space form. The basic structure of the discrete state-space equations is the following.



Matrices A, B, C and D are discrete versions of the state-space matrices employed for the continuous case. We can express our example system in state-space form as follows.



MATLAB representation

Now we will show you how to enter the equations derived above into MATLAB.

1. Transfer Function

Recall for continuous transfer function, the numerator and the denominator matrices are entered in descending powers of s. The same applies to discrete transfer functions. The numerator and the denominator matrices are entered in descending powers of z. For example, we can define the above transfer function from equation (2) as follows.

numDz = [1 -0.95];
denDz = [1 -0.75];
sys = tf(numDz, denDz, -1);

The -1 tells MATLAB that the sample time is undetermined. Alternatively, we can define transfer functions by defining the z variable as follows.

z = tf('z',-1);
sys = (z-0.95)/(z-0.75);

2. State-Space

For discrete state-space models, we can define the model in the same manner we did in the continous case. For example, the above discrete state-space model can be defined as follows.

A = .75;
B = .5;
C = -.4;
D = 1;
sys = ss(A,B,C,D,-1);

Again, -1 is used for an undetermined sample time.