Anda di halaman 1dari 14

School of Chemical and Biomedical Engineering

Division of Bioengineering

BG3801: Bioengineering Laboratory 3A


Year 3, Semester 1

Simulations of Physiological Control System


Location: N1.3-B2-25

Name:
_______________________________________
Matric Number:
_______________________________________
Group:
_______________________________________
Date of experiment:
_______________________________________

GRADE: _____________

Simulations of Physiological Control System using


SIMULINK
1. INTRODUCTION
Mathematical models that provide adequate representations of realistic dynamic
behavior of physiological control systems are generally too complicated to deal
with analytically. An approach to overcome this complex problem is to translate
the system block representation into a computer model and solve the problem
numerically. SIMULINK is a software tool that helps to simplify the task of
model simulation and analysis. The content used in this practical mainly comes
from reference book [1].
2. OBJECTIVES
In this practical you will learn to use MATLAB SIMULINK to simulate a
physiological control system (i.e. a simple linearized lung mechanics). You will
simulate a simple linearized lung mechanic for a normal subject and a subject
suffering from a chronic pulmonary disease. This will allow you to gain a better
understanding of how modeling can be used to further our understanding of
physiological control system.
3. BACKGROUND
3.1 SIMULINK
SIMULINK is an extension to MATLAB which uses icon-driven interface for the
construction of a block diagram representation of a system. A block diagram is a
graphical representation of a system which includes inputs and outputs, as shown
in Figure 1.1. Using the graphical interface provided by SIMULINK, the block
diagram can be constructed by connecting the necessary icons together, instead
of writing Matlab code. The icons represent possible inputs to the system, parts
of the systems, or outputs of the system. Please refer to BG3002 lecture notes for
more explanations about block diagrams.

Figure 1.1. A block diagram of a control system.

3.1 Linear Lung Mechanics

A simple model of a linearized description of lung mechanics is presented in


reference text [1], as shown in Figure 1.2. Figure 1.3 shows a simplified anatomy
of the lung for your reference. The following paragraph explaining the derivation
of the mathematical model is extracted from [1].

Figure 1.2. Linear Model of respiratory mechanics [1].


The airways are divided into two categories: the larger or central airways and the
smaller peripheral airways, with fluid mechanical resistances equal to RC and RP,
respectively. Air that enters the alveoli also produces an expansion of the chest
wall cavity by the same volume. This is represented by the connection of the lung
(CL) and chest-wall (CW) compliances in series. (Compliance represents storage
property.) However, a small fraction of the volume of air that enters the
respiratory system is shunted away from the alveoli as a result of the compliance
of the central airways and gas compressibility. This shunted volume is very small
under normal circumstances at regular breathing frequencies, but becomes
progressively more substantial if disease leads to peripheral airway obstruction
(i.e. increased RP) of a stiffening of the lungs or chest-wall (i.e. decreased CL or
CW). We account for this effect by placing a shunt compliance CS in parallel with
CL and CW. The pressures developed at the different points of this lung model are
Pao at the airway opening, Paw in the central airways, PA in the alveoli and Ppl in
the pleural space (between the lung parenchyma and chest wall). These pressures
are referenced to Po, the ambient pressure, which we can set to zero. Suppose the
volume flow-rate of air entering the respiratory system is Q. Then, the objective
here is to derive a mathematical relationship between Pao and Q.

Figure 1.3. Anatomy of the Lung.


From Kirchoffs Second Law (applied to the node Paw), if the flow delivered to
the alveoli is QA, then the flow shunted away from the alveoli must be Q - QA.
Applying Kirchoffs First Law to the closed circuit containing CS, RP, CL, and
CW, we have
1
1
1
Q A dt =
R p Q A +
+
Cs
C L CW

(Q Q )dt

(1)

Applying Kirchoffs First Law to the circuit containing RC and CS, we have
Pao = Rc Q +

1
Cs

(Q Q )dt

(2)

Differentiating Equation (1) and (2) with respect to time, and subsequently
reducing the two equations to one by eliminating QA, we obtain the equation
relating Pao to Q:
d 2 Pao
Rc
1 dPao
d 2Q 1
+
=
+
+
R
C
2
2
RP CT dt
dt
dt
C s R P CT

