Tuesday, 25 December 2012
Finding solutions
So, the first problem that I am having is that the radius of the artery that I am going to be receiving will be changing for every instance of simulation. I need to pass it on to a file which is called in the embedded matlab block which inputs this changing radius.
To make it sound simple, I will create a simpler scenario, make it work on my scenario, and then test it on the actual case. Now, what we have currently is a file that takes in a pulse generated value, and a sin wave, sums it and gives the output to a scope.
I'll do this, let the pulse output be the Arterial Cross Sectiional area variations. Let the sin wave be the pressure from the heart. The embedded MATLAB block will take the CS, calculate radius, save it to the workspace as the variable r, and call another function baby. Baby will take the updated radius increment it by 10. This incremented value will be multiplied to the sin wave and output will be shown.
So, what we have to do in simulink is
1. Sin block
2. Pulse generator block
3. Embedded matlab block with the above as inputs.
4. Calculate radius and save into a workspace variable and call baby
5. Baby takes radius, multiplies by 10 and returns value.
6. This value is then multiplied to sin wave and shown as output.
In all of the above steps, steps 4 and 5 are difficult. How do we do that?
Saturday, 22 December 2012
Need the complete program today
Referring to this for understand how to solve pde programmatically.
Really scared now.. :(
Okay, So have been going in steps.
Right now, the following program works.
[p,e,t]=initmesh('Mycircleg');
[p,e,t]=refinemesh('Mycircleg',p,e,t);
u0=zeros(size(p,2),1);
tlist=linspace(1,0.1,20);
u1=parabolic(u0,tlist,'circleb1',p,e,t,0.0035,1,f,1060);
pdesurf(p,t,u1)
What I have to do in this, are the following modifications:
1. The radius of the circle in Mycircleg.m need to be passed somehow from the main Embedded MATLAB file.
One way to do this is save the input radius variable in as a matlab variable in workspace and access it in the next file.
2. In the parabolic function, a number of replacements have to be done. We'll begin from the end. Last 4 parameters of the function are c, a, f, d.
c = viscosity of blood, 0.0035 kg/m.s. a is gravity = 1, pressure f needs to be provided dynamically from the pressure source, d = 1060kg/m3
One way to do this is to just have another input to the block, and use that variable in place of f.
3. tlist variable!! We know that the function parabolic will evaluate the solution to the geometry for every value of the array tlist. but I need the function to be evaluated for every value of the simulation time!
I will have to try different combinations of possibilities for this.
Friday, 21 December 2012
Trying to write the s function, and serendipity: Embedded MATLAB function
So, I know the template to be used. I know what I want to do. Just need the courage to start doing it. Here we go.
Phusssssssssss.................... Phusss, Phusssss, ...
So fooooolish of me!! Easier way is to use Embedded MATLAB function. Already tried it out with the example that I considered in the last post. Now, to my pde function. :)
Thursday, 20 December 2012
Analysis to plot the pde parabolic solution
Now that I have understood what the code snippette does, we've gotto think about what the output should be.. It should be the velocity profile during the simulation time.
This makes me realize that, the time tlist that we supply to the parabolic function for solution of the pde should be changed to the simulation time. => How?
Each column in u1 is the solution at the time given by the corresponding item in tlist. For my function, parabolic, each item in tlist needs to be block.CurrentTime. What should be the size of this array? Depends on the number of itertions of the solution we want to see. I need to try this out, on a smaller scale before implementing it on my model. Need an example.
let x be a sin wave, let y be a square wave. Let us try to build a block that will create an output that is a sum of these two inputs and the simulation time taken as an input through the functions arguments. ok. Let's try that out right away, .. but for that, I need to know how,.. how EXACTLY to write a level 2 matlab s function. Here we go.
Alright, so, read through and have realized that, it's a whole new set of keywords and almost an entire language to learn, .. when writiing an s function.. Remember having a s-function writing wizard of some sort in simulink.. It will be better if I use that,.. instead of wasting my time writing the entire code, .. let's check that out. No, .. no, .. that looks even more scary, coz it uses C mex and c code. Let that be. I'll continue with writing the s function matlab code only. Studying how to write an s-function from this pdf document. Very helpful.
Wednesday, 19 December 2012
Writing the s-function as m-file
Hey!! Good morning! Back after indeed a very very long time! Had my 3rd semester exams; and then a long vacation of an entire week. Pampered myself for a while. Now back to the project. Pressure needs to build up for me to get back on track. Spoke to my cousin sister yesterday, and finally decided that I should start.
So, I have sort of implemented all that I have written in the previous post, only the most important one, the last block of pde solution isn't done. I tried to do it.
Firstly, followed the same steps they have given in the pdetool, parabolic part in the manual. It's missing the plotting code. So realised I need to understand the bloody code. If I don't understand it, it's senseless. To understand the code, .. I HAVE to blog! Else my mind wanders around. So, here we go..
First line in the code is:
[p,e,t]=initmesh('circleg'); % Create initial triangular mesh
As we all know, to apply the pde on every point of the geometry, we first divide the geometry into small triangles. This we call meshing. We apply the pde on every triangle and then integrate the result. This is the method of finite element I guess. Need to search a bit on what it exactly is, but I think that's it. And this function 'initmesh' initializes the creation of this mesh.
The function obviously needs the geometry as the input parameter, which we can define in different ways according to the format and flexibility of the function. The output of the function is the meshed data; p => point matrix with x and y coordinates of mesh points as the rows of the matrix, e => edge matric with starting and ending point indices, starting and ending point parameter values, edge number and left and right side subdomain number, t => triangle matrix with three corner points in anticlockwise direction and subdomain number.
Next,
[p,e,t]=refinemesh('circleg',p,e,t); % Refine triangular mesh
Refinement usually bisects every edge of the specified triangles, thus creating 4 new smaller triangles out of every specified triangle. Hence the input to the function is the geometry under consideration, and the specified initial mesh and the output of the function is the p, e, t matrices of the refined mesh for that geometry.
Next,
u0=zeros(size(p,2),1);
size(p,2) returns the size of the 2-D p matrix and zeros(size(p,2),1) returns a 2-D zero matrix of the same size. We name it u0.
Next,
ix=find(sqrt(p(1,:).^2+p(2,:).^2)<0.4); % Find indices and values of nonzero elements
This finds all the non-zero points inside the circle with radius 0.4 units, and returns its indices as a column vector.
Next,
u0(ix)=ones(size(ix));
We replace the found non-zero entries of interest by 1 in the zero matrix u0
Next,
tlist=linspace(0,0.1,20);
create an array that will have values of 0 to 0.1 in 20 steps.
Last,
u1=parabolic(u0,tlist,'circleb1',p,e,t,1,0,1,1); % Solve parabolic PDE problem
parabolic is a function that produces the solution to the FEM formulation of the scalar PDE problem. Its input parameters are,
u0 => initial value of the mesh
tlist => time for which solution to be obtained
circleb1 => Initial Boundary condition data
p, e, t => mesh point, edge, triangle data
1, 0, 1, 1 => c, a, f, d
c => viscosity
a => gravity
f => pressure
d => density
u1 => final solution at the end of simulation time.
Now I need to plot this u1.
Saturday, 17 November 2012
Joining the Pieces of the Puzzle
Friday, 16 November 2012
Confirming the 4th Change in Direction and Some Relief!!
Wednesday, 14 November 2012
Serious Glitches..! Worried Now..
11:36 pm
Have been trying to avoid it, but that's going to be dangerous, gotto face it, and find a way out! Not run away! So here we go!
After reading the "Model of the Main Arterial Tree" part from the paper very carefully I have realised the following things:
The model is based on, firstly, the Mass Conservation Equation given by,
where,
v is the mean blood flow velocity
S is the arterial cross-section
z is the distance from the aortic valve along the arterial tree
psi is a function describin outflow from the small arteries which are not geometrically depicted
They have mentioned in the paper that they’ve solved this equation using the method of characteristics. Studied it with the help of this video and tried to solve my equation in the following way: (hope it is all understandable)
As you can see, I encounter many problems while trying to solve the mass conservation equation.
Firstly, I do not know if v is a variable which is dependent on the value of z or not. Thinking about it, we realize that the velocity does actually change depending on its distance away from the heart. But that happens only due to the change in pressure with distance which we rae going to accommodate for. If we include this dependence, the equation becomes difficult to be solved using the method of characteristics. Saying this, coz I tried doing that as shown below:
Thus, I decided to assume it independent of z, and continued as shown in the first image.
Secondly, knowing that v is the mean velocity, we try to understand the meaning of the word mean velocity. Considering the fact that in the paper, they have mentioned that the objective of using this method is to be able to compute blood velocity and pressure at any point in the arterial tree as the contribution of the incident and reflected velocity and pressure. Which implies that, by mean velocity, they mean, the resultant of velocity and pressure from maternal side and the fetal side. This makes us think that the v mentioned, needs to be the input to the simulink block that will solve the mass conservation equation, and before entering this block, there needs to exist a simulink block that will calculate this mean velocity. At whichever point in the arterial tree we need to check the velocity or pressure, we need to do the calculation for that part.
This conclusion gives rise to a controversy. Is this input velocity the same that will be shown as the output velocity? Cannot accurately answer this question right now, coz we haven’t come to that point in the process still, but all that I can guess right now, is that, this input velocity will be acted upon by the mass conservation equation, then the stokes navier equation etc. and get modified. Coming to think of it now, I feel that the input to the system is this mean velocity, but the output might be the pressure wave. This might be needed to be converted into velocity somehow, since none of the equations in this part give velocity as the output.<== Problem
Going into the depth of the above mentioned problem, now we need to
- Figure out how to calculate the mean velocity
- Find the expression that describes the relation between velocity and pressure of an incompressible fluid.
Once the mean velocity calculation problem is solved, we need to know how to incorporate this into the mass conservation equation, and design a simulink block that implements the mass conservation equation.
So now, let us talk about this solution of the mass conservation equation, In the equation, they have mentioned psi, whose value hasn’t been mentioned anywhere in the paper. Need to ask what value to input as PSI. Assuming currently that it is zero, I move ahead. As shown in the first image, this gives the solution as
S= f(zo)=f(z-vt)
This equation says that the cross sectional area for the curve represented by z-vt = zo is given by the function which is the initial condition at t=0 for that curve.
For all arterial segment we have been given the length of the segment and the cross sectional area at its 2 ends. The table is as follows:
Now as the solution the cross section needs to be a function of z-vt. What function? As the tutorial video suggests, this function is the initial condition given. What is the initial condition given to us? These are just numbers. Thus we need to form relationships, preferably, linear from the given values of cross sections and length. To do this, I used curve fitting tool from MATLAB. Here’s the video of how I did it. Sorry for the delay between video and audio, and the overall bad quality.
Okay, the video refuses to get uploaded, sorry! Here are the equations that I got:
For all the above expressions, y is the respective Cross section and x is the respective position coordinate.
For arterial segment 1 and arterial segment 5, the cross section remains constant. That is it does not change for any value of length. Thus the initial value remains the same for all space coordinates.
Now that we have a relationship that describes the initial condition and relates cross section with the z coordinates, we need to figure out how to incorporate the value of z into the initial condition and how to incorporate the initial condition into the solution.
For each of the above x, we substitute z- vt where z is the distance from the aortic valve along the arterial tree to the beginning / end (?) of the arterial segment, v is the computed mean velocity and t is the simulation time. So now, we have got the logic for doing a part of the Arterial segments modeling.
After this, is the block that computes the arterial vascular elasticity and incorporates that into the model. This part is given as follows:
So, c1(p) is a polynomial block, and c2(z) is a waveform to be approximated. these can be implemented on SIMULINK.
All this to be implemented on MATLAB and have to think about the mean velocity block, tomorrow!
ATB!
Saturday, 10 November 2012
Hello World!
04:43 pm
Trying to work on the project, but my cousin sister keeps disturbing me.. Making aweful noises in my ear.. Cheh.. But hey!! It’s fun!!
Trying out Windows Writer for the first time.. Let’s see how this goes!
Yo!! ATB!
Edit1: My sis angry! So, … Credit of the Writer Discovery to her!!! Maskaa!!
Monday, 5 November 2012
Modeling the Feto-Maternal Circulation Arterial Tree
3. Peripheral areas:
(PA.1) Brain
(PA.2) Kidneys
(PA.3) Peripherals at Primitive Iliac Artery Bifurcation
(PA.4) Peripherals at External Iliac Artery Bifurcation
(PA.5) Peripherals at Internal Iliac Artery Bifurcation
4. Arterial Segments:
(Seg.1) Ascending Aorta (Ductus Arteriosus)
(Seg.2) Thoracic Aorta
(Seg.3) Abdominal Aorta
(Seg.4) Primitive Iliac Artery
(Seg.5) Internal Iliac Artery
(Seg.6) Umbilical Arteries
(Seg.7) Uterine Arteries
5. Bifurcations:
(Bif.1) Cerebral Arteries
(Bif.2). Renal Arteries
(Bif.3) Primitive Iliac Arteries
(Bif.4) External Iliac Arteries
(Bif.5) Internal Iliac Arteries
6. Placenta on the fetal side of the feto-maternal circulation
7. Placenta on the maternal side of the feto-maternal circulation
1. Modeling of the fetal heart:
Fetal Heart parameters, ventricular pressure and ventricular volume follow the relation,
p(t) => ventricular pressure in mmHg
V(t) => ventricular volume in ml
V0 => Reference Volume
E(t) => Ventricle Elastance
In this relation, p(t) and V(t) are unknowns. Thus, I had to create a pressure wave that approximates the one given in the paper. I used the following values:
pressure axis => [0, 0, 1.09, 1.49, 1.79, 1.93, 1.99, 1.99164, 2, 1.96, 1.9, 1.82, 1.65, 0, 0]
To find E(t), there exists an equation
where En(t) = 5.412t^6 - 20.066t^5 + 25.542t^4 - 13.71t^3 + 2.714t^2 + 1.08t + 0.029
After the analysis of fetal lamb and dog heart and approximately equating it to human fetus, we obtain, Emax = 6 mmHg per ml and V0 = -8ml.
Error: The output produced shows pulsetile increase in pressure, but it does not reduce to the baseline!
2. Modeling of the maternal uterine arteries:
I approximated the above shown waveform which was the only information provided about the uterine pressure. The values that I used are:
Pressure values => [78, 77, 78, 80, 90, 100, 110, 118, 122, 130, 131, 130, 122, 118, 112, 108, 103, 100, 90, 87, 84, 82, 84, 84, 80, 79, 78]
Time Values => [0, 0.05, 0.1, 0.12, 0.14, 0.16, 0.18, 0.2, 0.22, 0.24, 0.25, 0.26, 0.28, 0.3, 0.32, 0.34, 0.36, ,0.38, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8]
3. Peripheral Areas
Q(t) => Blood flow
R => Resistance of PA
C => Compliance of PA
pc => Critical Pressure of PA
With the above mentioned values from the paper and the equation mentioned, I created the PA basic subsystem in Simulink as shown:
and varied the pc, R, and C values for every PA.
Arterial Segments and Bifurcations : Main arterial tree
- the density of blood
- viscosity
2. This highly mathematical part of the model in the paper, which requires the solution to the Navier - Stokes Equation as solved using Method of Characteristics, has not been provided.
Since we see that in the above mentioned paper, twhy use the PDETool, to solve the fluid flow equations, and I am using Simulink, I need to somehow interface these two. For this I just found this paper very useful.It gives an example in which they have attempted an interface between, Simulink and PDETool. Will be studying and implementing the model from these sources!
ATB!
Monday, 29 October 2012
Mathematical modeling, glitches expected
- It simple.
- Model parameter values have been provided.
- It not only talks about feto-placental circulation, but gives circulation in other important arteries like cerebral artery.
- By 2 weeks, that is, till Diwali, the simulation of this model on Simulink should be ready for review by the External Guide.
- If the model gives results that match the ones given in the paper, for a normal lady, then pathological cases could be taken up.
- This could be then presented to the ethical committee, and approved for collection of data for abnormal patients.
- Parallely, could think about writing a paper.
- How we are going to present this topic?
- Which conference to select? (Preference: International, IEEE conference)
Monday, 15 October 2012
Electrical model for Doppler Waveforms of Utero-Placental Blood Flow
Saturday, 13 October 2012
The Review Effect: Papers & Models!!
Sunday, 7 October 2012
Promising Optimistic Discussion, Heavy Dreams!
Saturday, 6 October 2012
Least Excited and Bothered : State of Mind
Wednesday, 3 October 2012
Finally Understood What He Wants
Editing the post.
So, I've realized that he doesn't want to use patient data, means he first wants to try it out on simple pulsatile flow of fluid. Now, I want to avoid going to IIT-B. So I prefer computer simulation of this fluid flow. Found out that the PDE toolbox in MATLAB helps using partial differentiation equation and the pdetool to simulate the fluid flow. But, I need a pulsatile fluid flow! <= Prob No. 1 !
Even if I'm able to find a pulsatile fluid flow code, and create it, I'm going to have to represent the flow in terms of velocity, and then convert the velocity profile of the fluid flow into audio. for further signal processing.<= Prob No. 2 !
All this feels very overwhelming. Because, for computer simulation, I need to know the equations governing the fluid flow, sheer stress, strain.. and lot of physics. It does make me feel that doing it in practice would be better than simulating it. But go to think about it, I will have to know the physics even if I want to do it in practice! Additionally, many factors would be clearly in much better control without any mess if I use computer simulation, rather than practical.
So, things to do:
1) Study pde tool.
2) Find a way to model pulsatile fluid flow.
3) Study the necessary fluidics.
ATB!
Tuesday, 2 October 2012
And Worst, a Mocked Reply.
Finally a Reply, with a Monotonous Negativity
Breakthrough, My Way!
Monday, 1 October 2012
Finding a Way, and Taking a Stand
Friday, 21 September 2012
Communicating the Doubts to my External Guide
This is a computer simulation based on Inverse Modelling. In inverse modeling, the model is a black box with unknown characteristic values. Given a set of outputs, the task is to identify these unknown characteristic values that produce outputs that match the given output to complete the model.
In our case the simulation output is the velocity profile of the blood or the blood flow. The inversion task is to identify the corresponding parameter values in the fetal-placental artery system to produce that blood flow.
Also, in our case, what affects the fetal-placental blood flow is :
i) the values of the fetal heart rate,
ii) the placental resistance
iii) the brain resistances
Based on the information, we can analyze the correlation between fetal heart rate and blood flow in the compensatory fetus.
Now, how do we find these characteristic values? We use the Genetic Algorithm. Genetic algorithm mimics the process of evolution. This is as follows :
i) Start with a population of randomly generated individuals,
ii) Find the fitness of all the individuals in this generation,
iii) Select multiple, say 2 individuals from this population with highest level of fitness
iv) Mutate them to form the next generation
v) Repeat the process till satisfactory level of fitness has been reached.
Applying this to our case, the each characteristic represents the individual in the generation, then we define the fitness level, in terms of how close the values of the simulated output should be to the expected output. And thus we implement the algorithm using various techniques of mutation, or crossover, and repeat the process till the fitness level is reached.
The black box then represents our system.
This has been implemented before, and I have this paper (please refresh to download or view) for help. Additionally, the entire theory is easily available for study. And trustworthy.
Once we have established the characteristics of the system to get certain output, we can give it various input to generate fetal-placental flow with various conditions. This can become the input to another signal processing system which will classify it, and determine which condition exists. This will validate our signal processing system.
Ya? ATB!