0% found this document useful (0 votes)
4 views107 pages

Tutorial 01

Uploaded by

10223035
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views107 pages

Tutorial 01

Uploaded by

10223035
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CHAPTER 1

Introduction to
Simulink®
Simulink is a software package for modeling, simulating, and analyzing
dynamic systems. It supports linear and nonlinear systems, modeled in
continuous time, sampled time, or a hybrid of the two.
This chapter shows the basics of simulation with Simulink. It contains
five examples, and they aim to make you familiar with the Simulink
environment and how to do a simulation there. You can start from the next
chapter if you are familiar with the Simulink environment.

Power Electronic Circuits and Simulation


Power electronics is the application of solid-state electronics to the control
and conversion of electric power with high efficiency. Power electronic
converters can be divided into four groups: AC-DC converters (rectifiers),
DC-AC converters (inverters), DC-DC converters, and AC-AC converters.
Computer simulation is a tool to virtually investigate the behavior
of the system under study. Computer simulation of power electronic
converters is an easy, safe, and cheap way to observe the behavior of the
converter (i.e., voltage of nodes and current of branches) and ensure that
the converter does what we exactly need. Computer simulation permits

© Farzin Asadi 2022 1


F. Asadi, Simulation of Power Electronics Circuits with MATLAB®/Simulink®,
[Link]
CHAPTER 1 INTRODUCTION TO SIMULINK®

us to test our ideas before we go wasting all that time building it with
a breadboard or printed circuit board (PCB), just to find out it doesn’t
really work.
MATLAB®/Simulink® is one of the most powerful software for
simulation of power electronic circuits. MATLAB/Simulink simulation
results are accurate and quite close to laboratory measurements. When
you want to simulate a power electronic converter with MATLAB/
Simulink, you can use all of the ready-to-use blocks available in the
Simulink environment. This is a very interesting property. For instance,
assume that you want to simulate a DC-DC converter, which is controlled
with a Fuzzy Logic controller. In this case you can simply use the ready-
to-use Fuzzy Logic Toolbox® blocks. If you try to do the same simulation
in other software, you need to consume a considerable amount of time to
model the Fuzzy Logic controller from the ground up.

Example 1: Step Response of a Transfer


Function Model
In this example a transfer function is stimulated with a unit step signal,
and its response is observed.
Enter the Simulink environment with the aid of the simulink command
(see Figures 1-1 and 1-2).

Figure 1-1. simulink command

2
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-2. Simulink Start Page

The Simulink Start Page window appears. Click the Blank Model.
Now the Simulink environment with a blank project is ready
(Figure 1-3).

3
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-3. Simulink environment

Click the Library Browser button (Figure 1-4).

Figure 1-4. Library Browser button

4
CHAPTER 1 INTRODUCTION TO SIMULINK®

After clicking the Library Browser icon, the Simulink Library Browser
window (see Figure 1-5) will be opened, and you can add required
components to the model.

Figure 1-5. Simulink Library Browser

5
CHAPTER 1 INTRODUCTION TO SIMULINK®

Locating Blocks
Simulink Library Browser contains many blocks, and it is impossible to
memorize each block location. The Enter search term box is useful to find
a block when you forgot its location. For instance, assume that you need a
PID controller block, but you don’t know where it is.
In this case just type “pid” in the Enter search term box (see Figure 1-6)
and press the Enter key of your keyboard. After pressing the Enter key,
Simulink will list blocks related to the entered term on the right side of
the window.

Figure 1-6. Searching for blocks related to “pid”

6
CHAPTER 1 INTRODUCTION TO SIMULINK®

The Transfer Fcn block can be found in the Continuous section of


Simulink Library Browser (see Figure 1-7). Click the Transfer Fcn block to
select it. Then drag and drop it to the model (see Figure 1-8).

Figure 1-7. Transfer Fcn block

7
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-8. Addition of the Transfer Fcn block to the Simulink model

Add a Step block (see Figure 1-9) to the model (see Figure 1-10).

8
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-9. Step block

Figure 1-10. Addition of the Step block to the Simulink model

9
CHAPTER 1 INTRODUCTION TO SIMULINK®

Add a Scope block (see Figure 1-11) to the model (see Figure 1-12).

Figure 1-11. Scope block

10
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-12. Addition of the Scope block to the Simulink model