dQ
1

+
dt RP C S

1
1

Q
+
C L CW

(3)

where CT is defined by
1
1
1

+
+
CT =
C
C
C
L
W
s

2.

LABORATORY
Computer Lab. (N1.3)

3.

EQUIPMENT
Personal Computers (Window NT 4.0) and MATLAB software (Ver 6.1).

4.

EXERCISE 1
Given that the differential equation relating total airflow, Q, to the applied
pressure at the airway opening, Pao is

d 2 Pao
Rc
d 2Q 1
1 dPao
R
+
=
+
+
C
2
2
R P CT dt
dt
dt
C s R P CT

dQ
1

+
dt RP C S

1
1

Q
+
C L CW

where CT is defined by
1
1
1
+
+
CT =
C L CW C s

Assume normal mechanics, and the values of the various pulmonary parameters
are as follows: RC = 1 cmH 2 OsL-1 , R P = 0.5 cmH 2 OsL-1 , C L = 0.2 LcmH 2 O -1 ,
CW = 0.2 LcmH 2 O -1 , and C S = 0.005 LcmH 2 O -1 .

By using Laplace transform, show that the transfer function is given by


Q( s)
s 2 + 420 s
= 2
Pao ( s ) s + 620 s + 4000

5.

EXERCISE 2
In this section of the practical, we will be using SIMULINK to create a simple
linearized lung mechanics model based on the transfer function that you shown in
Exercise 1.
5.1 Creating SIMULINK model Using Transfer Function
1. Start Matlab.
2. Run SIMULINK from within Matlab command window (i.e. type simulink at
the Matlab prompt). The SIMULINK main block library will be displayed in a
new window.

3. In the SIMULINK window, click on the File menu and select new model.
This will open another window named Untitled. This is the working window
in which we will build our model. Save the file as
respm1_YOUR_NAME.mdl before you proceed.
4. The main SIMULINK menu displays several libraries of standard block
functions that we can select for model development. In this practical, we
would choose a block that could represent the transfer function shown in
Equation (1).
5. Open the Control System Toolbox (by clicking this block).
6. Select LTI system and drag this block into the working window.

7. Double-click this block to input the parameters of the transfer function. Enter
the coefficients of the polynomials in s in the numerator and denominator of
the transfer function in the form of a row vector in each case. Thus, for our
example, the coefficients for the numerator will be [1 420 0] and denumerator
will be [1 620 4000]. These coefficients are ordered in descending powers of
s. Note that even though the constant term does not appear in the numerator of
Equation (1), it is still necessary to include explicitly as zero the coefficient
corresponding to this term.
8. Once the transfer function block has been set up, the next step is to include a
generating source for Pao. This can be found in the Sources library
in Simulink block. In this practical, we will select and drag the sinewave
function generator
Ventilator.

into working window. Label this Source as

9. Double-click this icon in order to modify the amplitude and frequency of the
sine wave.
10. Set the Amplitude to 2.5 cm H20 (i.e. peak-to-peak swings in Pao will be 5 cm
H20), and the frequency to 1.57 radians s-1, which corresponds to 1.57/(2 ) =
0.25 Hz or 15 breaths min-1. Leave the rest of the parameters as default values.
11. Now connect the output port of the sine wave block to the input port of the
transfer function block with a line. This can be done by dragging the mouse
from the source to the designated block.
12. To view the resulting output Q, open the Sinks library

and drag a Scope

block
into the working window. Do not choose the floating scope. Label
this Scope as Q vs Time (single click on the scope label and rename).
13. It is always useful to view the input simultaneously. Drag another Scope
block into the working window and connect the input of this block to the line
that transmits Pao. (i.e., by dragging a line from the Scope to the line at the
start of the source refer to Figure 2.1). Label this Scope as Pao vs time
14. Now, the model is complete and you can run the simulation by clicking on
icon in the working window (as shown in Figure 1).

Figure 2.1.

