Control Tutorials for MATLAB and Simulink (2024)

In this section, we will discuss converting continuous-time models into discrete-time (or difference equation) models. We will also introduce the z-transform and show how to use it to analyze and design controllers for discrete-time systems.

Key MATLAB commands used in this tutorial are: c2d , pzmap , zgrid , step , rlocus

Related Tutorial Links

  • Difference Equations
  • Discrete Poles
  • Sampling Activity

Related External Links

Contents

  • Introduction
  • Zero-Hold Equivalence
  • Conversion Using c2d
  • Example: Mass-Spring-Damper
  • Stability and Transient Response
  • Discrete Root Locus

Introduction

The figure below shows the typical continuous-time feedback system that we have been considering so far in this tutorial. Almost all continuous-time controllers can be implemented employing analog electronics.

Control Tutorials for MATLAB and Simulink (1)

The continuous controller, enclosed in the shaded rectangle, can be replaced by a digital controller, shown below, that performs the same control task as the continuous controller. The basic difference between these controllers is that the digital system operates on discrete signals (samples of the sensed signals) rather than on continuous signals. Such a change may be necessary if we wish to implement our control algorithm in software on a digital computer, which is frequently the case.

Control Tutorials for MATLAB and Simulink (2)

The various signals of the above digital system schematic can be represented by the following plots.

Control Tutorials for MATLAB and Simulink (3)

The purpose of this Digital Control Tutorial is to demonstrate how to use MATLAB to work with discrete functions, either in transfer function or state-space form, to design digital control systems.

Zero-Hold Equivalence

In the above schematic of the digital control system, we see that the system contains both discrete and continuous portions. Typically, the system being controlled is in the physical world and generates and responds to continuous-time signals, while the control algorithm may be implemented on a digital computer. When designing a digital control system, we first need to find the discrete equivalent of the continuous portion of the system.

For this technique, we will consider the following portion of the digital control system and rearrange as follows.

Control Tutorials for MATLAB and Simulink (4)

Control Tutorials for MATLAB and Simulink (5)

The clock connected to the D/A and A/D converters supplies a pulse every Control Tutorials for MATLAB and Simulink (6) seconds and each D/A and A/D sends a signal only when the pulse arrives. The purpose of having this pulse is to require that Control Tutorials for MATLAB and Simulink (7) acts only on periodic input samples Control Tutorials for MATLAB and Simulink (8), and produces periodic outputs Control Tutorials for MATLAB and Simulink (9) only at discrete intervals of time; thus, Control Tutorials for MATLAB and Simulink (10) can be realized as a discrete function.

The philosophy of the design is the following. We want to find a discrete function Control Tutorials for MATLAB and Simulink (11) so that for a piecewise constant input to the continuous system Control Tutorials for MATLAB and Simulink (12), the sampled output of the continuous system equals the discrete output. Suppose the signal Control Tutorials for MATLAB and Simulink (13) represents a sample of the input signal. There are techniques for taking this sample Control Tutorials for MATLAB and Simulink (14) and for holding it to produce a continuous signal Control Tutorials for MATLAB and Simulink (15). The sketch below shows one example where the continuous signal Control Tutorials for MATLAB and Simulink (16) is held constant at each sample Control Tutorials for MATLAB and Simulink (17) over the interval Control Tutorials for MATLAB and Simulink (18) to Control Tutorials for MATLAB and Simulink (19). This operation of holding Control Tutorials for MATLAB and Simulink (20) constant over the sample period is called a zero-order hold.

Control Tutorials for MATLAB and Simulink (21)

The held signal Control Tutorials for MATLAB and Simulink (22) then is passed to Control Tutorials for MATLAB and Simulink (23) and the A/D produces the output Control Tutorials for MATLAB and Simulink (24) that will be the same piecewise signal as if the discrete signal Control Tutorials for MATLAB and Simulink (25) had been passed through Control Tutorials for MATLAB and Simulink (26) to produce the discrete output Control Tutorials for MATLAB and Simulink (27).

Control Tutorials for MATLAB and Simulink (28)

Now we will redraw the schematic, replacing the continuous portion of the system with Control Tutorials for MATLAB and Simulink (29).

Control Tutorials for MATLAB and Simulink (30)

Now we can design a digital control system dealing with only discrete functions.