When you bring the mouse pointer close to the block terminals, it will be
changed to crosshair and permits you to start connecting them. After seeing
the crosshair, hold down the left button on the mouse and drag the connection
toward the destination terminal and release the button on the destination
terminal. Use this method to connect the blocks together (Figure 1-13).

Figure 1-13. Connecting the blocks together

Double-click the blocks and configure their settings as shown in


Figures 1-14 and 1-15. Settings of Figure 1-14 generate a pulse, which
100
jumps from 0 to 1 at t=0. Settings of Figure 1-15 simulate the 2
s  8 s  100
transfer function.

11
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-14. Settings of the Step block

12
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-15. Settings of the Transfer Fcn block

Assume that you want to simulate the behavior of the system for time
length of 2 s. Enter 2 in the Stop Time box and click the Run button (or
press Ctrl+T) to simulate the behavior of the system (see Figure 1-16).
Sometimes you need to do the simulation with a specific solver. In these
cases, use Model Settings (see Figure 1-17) to select the desired solver.
After clicking the Model Settings icon (or pressing Ctrl+E), the window
shown in Figure 1-18 appears, and you can select the desired type of solver.
13
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-16. Stop Time box and Run button

Figure 1-17. MODELING tab and Model Settings button

Figure 1-18. Solver section of the Configuration Parameters window

14
CHAPTER 1 INTRODUCTION TO SIMULINK®

The simulation result is shown in Figure 1-19. It can be copied into the
clipboard by pressing Ctrl+C. You can paste the copied waveform in other
software by pressing Ctrl+V. This is very useful when you want to prepare a
presentation or report.

Figure 1-19. Simulation result

You can use Cursor Measurement (see Figure 1-20) to read the
coordinates of different points on the graph. After clicking Cursor
Measurement, two vertical lines will be added to the graph (see
Figure 1-21). You can move them to read the coordinates of different points
on the graph.

15
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-20. Cursor Measurement icon

16
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-21. Two cursors are added to the Scope block

In this example you learned how to do a simple simulation in


the Simulink environment. In the next example, we will learn how to
tune a PID controller in MATLAB. PID controllers can be tuned in the
Simulink environment as well. Tuning of PID controllers in the Simulink
environment is studied in Example 4.

17
CHAPTER 1 INTRODUCTION TO SIMULINK®

Example 2: PID Controller Design


in the MATLAB Environment
PID controllers are the most widely used type of controllers used in
industry. MATLAB can be used to tune the PID controllers. In this example
we want to design a PID controller for the transfer function of the previous
example.
The command shown in Figure 1-22 enters the transfer function into
the MATLAB environment.

100
Figure 1-22. Entering the H  s   into MATLAB
s 2  8s  100

The pidTuner command (see Figure 1-23) helps you tune the PID
controller. After running the pidTuner command, the window shown in
Figure 1-24 appears.

Figure 1-23. pidTuner command

18
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-24. PID Tuner window

Move the sliders until you obtain a good response. By default, the PID
Tuner does the tuning in the time domain (see Figure 1-25). You can do it
in the frequency domain, as well (see Figure 1-26).

Figure 1-25. Tuning is done in the time domain

Figure 1-26. Tuning is done in the frequency domain

19
CHAPTER 1 INTRODUCTION TO SIMULINK®

Sometimes the output signal of a plant is quite good; however, the


control signal (which is applied to the input of a plant) is too big. So it is a
good idea to activate the Controller effort window (see Figure 1-27) to see
the control signal as well (see Figure 1-28). This allows you to see whether
or not the control signal is in the allowed range.

Figure 1-27. Activation of the Controller effort graph

20
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-28. The Controller effort window is activated

After designing a suitable controller, you can export the designed


controller to the MATLAB environment by clicking the Export button
(see Figure 1-29). After clicking the Export button, the window shown in
Figure 1-30 appears. Enter the desired name in the Export PID controller
box and click the OK button.

Figure 1-29. Export button

21
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-30. Export Linear System window

In this example we designed a PID controller for the given plant. In the
next example, we will simulate the behavior of a closed-loop system in the
Simulink environment.

Example 3: Feedback Control System


A feedback control system uses one or more than one sensor to measure
the output of the system, compare the measured output with a reference
signal, and give a suitable input to the system under control based on
the difference between the reference signal and output of the system.
MATLAB/Simulink has many tools for analysis and design of feedback
control systems. In this example we will simulate a feedback control
system in Simulink.
Consider the feedback control system shown in Figure 1-31.

