Control Tutorials for MATLAB and Simulink (2025)

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 (2025)

FAQs

How do I find answers in MATLAB? ›

To view all of your solutions, go to a Problem page and click View my solutions. You can view your solutions in a list or in the Solution Map. If using the list view, you can review the display by selecting a Sort by option.

Is MATLAB Simulink hard to learn? ›

MATLAB is designed for the way you think and the work you do, so learning is accessible whether you are a novice or an expert. The Help Center is always available to guide you with robust documentation, community answers, and how-to videos. Additionally, online interactive training is a great way to get started.

How much time is required to learn MATLAB? ›

If you're a novice programmer, you can expect it to take a little longer than if you were a more seasoned programmer. Someone who can afford to devote all their time to MATLAB can finish learning the language in two weeks. If you have a lot of other responsibilities, however, it will take you longer to complete.

Does anyone still use MATLAB? ›

As of May 2022, LinkedIn searches return about 7.6 million Python users and 4.1 million MATLAB users. People who do not work in engineering or science are often surprised to learn how widespread MATLAB is adopted, including: Millions of users in colleges and universities. Thousands of startups.

How do you get a long answer in MATLAB? ›

To format the way numbers display, do one of the following:
  1. On the Home tab, in the Environment section, click Preferences. Select MATLAB > Command Window, and then choose a Numeric format option.
  2. Use the format function, for example: format short format short e format long.

How do I find Solver in MATLAB? ›

Description. S = solve( eqn , var ) solves the equation eqn for the variable var . If you do not specify var , the symvar function determines the variable to solve for. For example, solve(x + 1 == 2, x) solves the equation x + 1 = 2 for x.

Is MATLAB harder than Python? ›

The Difference in Technical Computing:

They are both used for the same type of work, such as numerical analysis, data visualization, and scientific computation. When it comes to syntax and readability, Python is often easier to read and understand than MATLAB.

What is the salary of MATLAB Simulink? ›

Average Annual Salary by Experience

Matlab Developer salary in India with less than 1 year of experience to 5 years ranges from ₹ 2.0 Lakhs to ₹ 9.4 Lakhs with an average annual salary of ₹ 5.6 Lakhs based on 342 latest salaries.

Is MATLAB enough for a job? ›

Conclusion. The industry has some familiar buzz that learning MATLAB will not be a good opportunity for a better career. But this is not fully true. Yes, it is an acceptable reason that salary or company structure will never be able to touch available popular jobs on other programming technologies.

Is MATLAB in high demand? ›

Matlab careers are actually on the rise today. It's a very popular programming language. It can be used by a developer, engineer, programmer, scientist, etc. to collect and sort out data, and develop apps, software, and sites.

Can I learn MATLAB in 1 month? ›

If you want to become an expert in Matlab then you need to mention which part of madlab you want to learn and want expertise. If I generalize my answer highly, It may take at least 3 months to learn matlab and may take maximum 3 years to become an expert.

Is MATLAB becoming obsolete? ›

MATLAB is almost dropping off from the top 20 for the first time in more than a decade. In April 2021, it was at the 19th position, and now, a year after that, it has dropped further. MATLAB finds its usage in the numerical analysis domain and is often combined with Simulink.

Does NASA use MATLAB? ›

In 2022, the team at NASA published a report titled “Rapid Flight Control Law Deployment and Testing Framework for Subscale VTOL Aircraft”, describing flight control law development and deployment using UAV Toolbox with MATLAB.

Is MATLAB losing to Python? ›

Is MATLAB better than Python? 🔗 Almost always, no. For the vast majority of readers, Python is the better choice because it's free to use and get started with, the libraries make it a more versatile language, and it's just a better language for data science, machine learning, software development, and programming.

Is MATLAB easy to learn? Is guidance required ...Quorahttps://www.quora.com ›

It's more fun to self-learn MATLAB from available books, videos etc.The training institutes are structured in a rigid form, on contrary, any programming lan...
MATLAB, represents Matrix Laboratoty, is an elite language which absorbs calculation, perception and programming in a solitary situation. The MATLAB instruction...
Adam is only partially right. Many, if not most, mathematicians will never touch it. If there is a computer tool used at all, it's going to be something lik...

How to check results in MATLAB? ›

View Results in Command Window

The Summary Report link provides access to the Model Advisor Command-Line Summary report. You can review additional results in the Command Window by calling the DisplayResults parameter when you run the Model Advisor.

How do you find the step response in MATLAB? ›

[ y , tOut ] = step( sys , tFinal ) computes the step response from t = 0 to the end time t = tFinal . [ y , tOut ] = step( sys , t ) returns the step response of a dynamic system model sys at the times specified in the vector t .

How do I find something in MATLAB code? ›

Search Using Find Dialog Box

The Find dialog box opens. The search begins at the current cursor position. MATLAB finds the text you specified and highlights it. MATLAB beeps when a search for Find Next reaches the end of the Command Window, or when a search for Find Previous reaches the top of the Command Window.

What is the ANS command in MATLAB? ›

ans is the variable created when an output is returned without a specified output argument. MATLAB® creates the ans variable and stores the output there. Changing or using the value of ans in a script or function is not recommended, as the value can change frequently. ans is specific to the current workspace.

References

Top Articles
Latest Posts
Recommended Articles
Article information

Author: Stevie Stamm

Last Updated:

Views: 5425

Rating: 5 / 5 (60 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Stevie Stamm

Birthday: 1996-06-22

Address: Apt. 419 4200 Sipes Estate, East Delmerview, WY 05617

Phone: +342332224300

Job: Future Advertising Analyst

Hobby: Leather crafting, Puzzles, Leather crafting, scrapbook, Urban exploration, Cabaret, Skateboarding

Introduction: My name is Stevie Stamm, I am a colorful, sparkling, splendid, vast, open, hilarious, tender person who loves writing and wants to share my knowledge and understanding with you.