Log-sheet Question
2.1 What did you observe in your Scopes?

15. It is useful to add a couple of features, e.g. to view the results in terms of
volume delivered to the patient. This is achieved by integrating Q. From the
Continuous block

, select the Integrator block

Connect Q as the input of this block and direct the output (Vol) of the block to
a third Scope. Label the Scope as Volume vs time.
16. It is also a good practice to save the results of each simulation run into a data
file that can be examined later. This is can be achieved by using the To File
block. From the Sinks library
, select and drag the To File block into the
working window. This output file will contain a matrix of numbers. A name
has to be assigned to this output file as well as the matrix variable.
17. Double click on the To File block and a dialog window will be displayed. In
the Filename textbox, enter the name of your file as
respm1_YOUR_NAME.mat, and in the Variable name textbox (i.e. the matrix
variable) enter the name respm1_YOUR_NAME. Note that mat files are the
standard (binary) format in which MATLAB variables and results are saved.
18. The first row of matrix respm1_YOUR_NAME will contain the times that
correspond to each iteration step of the simulation procedure. In our case, we
would like to save the time-histories of Pao, Q and Vol. Thus, the To File
block will have to be adjusted to accommodate three inputs. Since this block
expects the input to be in the form of a vector, the three scalar variables will
have to be transformed into a 3-element vector prior to being sent to the To
File block. This is achieved with the use of the Mux block
the Signal Routing library.

, found in

19. After dragging it into the working window, double-click the Mux block and
enter 3 for the number of inputs. Upon exiting the Mux dialog block, note that
there are now three input ports on the Mux block.
20. Connect the Mux output with the input of the To File Block. Connect the
input ports of the Mux block to Pao, Q and Vol.
21. The block diagram of the completed SIMULINK model is shown in Figure
2.3. The final step is to run the simulation.
Pao vs time'
respm1_INSTRUCTOR
To File

1
s
Integrator

Volume vs time

tf([1 420 0],[1 620 4000])


Ventilator
LTI System

Q vs time

Figure 2.3. SIMULINK model of simple lung mechanic in Exercise 2.

22. Click Start in the Simulation menu or clicking on


window to proceed with the simulation.

icon in the working

Log-sheet Question
2.2. What are the predicted dynamics of Q and Volume that you obtained?
Exercise 3 Creating Simulink Model using Ordinary Differential Equations
This is a simple exercise to guide you through creating a Simulink model using
ordinary differential equation (ODE) directly, as opposed to deriving the transfer
function as in Exercise 2. Consider the following First Order ODE,

dy
= kx my
dt
where y and x are variables, and k and m are parameters.
Assume zero initial conditions, parameters k = 2 and m = 0.5.
1. Solve for the terms with the highest-order derivatives. In this case, our
highest-order derivative is dy/dt.
2. Make the left-hand term the output of a summing block and make the righthand term the input of the summing block, see Figure 3.1.

Figure 3.1.
3. Add integrators to obtain the desired output variables as shown in Figure 3.2.

Figure 3.2. Step 3.


4. Add initial conditions to the integrators by double clicking on the integrators
and edit the initial conditions field. (It is zero by default). In our case, they
should all be zero.
5. Referring to the equations, signals are feedback to the summer. Connect to the
integrated signals with gain blocks to create the necessary signals as shown in
Figure 3.3. You may flip the orientation of the gain block by clicking format>flip block.

Figure 3.3.
6. Connect the feedback signals to the summer.
7. Identify input by connecting a step function and output to a scope.
8. Connect a gain to the input x and connect the signals to the summer. Modify
the gain parameters to be m = 0.5 and k = 2.

Figure 3.4.
9. The SIMULINK diagram is completed as shown in Figure 3.4. Run the
simulation and observe the output and input by connecting the scopes.

Log-sheet Questions
3.1 What is the output y that you obtained?
EXERCISE 4 Creating Lung Mechanics Model directly using ODEs
In Exercise 2, we need to derive the analytical expression for the transfer function
Q(s)/Pao(s) which can be quite tedious. In this exercise we will implement the
same model using the basic circuit equation directly (i.e. Equation 1 and 2).
One limitation in the model implemented in Figure 2.3 is that is does not allow
access to these internal variables since the system dynamics are lumped into a
single transfer function block [1]. The SIMULINK implementation of the same
model in Figure 4.1 displays a more open structure. Various segments in the