100
s  8 s  100
2

22
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-31. Simulink model of Example 3


100
The plant transfer function is . This simulation uses the
s  8 s  100
2

Sum (see Figure 1-32) and PID Controller (see Figure 1-33) blocks. Settings
of the Sum and PID Controller blocks are shown in Figures 1-34 and 1-35,
respectively.

Figure 1-32. Sum block

23
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-33. PID Controller block

24
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-34. Settings of the Sum block

25
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-35. Settings of the PID Controller block

26
CHAPTER 1 INTRODUCTION TO SIMULINK®

Run the simulation. The result shown in Figure 1-36 is obtained.

Figure 1-36. Simulation result

In Example 2 you learned how to design a PID controller in the


MATLAB environment. In the next example, we will learn how to design
the PID controller in the Simulink environment.

27
CHAPTER 1 INTRODUCTION TO SIMULINK®

Example 4: PID Controller Design


in the Simulink Environment
In Example 2 you learned how to tune a PID controller in the MATLAB
environment. You can do the tuning in the Simulink environment as well.
In this example we will tune a PID controller in the Simulink environment.
Consider the Simulink model shown in Figure 1-37.

Figure 1-37. Simulink model of Example 4


100
The plant transfer function is . The PID Controller block
s  8 s  100
2

has the default parameter values. Double-click the PID Controller block
and click the Tune button (see Figure 1-38). After clicking the Tune button,
the window shown in Figure 1-39 appears and permits you to tune the
controller.

28
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-38. PID Controller block settings

29
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-39. Tuned response vs. current response

Sometimes the output signal of a plant is quite good; however, the


control signal (which is applied to the input of a plant) is too big. So it is a
good idea to activate the Controller effort window (see Figure 1-40) to see
the control signal as well (see Figure 1-41). This allows you to see whether
or not the control signal is in the allowed range. After tuning the controller,
click the Update Block button to apply the changes to the block.

30
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-40. Activation of the Controller effort graph

31
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-41. The Controller effort window is activated

Up to this point, the Scope blocks showed a graph of one signal only.
Sometimes you need to view two or more signals simultaneously. We will
learn how to do this in the next example.

Example 5: Plot Two or More Waveforms


on One Scope Block
In this example we’ll review a couple ways to view two or more signals
simultaneously. Viewing two or more signals simultaneously permits you
to clearly see the relationship between them. For instance, you can view
the input and output simultaneously on a Scope block. This helps you
observe the effect of the input on the output.

32
CHAPTER 1 INTRODUCTION TO SIMULINK®

Option 1: Increasing the Number of Inputs


on the Scope Block
Consider the model shown in Figure 1-42. The plant transfer function is
100
. Settings of the PID Controller block are shown in Figure 1-43.
s  8 s  100
2

Figure 1-42. Simulink model of Example 5

Figure 1-43. PID Controller block settings


33
CHAPTER 1 INTRODUCTION TO SIMULINK®

Click the connection between the scope and output of the system (see
Figure 1-44) and press the Delete key to remove it (see Figure 1-45).

Figure 1-44. Selection of the wire from output to scope

Figure 1-45. Removing the wire from output to scope

Double-click the Scope block and select 2 for Number of Input


Ports (see Figure 1-46). The Scope block changes to what is shown in
Figure 1-47.

34
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-46. Determining the number of inputs

Figure 1-47. The Scope block has two inputs

Connect the inputs of the Scope block to the desired nodes of the
system (Figure 1-48).

35
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-48. Connecting the scope inputs to the model

Run the simulation. The result shown in Figure 1-49 is obtained. One of
the signals has round markers on it. You can remove these round markers
by clicking the Style icon (see Figure 1-50). After clicking the Style icon, the
window shown in Figure 1-51 appears. Convert the Marker box to none (see
Figure 1-52). Now the waveform has no round markers on it (see Figure 1-53).

Figure 1-49. Simulation result

36
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-50. Style icon

Figure 1-51. Scope window. The round marker is selected

37
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-52. Scope window. The Marker box is changed to none

38
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-53. Simulation result

Option 2: Using the Multiplexer (Mux) Block


There is another way to see two or more signals simultaneously: using
the multiplexer (Mux) block (see Figure 1-54). If you double-click the
Mux block, the window shown in Figure 1-55 appears and permits you to
determine the desired number of inputs for the Mux block.

