Division of Bioengineering
Name:
_______________________________________
Matric Number:
_______________________________________
Group:
_______________________________________
Date of experiment:
_______________________________________
GRADE: _____________
(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 .
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.
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
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
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
Q vs time
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.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
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.)
11
REFERENCES
1.
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
14