Note: There are certain cases where the discrete response does not match the continuous response generated by a hold circuit implemented in a digital control system. For further information, see the page Lagging Effect Associated with a Hold.

Conversion Using c2d

There is a MATLAB function c2d that converts a given continuous system (either in transfer function or state-space form) to a discrete system using the zero-order hold operation explained above. The basic syntax for this in MATLAB is sys_d = c2d(sys,Ts,'zoh')

The sampling time (Ts in sec/sample) should be smaller than 1/(30BW), where BW is the system's closed-loop bandwidth frequency.

Example: Mass-Spring-Damper

Transfer Function

Suppose you have the following continuous transfer function model:

(1)Control Tutorials for MATLAB and Simulink (31)

Assuming the closed-loop bandwidth frequency is greater than 1 rad/sec, we will choose the sampling time (Ts) equal to 1/100 sec. Now, create a new m-file and enter the following commands.

m = 1;b = 10;k = 20;s = tf('s');sys = 1/(m*s^2+b*s+k);Ts = 1/100;sys_d = c2d(sys,Ts,'zoh')
sys_d = 4.837e-05 z + 4.678e-05 ----------------------- z^2 - 1.903 z + 0.9048 Sample time: 0.01 secondsDiscrete-time transfer function.

State-Space

A continuous-time state-space model of this system is the following:

(2)Control Tutorials for MATLAB and Simulink (32)

(3)Control Tutorials for MATLAB and Simulink (33)

All constants are the same as before. The following m-file converts the above continuous-time state-space model to a discrete-time state-space model.

A = [0 1; -k/m -b/m];B = [ 0; 1/m];C = [1 0];D = [0];Ts = 1/100;sys = ss(A,B,C,D);sys_d = c2d(sys,Ts,'zoh')
sys_d = A = x1 x2 x1 0.999 0.009513 x2 -0.1903 0.9039 B = u1 x1 4.837e-05 x2 0.009513 C = x1 x2 y1 1 0 D = u1 y1 0 Sample time: 0.01 secondsDiscrete-time state-space model.

From these matrices, the discrete state-space can be written as

(4)Control Tutorials for MATLAB and Simulink (34)

(5)Control Tutorials for MATLAB and Simulink (35)

Now we have the discrete-time state-space model.

Stability and Transient Response

For continuous systems, we know that certain behaviors result from different pole locations in the s-plane. For instance, a system is unstable when any pole is located to the right of the imaginary axis. For discrete systems, we can analyze the system behaviors from different pole locations in the z-plane. The characteristics in the z-plane can be related to those in the s-plane by the following expression.

(6)Control Tutorials for MATLAB and Simulink (36)

  • T = sampling time (sec/sample)
  • s = location in the s-plane
  • z = location in the z-plane

The figure below shows the mapping of lines of constant damping ratio (Control Tutorials for MATLAB and Simulink (37)) and natural frequency (Control Tutorials for MATLAB and Simulink (38)) from the s-plane to the z-plane using the expression shown above.

Control Tutorials for MATLAB and Simulink (39)

You may have noticed that in the z-plane the stability boundary is no longer the imaginary axis, but rather is the circle of radius one centered at the origin, |z| = 1, referred to as the unit circle. A discrete system is stable when all poles are located inside the unit circle and unstable when any pole is located outside the circle.

For analyzing the transient response from pole locations in the z-plane, the following three equations used in continuous system designs are still applicable.

(7)Control Tutorials for MATLAB and Simulink (40)

(8)Control Tutorials for MATLAB and Simulink (41)

(9)Control Tutorials for MATLAB and Simulink (42)

where,

  • Control Tutorials for MATLAB and Simulink (43) = damping ratio
  • Control Tutorials for MATLAB and Simulink (44) = natural frequency (rad/sec)
  • Control Tutorials for MATLAB and Simulink (45) = 1% settling time
  • Control Tutorials for MATLAB and Simulink (46) = 10-90% rise time
  • Control Tutorials for MATLAB and Simulink (47) = maximum overshoot

Important: The natural frequency (Control Tutorials for MATLAB and Simulink (48)) in the z-plane has units of rad/sample, but when you use the equations shown above, Control Tutorials for MATLAB and Simulink (49) must be represented in units of rad/sec.

Suppose we have the following discrete transfer function

(10)Control Tutorials for MATLAB and Simulink (50)

Create a new m-file and enter the following commands. Running this m-file in the command window gives you the following plot with the lines of constant damping ratio and natural frequency.