39
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-54. Multiplexer block

40
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-55. Settings of the multiplexer block

The block diagram shown in Figure 1-56 shows the output of the
system and control input simultaneously (see Figure 1-57).

Figure 1-56. Showing two signals on the scope with the


multiplexer block

41
CHAPTER 1 INTRODUCTION TO SIMULINK®

Figure 1-57. Simulation result

Summary
In this chapter you learned the basics of simulation with Simulink. You learned
how to observe the step response of a system, how to tune a PID controller
with MATLAB and Simulink, how to simulate a closed-loop feedback control
system, and how to observe two or more signals simultaneously.
Power electronic converters are dynamic systems. In the next
chapter, we will learn how to simulate a dynamic system in the Simulink
environment.

42
CHAPTER 2

Simulation of
Dynamic Systems
in Simulink®
Basics of Simulink were studied in the previous chapter. In this chapter
we will focus on the modeling of dynamic equations in the Simulink
environment. Dynamic equations can be divided into two categories:
continuous time dynamic equations (differential equations) and discrete
time dynamic equations (difference equations). Modeling of both of these
equations is studied in this chapter.
Differential equations can be divided into two groups: time domain
equations and state space equations. In order to simulate a differential
equation in the Simulink environment, you need to convert it into
state space.
In this chapter we will learn how to convert a time domain differential
equation into a state space equation, how to decrease the number of
Integrator blocks used in the Simulink model, how to simulate a state
space equation with the aid of State-Space and MATLAB Function blocks,
how to transfer the simulation result from Simulink to the MATLAB
environment, how to simulate a DC-DC boost converter, and how to
simulate difference equations.

© Farzin Asadi 2022 43


F. Asadi, Simulation of Power Electronics Circuits with MATLAB®/Simulink®,
[Link]
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Example 1: Simulation of
Differential Equations
In this example we want to simulate the following system:

 
y  5 y  10 y  7 sin  3t   , y  0   1, y  0   4
 (2.1)
 3

Let’s define two new variables and convert the given equation into the
state space system:

dy
x1 y, x2 y (2.2)
dt

The state space representation of the system is

 
x1  x2 , x2  10 x1  5 x2  7 sin  3t   , x0  14 (2.3)
 3

where x0 indicates the initial condition of the system. This state space
representation is suitable for drawing the Simulink model. Add two
Integrator blocks (see Figure 2-1) to the Simulink model (see Figure 2-2).

44
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-1. Integrator block

45
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-2. Addition of two Integrator blocks to the model

The relationship between the integrator input and output is shown in


Figure 2-3.

Figure 2-3. Relationship between input and output of


Integrator blocks

According to the obtained state space model, x1 x2 . Implementation


of this equation is shown in Figure 2-4.

Figure 2-4. Implementation of x1 x2

We need Gain (see Figure 2-5), Sum (see Figure 2-6), and Sine Wave
 
(see Figure 2-7) blocks to implement x2  10 x1  5 x2  7 sin  3t   . The
 3
implementation of this equation is shown in Figure 2-8. Note that Gain
blocks are rotated by clicking them and pressing Ctrl+R.

46
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-5. Gain block

47
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-6. Sum block

48
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-7. Sine Wave block

49
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®


Figure 2-8. Implementation of x1 x2 and x2  10x1  5x2  7sin  3t  
 3
equations

Settings of blocks in Figure 2-8 are shown in Figures 2-9 to 2-14.

50
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-9. Settings of the Sine Wave block

51
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-10. Settings of the Sum block

52
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-11. Settings of the Integrator 1 block

53
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-12. Settings of the Integrator 2 block

54
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-13. Settings of the G1 block

Figure 2-14. Settings of the G2 block

55
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Add two Scope blocks to the Simulink model (Figure 2-15).

Figure 2-15. Addition of two Scope blocks to see the x1 and x2

We want to study the system behavior for 1 s. Enter 1 in the Stop


Time box and run the simulation (see Figure 2-16). The result is shown
in Figures 2-17 and 2-18. According to the obtained result, the system is
unstable.

Figure 2-16. Entering 1 in the Stop Time box

56
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-17. Simulation result (x1)

57
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-18. Simulation result (x2)

In this example we used two Integrator blocks to simulate a second-