10

block diagram shown correspond directly with the basic circuit equations (i.e.
Equation 1 and 2).
1
1
1
Q A dt =
(Q Q A )dt
R p Q A +
+
(1)
Cs
C L CW
Pao = Rc Q +

1
Cs

(Q Q )dt

(2)

1. Modify the SIMULINK respiratory mechanic model in Exercise 2 into the


model as shown in Figure 4. An enlarged version of Figure 4 is shown in
Appendix A.
Pao vs time'
respm2_INSTRUCTOR
To File

1
s
Pao

Integrator

Volume vs time

1
Ventilator

Add

1/RC
Q vs time
QA

0.005
Memory

du/dt

Cs

QS

Derivative

Add1

1
s
Integrator1

Paw
0.5
1/0.2

Rp

1/CL
Sum3
Sum2
1/0.2
1/Cw

Figure 4.1. SIMULINK model of simple lung mechanics for Exercise 2. (Refer to
Appendix A for an enlarged version of the diagram.)

Log Sheet - Questions


4.1 Include all your SIMULINK models in your log sheet.
4.2 Using the model in Exercise 4, determine how airflow Q and tidal volume
(Vol) would vary in response to sinusoidal pressure waveforms at the airway
opening (Pao) applied at 15, 60, 120 breaths min-1 (with amplitude = 2.5 cm
H2O). Include the graphs of the results in your log sheet. Comments on your
results.
4.3 Emphysema is a pulmonary disease which is caused by loss of elasticity or
increase in compliance of the lung tissue. This is due to destruction of
structures supporting the alveoli and capillaries feeding the alveoli. To

11

simulate a subject with emphysema, increase lung compliance (CL) to 0.4L cm


H20-1 and peripheral airway resistance (RP) to 7.5 cm H2O)sL-1. Repeat the
simulations at the frequencies listed above. Compare the frequency
dependence of the resulting airflow and volume waveforms to those obtained
for the normal subject.
4.4 Comments on the advantages and disadvantages of SIMULINK models in
Exercise 2 and Exercise 4.
7.

REFERENCES
1.

Michael C.K. Khoo, Physiological Control Systems. Analysis, Simulation,


and Estimation. Wiley-IEEE Press, 1999.

12

Appendix A

Pao vs time'
respm2_INSTRUCTOR
To File

1
s
Pao

Integrator

Volume vs time

1
Ventilator

Add

1/RC
Q vs time
QA

0.005
Memory

du/dt

Cs

QS

Derivative

Add1

1
s
Integrator1

Paw
0.5
1/0.2

Rp

1/CL
Sum3
Sum2
1/0.2
1/Cw

13

Appendix B (If you are curious)


Why do we need a memory block in our model?
The double loop containing the gain 1/CL, 1/CW, RP and CS in the SIMULINK
diagram of Figure 4.1 represents Equation (1). This kind of open architecture also
makes it easier to determine how alterations in the parameters, such as what might
occur with different lung diseases, are expected to affect overall lung mechanics.
However, a common limitation with this approach is the creation of algebraic
loops. This problem arises when blocks with direct feedthrough blocks are
connected together in a loop. For example, in Figure 4.1, the gains RP and CS are
connected together with the derivative block in a closed loop. These functions are
all feedthrough blocks, so that any integration step, the simultaneous solution of
the two equations represented by this loop is required. This is accomplished
iteratively, but numerical ill-conditioning could lead to no convergent solution.
For algebraic loop, SIMULINK reports an error when more than 200 iterations
are expended per integration step. We eliminate this problem in our example by
adding memory block to the closed loop in question. The memory block simply
adds a delay of one integration time-step to the circuit. However, one should be
cautioned that this fix does not always work and, under certain circumstance,
could lead to numerical instability. [1]

14

Anda mungkin juga menyukai