numDz = 1;denDz = [1 -0.3 0.5];sys = tf(numDz,denDz,-1); % the -1 indicates that the sample time is undeterminedpzmap(sys)axis([-1 1 -1 1])zgrid

Control Tutorials for MATLAB and Simulink (51)

From this plot, we see the poles are located approximately at a natural frequency of Control Tutorials for MATLAB and Simulink (52) (rad/sample) and a damping ratio of 0.25. Assuming that we have a sampling time of 1/20 sec (which leads to Control Tutorials for MATLAB and Simulink (53) = 28.2 rad/sec) and using the three equations shown above, we can determine that this system should have a rise time of 0.06 sec, a settling time of 0.65 sec, and a maximum percent overshoot of 45% (0.45 times more than the steady-state value). Let's obtain the step response and see if these are correct. Add the following commands to the above m-file and rerun it in the command window. You should obtain the following step response.

sys = tf(numDz,denDz,1/20);step(sys,2.5);

Control Tutorials for MATLAB and Simulink (54)

As we can see from the plot, the rise time, settling time and overshoot came out to be what we expected. This demonstrates how we can use the locations of poles and the above three equations to analyze the transient response of a discrete system.

Discrete Root Locus

The root-locus is the locus of points where roots of the characteristic equation can be found as a single parameter is varied from zero to infinity. The characteristic equation of our unity-feedback system with simple proportional gain, Control Tutorials for MATLAB and Simulink (55), is:

(11)Control Tutorials for MATLAB and Simulink (56)

where Control Tutorials for MATLAB and Simulink (57) is the digital controller and Control Tutorials for MATLAB and Simulink (58) is the plant transfer function in z-domain (obtained by implementing a zero-order hold).

The mechanics of drawing the root-loci are exactly the same in the z-plane as in the s-plane. Recall from the continuous Root-Locus Tutorial, we used the MATLAB function sgrid to find the root-locus region that gives an acceptable gain (Control Tutorials for MATLAB and Simulink (59)). For the discrete root-locus analysis, we will use the function zgrid, which has the same function as sgrid. The syntax zgrid(zeta, Wn) draws lines of constant damping ratio (zeta) and natural frequency (Wn).

Suppose we have the following discrete transfer function

(12)Control Tutorials for MATLAB and Simulink (60)

and the requirements are a damping ratio greater than 0.6 and a natural frequency greater than 0.4 rad/sample (these can be found from the design requirements, the sampling period (sec/sample), and the three equations shown in the previous section). The following commands draw the root-locus with the lines of constant damping ratio and natural frequency. Create a new m-file and enter the following commands. Running this m-file should generate the following root-locus plot.

numDz = [1 -0.3];denDz = [1 -1.6 0.7];sys = tf(numDz,denDz,-1);rlocus(sys)axis([-1 1 -1 1])zeta = 0.4;Wn = 0.3;zgrid(zeta,Wn)

Control Tutorials for MATLAB and Simulink (61)

From this plot, we can see that the system is stable for some values of Control Tutorials for MATLAB and Simulink (62) since there are portions of the root locus where both branches are located inside the unit circle. Also, we can observe two dotted lines representing the constant damping ratio and natural frequency. The natural frequency is greater than 0.3 outside the constant-Wn line, and the damping ratio is greater than 0.4 inside the constant-zeta line. In this example, portions of the generated root-locus are within in the desired region. Therefore, a gain (Control Tutorials for MATLAB and Simulink (63)) chosen to place the two closed-loop poles on the loci within the desired region should provide us a response that satisfies the given design requirements.


Published with MATLAB® 9.2

Control Tutorials for MATLAB and Simulink (2024)

References

Top Articles
Latest Posts
Article information

Author: Nathanial Hackett

Last Updated:

Views: 6063

Rating: 4.1 / 5 (52 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Nathanial Hackett

Birthday: 1997-10-09

Address: Apt. 935 264 Abshire Canyon, South Nerissachester, NM 01800

Phone: +9752624861224

Job: Forward Technology Assistant

Hobby: Listening to music, Shopping, Vacation, Baton twirling, Flower arranging, Blacksmithing, Do it yourself

Introduction: My name is Nathanial Hackett, I am a lovely, curious, smiling, lively, thoughtful, courageous, lively person who loves writing and wants to share my knowledge and understanding with you.