order system. In the next example, we will learn how to decrease the
number of Integrator blocks of our Simulink model to one.

58
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Example 2: Simulation of Differential


Equations with Only One Integrator Block
In this example, we want to implement the state space equation of
Example 1 with only one Integrator block. The state space equation of
Example 1 is rewritten in the following:

 
x1  x2 , x2  10 x1  5 x2  7 sin  3t   , x0  [14] (2.3)
 3

This state space equation has the following form

x  Ax  u , x0  [14] (2.4)

   
where x = [x1;x2 ], A = [0 1;10 − 5 ], and u  0; 7 sin  3t    . The model
  3 
shown in Figure 2-19 implements the state space equation with only one
Integrator block. Settings of the blocks are shown in Figures 2-20 and 2-21.
This model used a Constant block (see Figure 2-22) to implement the zero
   
of vector u  0 7 sin  3t    .
  3 

Figure 2-19. Simulink model of Example 2

59
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-20. Settings of the Integrator block

60
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-21. Settings of the G1 block

61
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-22. Constant block

Run the simulation. The result shown in Figure 2-23 is obtained. Both
of the signals are shown on one scope. The model in Figure 2-24 shows
how to separate the signals and send each signal to a separate scope. This
model used a demultiplexer (Demux) block (see Figure 2-25) to separate
the signals.

62
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-23. Simulation result

Figure 2-24. The simulation result is shown on two Scope blocks

63
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-25. Demultiplexer block

In the next example, we will learn how to simulate a nonlinear system


with the aid of the MATLAB Function block.

64
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Example 3: Simulation of Differential


Equations with the MATLAB Function Block
In this example we want to simulate the following equation:

 
y   
t  sin  t  y  t 2 y  7 sin  3t   , y  0   1, y  0   4
 3
(2.5)

Let’s convert the equation to state space. The new variables x1 and x2
are defined as

dy
x1 y, x2 y (2.6)
dt

So the state space model of the given system is

 
x1  x2 , x2  t 2 x1   
t  sin  t  x2  7 sin  3t  
 3
(2.7)

This model can be written as

x  Ax  u (2.8)

   
where x = [x1 x2 ], A  01; t 2 
  
t  sin  t   , and u  0; 7 sin  3t    .
   3 
The obtained state space equation is implemented with the block diagram
shown in Figure 2-26. This model used MATLAB Function and Clock
blocks (Figures 2-27 and 2-28).

65
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-26. Simulink model of Example 3

Figure 2-27. MATLAB Function block


66
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-28. Clock block

Double-click the MATLAB Function block and enter the code


shown in Figure 2-29. u(1) indicates variable x1, u(2) indicates variable
x2, and u(3) indicates variable t. So Figure 2-29 is the translation of
   
 x2 ; t x1 

2
 
t  sin  t  x2  7 sin  3t    into MATLAB language.
 3 

67
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-29. Content of the MATLAB Function block

Settings of the Integrator block are shown in Figure 2-30.

Figure 2-30. Settings of the Integrator block

68
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Run the simulation. The result shown in Figures 2-31 and 2-32 is
obtained.

Figure 2-31. Simulation result (x1)

69
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-32. Simulation result (x2)

The given system in this example can be simulated with the aid of
the following block diagram as well. This Simulink model used more
blocks in comparison to the model shown in Figure 2-26. If you run the
Simulink model shown in Figure 2-33, you will obtain the results shown in
Figures 2-31 and 2-32.

70
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-33. Simulink model of Example 3 with discrete blocks

The model shown in Figure 2-33 used Sqrt (see Figure 2-34) and Math
Function (see Figure 2-35) blocks.

71
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-34. Sqrt block

72
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-35. Math Function block

73
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Settings of blocks used in Figure 2-33 are shown in Figures 2-36 to 2-40.

Figure 2-36. Settings of the Sine Wave1 block

74
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-37. Settings of the Sine Wave2 block

75
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-38. Settings of the Integrator1 block

76
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-39. Settings of the Integrator2 block

77
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-40. Settings of the Math Function block

In the next example, we will learn how to copy and take out a block
from our Simulink model.

Example 4: Copying and Taking Out a Block


from the Model
In this example we will show how to copy and take out a block from its
location easily. Consider the model shown in Figure 2-41. Assume that
you need one more scope. One way is to click the Library Browser icon
and drag a new Scope block to the model. However, there is a simpler way.
You can hold down the Ctrl key, click the Scope block, and drag the block
outward. Once you release the mouse button, one copy of the block will be
generated for you (see Figure 2-42).

78
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-41. Select scope x2 by clicking it

Figure 2-42. Making a copy of a Scope block


79
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Assume that we want to take out the Sqrt block of Figure 2-43 and
replace it with something else. In order to do this, hold down the Shift key,
click the Sqrt block, and drag the block. This separates the block from the
model without affecting the connections (see Figure 2-44). Now you can
add the new block to the model. Just bring the new block terminals close
to the connection shown with the red dotted line. Simulink makes the
connection for you.

Figure 2-43. Select the Sqrt block by clicking it

80
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-44. Taking out the Sqrt block

In the next example, we will learn how to use the State-Space block to
simulate linear state space models.

Example 5: State-Space Block


In this example we will see how to simulate a linear state space system.
Assume that you want to simulate the following state space system

x  Ax  Bu

y  Cx  Du (2.9)

81
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

where A = [1 2; − 1 3 ], B = [1 1;5 3 ], C = [1 1;6 − 3 ], and D = [0 0;0 0 ].


The initial condition of the system is x0 = [1;3 ], and input is u = [R(t) 0 ],
where R(t) indicates the unit ramp signal. The State-Space block (see
Figure 2-45) can be used for this problem. Note that if you want to simulate
a nonlinear state space equation, you need to use the Integrator block
(see Example 3). The State-Space block cannot be used for nonlinear state
space models.

Figure 2-45. State-Space block

82
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

The Simulink model is shown in Figure 2-46. This diagram used the
Ramp block shown in Figure 2-47 to stimulate the system with a unit ramp
signal. Settings of the State-Space block are shown in Figure 2-48.

Figure 2-46. Simulink model of Example 5

Figure 2-47. Ramp block

83
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-48. Settings of the State-Space block

The simulation result is shown in Figure 2-49.

84
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-49. Simulation result

In the next example, we will learn how to transfer the simulation


results from the Simulink environment to MATLAB Workspace.

Example 6: To Workspace Block


You can use the To Workspace block (see Figure 2-50) to transfer the signal
from the Simulink environment to MATLAB Workspace. Let’s send the
output of the previous example to Workspace. Add a To Workspace block
to the Simulink model of the previous example (see Figure 2-51).

85
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-50. To Workspace block

86
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-51. Addition of the To Workspace block to the


Simulink model

Run the simulation. After running the simulation, a new variable


named “out” will be added to Workspace (Figure 2-52).

Figure 2-52. Variable “out” is added to Workspace

Enter the commands shown in Figure 2-53. t, y1, and y2 indicate time,
first output, and second output, respectively. The result of this code is
shown in Figures 2-54 and 2-55. This result is the same as the result shown
in Figure 2-49.

Figure 2-53. Reading the data imported from Simulink and drawing
its graph

87
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-54. Output of code in Figure 2-53 (1)

88
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-55. Output of code in Figure 2-53 (2)

In the next example, we will learn how to simulate a boost converter


with the aid of its dynamic equation. In Chapter 5 we will learn how to
simulate a DC-DC converter with the aid of Simscape blocks (i.e., blocks
like voltage sources, inductors, diodes, MOSFETs, etc.).

89
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Example 7: Simulation of the Dynamic


Equation of a Boost Converter
In this example we will simulate the dynamic equation of a boost
converter. Consider the boost converter shown in Figure 2-56.

Figure 2-56. Schematic of a boost converter

The equivalent circuit of the boost converter for closed MOSFET is


shown in Figure 2-57. The MOSFET is assumed to be ideal, that is, the
drain-source resistance is ignored, for the sake of simplicity.

Figure 2-57. Equivalent circuit of the boost converter for


closed MOSFET

90
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

The dynamic equation of this circuit is

d V d v
iL  IN , vC   C (2.10)
dt L dt R.C

The equivalent circuit of the boost converter for open MOSFET is


shown in Figure 2-58. The diode is assumed to be ideal, that is, the forward
voltage drop is ignored, for the sake of simplicity.

Figure 2-58. Equivalent circuit of the boost converter for


open MOSFET

The dynamic equation of this circuit is

d V v d i v
iL  IN  C , vC  L  C (2.11)
dt L L dt C R.C

The obtained two sets of equations can be written as

d v 1 d i v
iL  1  u  C  VIN , vC  1  u  L  C (2.12)
dt L L dt C R.C

where u indicates the status of the MOSFET. When the MOSFET is


closed, u = 1; and when the MOSFET is opened, u = 0. The model shown in
Figure 2-59 implements these equations. This model used Pulse Generator
(see Figure 2-60) and Switch (see Figure 2-61) blocks. Note that values of
components are defined in MATLAB Workspace (see Figure 2-62).
91
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-59. Implementation of equation (2.12)

92
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-60. Pulse Generator block

93
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-61. Switch block

Figure 2-62. Values of components are defined in Workspace

94
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Settings of the blocks are shown in Figures 2-63 and 2-64.

Figure 2-63. Switch block settings

95
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-64. Pulse Generator block settings

Run the simulation. The results shown in Figures 2-65 and 2-66 are
obtained. According to the obtained results, the steady-state voltage of
the capacitor is about 30 V, and the steady-state inductor current has
minimum of 0.5457 A and maximum of 2.453 A. You need to zoom the
waveform in order to see these values.

96
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-65. Simulation result (inductor current)

97
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-66. Simulation result (capacitor voltage)

In the previous examples, we learned how to simulate continuous time


systems (i.e., systems described by a differential equation). In the next
example, we will learn how to simulate discrete time systems (i.e., systems
described by a difference equation).

98
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Example 8: Simulation of Discrete Time


Equations (I)
In this example we will simulate a discrete time equation. Consider
the 2 × x(n − 1) + 6 × x(n − 2) = x(n), x(−1) = 11, and x(−2) = 7. Let’s do
some hand calculations for the first three terms: x(0) = 2 × 11 + 6 × 7 = 64,
x(1) = 2 × 64 + 6 × 11 = 194, and x(2) = 2 × 194 + 6 × 64 = 772. The Simulink
model shown in Figure 2-67 implements the given equation. This model
used the Unit Delay block (see Figure 2-68). You can use the Delay block
(see Figure 2-69) as well. If you want to use the Delay block, you need to
double-click it and enter 1 in the Delay length box.

Figure 2-67. Simulink model of Example 8

99
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-68. Unit Delay block

100
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-69. Delay block

101
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Click the Model Settings button (Figure 2-70).

Figure 2-70. MODELING tab and Model Settings button

Configure the settings as shown in Figure 2-71.

Figure 2-71. The discrete solver must be selected for discrete time
simulations

102
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Run the simulation. The result is shown in Figure 2-72. The obtained
result is the same as hand calculations.

Figure 2-72. Simulation result

In this example we used a Delay block to simulate the given system. In


the next example, we will use the MATLAB Function block to simulate a
discrete time system.

103
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Example 9: Simulation of Discrete Time


Equations (II)
In this example we will simulate a discrete time equation. Consider
the y(n) − 3 × y(n − 1) = 4n − 1 , y(−1) = 0. This system can be written
as y(n) = 3 × y(n − 1) + 4n − 1 , y(−1) = 0. Let’s calculate the first
3 7
three terms: y(0) = 3 × 0 + 4−1 = 0.25, y 1   1   1.75, and
4 4
21 37
y  2   4   9.25 . The Simulink model shown in Figure 2-73
4 4
implements this equation. This model used a Zero-Order Hold block (see
Figure 2-74) to produce variable n from continuous variable t. The code
inside of the MATLAB Function block is shown in Figure 2-75.

Figure 2-73. Simulink model of Example 9

104
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Figure 2-74. Zero-Order Hold block

Figure 2-75. Content of the MATLAB Function block

105
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Run the simulation. The result shown in Figure 2-76 is obtained. The
obtained result is the same as the hand calculations.

Figure 2-76. Simulation result

106
CHAPTER 2 SIMULATION OF DYNAMIC SYSTEMS IN SIMULINK®

Summary
In this chapter you learned how to simulate a dynamic system in the
Simulink environment. To do so, the given time domain differential
equations must be converted into a state space model. The obtained state
space model can be implemented with the aid of Integrator blocks. You
learned how to decrease the number of integrators used in the Simulink
model, how to transfer the simulation results from Simulink into MATLAB,
and how to simulate discrete time models.
In the next chapter, we will learn how to simulate uncontrolled AC-DC
converters with the aid of Simscape™ blocks.

107

You might also like