SlideShare a Scribd company logo
1 of 11
1
A241MS- Matlab and Simulink for Science and Engineering Research
Coursework
Coventry University
Michael James Etienne
SID: 4129406
2
Table of Contents
A. Case Study A 1
a) Part a.........................................................................................................................................3
b) Part b.........................................................................................................................................4
B. Question A 2 creating a Matlab Function
a) Part a..........................................................................................................................................5
b) Part b..........................................................................................................................................5
c) Part c..........................................................................................................................................5
d) Part d..........................................................................................................................................6
C. B2 Simulink
a) B1...............................................................................................................................................7
b) B2c .............................................................................................................................................7
c) B2d............................................................................................................................................7
d) B2e.........................................................................................................................................8 & 9
D. C Image Processing
a) Part a........................................................................................................................................10
b) Part b........................................................................................................................................11
3
A case study 1
a) As relevant to the question criteria my answers willbe in relation to the data supplemented fromgroup 1.
Firstly I loaded the data fromM1_video fromthe respiratory data and displayed it below in a figure showing
the data plotted in relation to amplitude (cm)and time (samples) for the whole data. To only select the
M1_videoand not load any other data I implemented this code:
%%loading the data specifically the M1_video and plotting 3 cycles
%%specific to my student ID
load('RespiratoryData2013.mat','M1_video')
bi) The next part of the question was to extract 3 cyclesof data from the graph. To do this I had to create a
Matlab code,which wouldselect the data within the 3 cyclesand it was unique for every person. This was your
last digit in yourID+1. In my case this was 6+1=7 meaning I had to extract 3 cyclesof data from the fourth
cycle.For this I used the followingcode to extract the 3 cyclesworthof data and plot it. This was named ME3.
ME3 = M1_video(1,145:230);
The result from using this codeto select this particular data and then plotting it gives the figure below.
4
bii) The three cyclesof data are then normalised so that it will begin at 0. Implementing this code below does
this and it brings all the points down. I worked this out by looking at the first point (145) on the graph, which
showed it to be 4.315. This was subtracted fromall the points to bring them all downby the same value. This
data was then plotted again against the same axis and this produces the graph below:
%%Normalising the 3 cycle so it begins at 0,0
A = M1_video(1,145);
figure, plot(ME3-A);
biii) The time vectorfor this question, which can be used to correspond with the 10Hz sampling time and in
with the same length of the 3 cycles,is:
%%Creating the time vector for the data
fs = 10;
Ts = 1/fs;
TimeVector = [0:Ts:8.5]; %difference between 14.5-24 seconds
M = ME3-A;
figure, plot(TimeVector,M)
The reason that 0.1 is used as the time sampling is that 10Hz is the sampling time and from the graph above
this time is used from 0 to 8.5 as this is the time for3 cyclesto occur in-between 14.5-23 seconds which was
calculated from the frequency being 10Hz=0.1 second, e.g. 145/0.1=14.5.
biv & bv) Now applying the time vectorto the data and then plotting it with relevant axis gives the graph
below. The axis were labeled in correspondence to the data which was the amplitude, this was in relation to the
height of chest as it rose
up and down when the
person was breathing.
The x-axis is the time
period where the
breathing was taking
place. To edit the axis’s
you clickon the insert tab
on the top and scroll
down to x or y label. The
size and font of the
writing of the axes can be
edited at the bottom of
the page as well as colour
and other features to
make the graph more
interesting or eye
grabbing.
5
A2 Creating a Matlab Function and fitting to data
a) For this question I had to create a functionwith a formula to model the respiratory motion. The function
implemented the followingformula:
𝑦(𝑡) = 𝑌𝑜𝑓𝑓𝑠𝑒𝑡 − 𝐴 ∗ 𝑐𝑜𝑠2𝑛(
𝜋𝑡
𝑇
)
With the inputs being: 𝑌𝑜𝑓𝑓𝑠𝑒𝑡 , A ,n ,T ,t and the outputs being: y(t).Along withthis I then created a Matlab
Function incorporating this formula to create a coswavewhichwas plotted in the time vectorwhichwas t = (0:
0.1 : 8.5) whichwas used in A1.b.iii . Below was the Matlab Function, whichI implemented and then provided
comments to make sure that I understood every step
function Y= fctME(Yoffset,T,t,A,n) %creating a function that can be implemented and shows the
inputs of this function
Y = Yoffset-A*cos(pi*t/T).^(2*n); %formula which is used in the function
%creating the function which the different inputs are linked to my SID
Yoffset= 3.6; %3.SID which ends in a 6
t= (0:0.1:8.5); %the time vector previously defined in 1A for the 3 cycles of data
T= 4.6; %4.SID which ends in a 6
A= 2.6; %2.SID which ends in a 6
n= 4;%given as 4 as my last number of my SID is an even number
bi) I then moved onto creating the mfile that wouldcall this functionand creating the coswaveassociated with
this formula. I had to define all the variables in the mfile. This is shown below:
%%Initilisation
A = 2.6;
Yoffset = 3.6;
T = 4.6;
t = (0:0.1:8.5);
n = 4;
bii, biii) After this I then had to call the function into this mfile to calculatey(t) using the time vectorfromthe
pervious question A1.b.iii. The time vectorused was t = (0: 0.1 : 8.5). Once the time vectorwas implemented
and the function is called in the mfile, I was then able to plot the graph that is shown below.
c) I then plotted this waveon top of my data but it became my y(est) as I reduced the amplitude in line withthe
data so it became the estimate wave of the respiratory data. Toreduce the amplitude, the value A was reduced
to be equal to the maximum value of A of the data, for my workthis was 0.8685. This was then plotted in a
graph, whichis shown at the top of the next page with the relevant script workalong with it.
6
%%Initilisation
A = 0.8685; this is the new value of the amplitude for the y(est) to fall in line with the y(t)
Yoffset = 3.6;
T = 4.6;
t = (0:0.1:8.5);
n = 4;
%%plot the result
figure(2)
plot(TimeVector,Y-2.747,'ro');%normalise y(t) in relation to the function fctME
hold on
load('RespiratoryData2013.mat','M1_video')
ME3 = M1_video(1,145:230); %using the previous 3 cycles of data from A1
A = M1_video(1,145);
M =ME3-A;
plot(TimeVector,M);%normalise this y(est) and then is plotted along with the fctME.m
% create a string what will be displayed at the top of the figure (graph)
title('3 cycles of respiratory data')
% same but using num2str to display the value of f as opposed to the letter
title('3 cycles of respiratory data')
xlabel ('Time[s]')
ylabel ('Amplitdue[cm]')
d)
Above is the fully documented plot containing two times of data including the y(t) (blue line) whichis the
actual data fromprevious question, refer backto 1A, and the y(est) (red dotted line) whichis the function
created in this question which includes the inputs; A, T, t, Yoffset.
Left: This part of the script was used to create the
titles on my figure including the two axes. If I wanted
to change them at any time I would simply change it
here and not have the trouble of doing it on the figure.
7
B2 Simulink
B1) This question involvedusing the programme Simulink to model a free body diagram where different
forcesare acting on a mass. With this model you have a transfer functionthat is used in first order model and it
is given by:
𝑌(𝑠)
𝐹(𝑠)
=
1
𝑀𝑠2 + 𝐵𝑠 + 𝐾
The variables used in this model are given as:
 M = 300kg
 B = 16000N/m
 K = 1400 whichdoesn’t have a unit
For these variables to be implemented into the models I had to create an initialisation file on Matlab that could
be used to drive the model and also produce the signals. Below was the Initialisation file I created on Matlab to
be used throughout this question, where the variables were also stated.
%%Initialisation file used for the simulink model on question B
M = 300; %measured in kg
K = 16000; %measured in N/m
B = 1400; %no value stated in the question
This also included the amplitude at the value of 1000 and I chose the frequency tobe 0.2. This was chosen as I
felt it gave me the correct sampling time in which I couldcapture all the dynamics created by the model. If it
was any greater then it wouldn’t be clear enough or if it was any smaller I feltyou wouldn’t be capturing
anything and would be seeing a small section of it. These twovariables will remain constant throughout the
question.
B2c) The next part of the question involved using the initialisation file and creating a first order model that in
turn should create a signal with a square wave frequency.The model I created involveda signal generator, a
transfer functionand scope. This is the model shown below:
This was quite a simple model to create on simulink as it was just a second order with a transfer functionand
once the variables were ran on Matlab as well as the model, the signal produced was this shown below. Ihad to
also alter parameters on the model by changing the tolerance to 7 instead of 3 because this makes it a smoother
curveas well as changing the maximum step to 100. Changing the step saves changing the zoomon the screen.
Above: Screenshot of the history of how the model was
constructed in Simulink
8
Youcan see as well there are areas of overdamping where the line goes above0 and there are areas of over
damping which are points that are below 0.
B2d) As well as using this model to produce this signal it can also be produced from a rearranged differential
in a model. This is done when using an equation with the highest order of the differential equation being
expressed as a functionof lowerorders. By this I mean that the original differential equation can be rearranged
as:
𝑓( 𝑡) = 𝑀
𝑑2 𝑦(𝑡)
𝑑𝑡2 + 𝐵
𝑑𝑦(𝑡)
𝑑𝑡
+ 𝐾𝑦( 𝑡) →
𝑑2 𝑦(𝑡)
𝑑𝑡2 =
1
𝑀
𝑓( 𝑡) −
𝐵
𝑀
𝑑𝑦( 𝑡)
𝑑𝑡
−
𝐾
𝑀
𝑦(𝑡)
From this equation I am able to constructanother simulink model based around the first order model. This
would be seen as a second order model as it would be in the transfer functionfrom the previous model. This
was slightly trickier to construct. The only way in whichI could tell if I had constructed correctly wasif the
output signal in the scope was identical to the first model scope. Below is the model that I created on simulink
in relation to the differential equation.
This model involvedmore
blocks fromthe library
including a gain, integrators and
a summing junction. The same
variables were used in this
model as well and fromthis the
signal produced from the scope
was equal to the first model. The
signal produced is shown
below:
Above: Changing the scope to an array for the Matlab and giving it a variable name
9
B2e) Now to clarify that both of my signals from both the signals are identical and the models are both
correct,I would have to plot both signals onto one signal graph. To do this I wouldhave to create a Matlab
script to allow me to plot the graph but before this I wouldhave to create arrays for the x points and y points
for every signal whichthen allows me to plot both of them against eachother. First forboth signals I would have
to change the signal to an array, clickingon scope parameters and select save data for the workspace and as an
array as well (this is shown in the two images above where both of the scopes were selected to an array). It was
important to remember the variable name as it wouldbe used in the script on Matlab and if it were wrong then
it would come up with error. Below are the codes written to use the arrays and the graph produced from this:
%%creating a file so I am able to see the graphs in Matlab and uses the
%%variables above in the Simulink model
TFscopex = TFscope(:,1);
TFscopey = TFscope(:,2);
plot(TFscopex,TFscopey);
hold on %to compare two models
Differentialx = Differential(:,1);
Differentialy = Differential(:,2);
plot(Differentialx,Differentialy, 'ro');
The second differential signal is the line represented with the red circles while the first order was the blue line.
The x columnwas selected in the first column while the y column was selected in the second column as youcan
see above. Then both x and y coordinates can then be plotted. From the graph I could definitely say that both
models produced the same signals meaning that both models are correct. It shows there are periods of where
there is a flatline and there is no displacement beforeit spikes positively and then negatively. The graph was
created to the specific requirements from the question whichwere the text must be in times new roman and
the dimensions were 17cm wide and 12 cm high.
10
C- Image Processing
a) This question involvedusing image processing on a CT image that was relevant to my student ID (4129406).
As before in 1A, as my last number ends in an even number, I was to be assigned to the data from EXct256from
the CTcoursework.mat. The image number that I was going to be used was calculated by:
Image Number = SID(end)+SID(end-1)
Image Number = 6+0 = 6
In this part of the question I had to determine, using imtool, the CT number of the different structures present
in the CT image of the phantom. I had to firstly write a few lines of code, to one load the data then extract the 6th
image whichI would be using the image processing tool of imtool. This allows me to look at the pixels of the
image and shown below is the code that was implemented along with the image with reference to different
parts of the body shown on the scan.
%%determining the number of different structures
%first load the file and the CT image associated with that number
load('CTcoursework.mat','EXct256');
A=EXct256(:,:,6);
imtool(A);
imshow(A);
The next part of this task was to then determine the number of different structures present in the CT scan. The
only means of doing this was to make a mesh; this shows different layers of the image. First I needed to make a
filter that would allow me to plot the data in 3D form and it was applied to the original image.
%%Applying the mesh tool to identify different layers of the CT scan
figure(3)
subplot(111)
mesh(double(A)) %Using the original CT image Below:showing the different densities and revels
where areas of bone including the spine and the ribs
Lungs
Ribs
Spine
11
Bi) On part b of the question, I had to create an edge detection to obtain the contour of the CT image and to
then plot the contour on the top of the CT. Firstly I had to apply an edge detector of my choice which in this case
was sobel and I then checkedusing the imshow that the edge detector I used enabled me to see the outlines for
the contour of the image. Below is the coding I used forthe edge detection as well as the CT image withthe
sobel filter.
%%edge detection on the image
X = edge(A,'sobel');
figure, imshow(X);
Bii & Biii) The final part of this question involvedtwo tasks, whichwere to use the command regionprops to
obtain the list of pixels corresponding to the edge “PixelList” and then store them as twoarrays called xROI and
yROI.As youcan see from the Matlab code below I used the command regionprops to create the pixel list, this
was then sorted into the twoarrays, one for x axes and one for y axes. These sets of pixels will be important
because I then plotted them on top of the image (A) used at the start as a red line whichappeared mapping the
edges. I noticed that there was a region in whichthey were no pixels and that was due to a gap between the
points so it couldn’t be joined.
%%Using regioprops to identify to obtain the list of pixels corresponding
%%to an edge of a pixel list
B= regionprops(X,'PixelList');
C = B(1).PixelList; %showing where all the points have a grey level 1
xROI=C(:,1); %one array with the x points
yROI=C(:,2); %one
array with the y
points
figure, imshow(A)
hold on
plot(xROI,yROI,'r.')
Left: The CT image contain
pixels round the edge as
shown in red.
The gap in the image causing
to be no pixels plotted in
there so there is no red line
shown.

More Related Content

Similar to Etienne_ME_a241ms

Movimiento circular uniforme aplicado a la maqueta de un ventilador
Movimiento circular uniforme aplicado a la maqueta de un ventiladorMovimiento circular uniforme aplicado a la maqueta de un ventilador
Movimiento circular uniforme aplicado a la maqueta de un ventiladorAlexToavanda
 
JGrass-NewAge probabilities forward component
JGrass-NewAge probabilities forward component JGrass-NewAge probabilities forward component
JGrass-NewAge probabilities forward component Marialaura Bancheri
 
Foundations and methods of stochastic simulation
Foundations and methods of stochastic simulationFoundations and methods of stochastic simulation
Foundations and methods of stochastic simulationSpringer
 
Method for a Simple Encryption of Images Based on the Chaotic Map of Bernoulli
Method for a Simple Encryption of Images Based on the Chaotic Map of BernoulliMethod for a Simple Encryption of Images Based on the Chaotic Map of Bernoulli
Method for a Simple Encryption of Images Based on the Chaotic Map of BernoulliAIRCC Publishing Corporation
 
METHOD FOR A SIMPLE ENCRYPTION OF IMAGES BASED ON THE CHAOTIC MAP OF BERNOULLI
METHOD FOR A SIMPLE ENCRYPTION OF IMAGES BASED ON THE CHAOTIC MAP OF BERNOULLIMETHOD FOR A SIMPLE ENCRYPTION OF IMAGES BASED ON THE CHAOTIC MAP OF BERNOULLI
METHOD FOR A SIMPLE ENCRYPTION OF IMAGES BASED ON THE CHAOTIC MAP OF BERNOULLIijcsit
 
METHOD FOR A SIMPLE ENCRYPTION OF IMAGES BASED ON THE CHAOTIC MAP OF BERNOULLI
METHOD FOR A SIMPLE ENCRYPTION OF IMAGES BASED ON THE CHAOTIC MAP OF BERNOULLIMETHOD FOR A SIMPLE ENCRYPTION OF IMAGES BASED ON THE CHAOTIC MAP OF BERNOULLI
METHOD FOR A SIMPLE ENCRYPTION OF IMAGES BASED ON THE CHAOTIC MAP OF BERNOULLIAIRCC Publishing Corporation
 
BS LAB Manual (1).pdf
BS LAB Manual  (1).pdfBS LAB Manual  (1).pdf
BS LAB Manual (1).pdfssuser476810
 
Signals And Systems Lab Manual, R18 Batch
Signals And Systems Lab Manual, R18 BatchSignals And Systems Lab Manual, R18 Batch
Signals And Systems Lab Manual, R18 BatchAmairullah Khan Lodhi
 
Simple Pendulum Experiment and Automatic Survey Grading using Computer Vision
Simple Pendulum Experiment and Automatic Survey Grading using Computer VisionSimple Pendulum Experiment and Automatic Survey Grading using Computer Vision
Simple Pendulum Experiment and Automatic Survey Grading using Computer VisionAnish Patel
 
M166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docx
M166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docxM166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docx
M166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docxinfantsuk
 
Digital Signal Processing Lab Manual
Digital Signal Processing Lab Manual Digital Signal Processing Lab Manual
Digital Signal Processing Lab Manual Amairullah Khan Lodhi
 
MATLAB review questions 2014 15
MATLAB review questions 2014 15MATLAB review questions 2014 15
MATLAB review questions 2014 15chingtony mbuma
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxanhlodge
 
EE380-4 Course project Experimental determination of a Ser.docx
EE380-4  Course project Experimental determination of a  Ser.docxEE380-4  Course project Experimental determination of a  Ser.docx
EE380-4 Course project Experimental determination of a Ser.docxjack60216
 

Similar to Etienne_ME_a241ms (20)

Eigenfaces
EigenfacesEigenfaces
Eigenfaces
 
Movimiento circular uniforme aplicado a la maqueta de un ventilador
Movimiento circular uniforme aplicado a la maqueta de un ventiladorMovimiento circular uniforme aplicado a la maqueta de un ventilador
Movimiento circular uniforme aplicado a la maqueta de un ventilador
 
Lab03
Lab03Lab03
Lab03
 
Laboratory 7
Laboratory 7Laboratory 7
Laboratory 7
 
JGrass-NewAge probabilities forward component
JGrass-NewAge probabilities forward component JGrass-NewAge probabilities forward component
JGrass-NewAge probabilities forward component
 
Foundations and methods of stochastic simulation
Foundations and methods of stochastic simulationFoundations and methods of stochastic simulation
Foundations and methods of stochastic simulation
 
Method for a Simple Encryption of Images Based on the Chaotic Map of Bernoulli
Method for a Simple Encryption of Images Based on the Chaotic Map of BernoulliMethod for a Simple Encryption of Images Based on the Chaotic Map of Bernoulli
Method for a Simple Encryption of Images Based on the Chaotic Map of Bernoulli
 
METHOD FOR A SIMPLE ENCRYPTION OF IMAGES BASED ON THE CHAOTIC MAP OF BERNOULLI
METHOD FOR A SIMPLE ENCRYPTION OF IMAGES BASED ON THE CHAOTIC MAP OF BERNOULLIMETHOD FOR A SIMPLE ENCRYPTION OF IMAGES BASED ON THE CHAOTIC MAP OF BERNOULLI
METHOD FOR A SIMPLE ENCRYPTION OF IMAGES BASED ON THE CHAOTIC MAP OF BERNOULLI
 
METHOD FOR A SIMPLE ENCRYPTION OF IMAGES BASED ON THE CHAOTIC MAP OF BERNOULLI
METHOD FOR A SIMPLE ENCRYPTION OF IMAGES BASED ON THE CHAOTIC MAP OF BERNOULLIMETHOD FOR A SIMPLE ENCRYPTION OF IMAGES BASED ON THE CHAOTIC MAP OF BERNOULLI
METHOD FOR A SIMPLE ENCRYPTION OF IMAGES BASED ON THE CHAOTIC MAP OF BERNOULLI
 
BS LAB Manual (1).pdf
BS LAB Manual  (1).pdfBS LAB Manual  (1).pdf
BS LAB Manual (1).pdf
 
Laboratorio vibra
Laboratorio vibraLaboratorio vibra
Laboratorio vibra
 
Signals And Systems Lab Manual, R18 Batch
Signals And Systems Lab Manual, R18 BatchSignals And Systems Lab Manual, R18 Batch
Signals And Systems Lab Manual, R18 Batch
 
Simple Pendulum Experiment and Automatic Survey Grading using Computer Vision
Simple Pendulum Experiment and Automatic Survey Grading using Computer VisionSimple Pendulum Experiment and Automatic Survey Grading using Computer Vision
Simple Pendulum Experiment and Automatic Survey Grading using Computer Vision
 
Bode
BodeBode
Bode
 
M166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docx
M166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docxM166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docx
M166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docx
 
Digital Signal Processing Lab Manual
Digital Signal Processing Lab Manual Digital Signal Processing Lab Manual
Digital Signal Processing Lab Manual
 
MATLAB review questions 2014 15
MATLAB review questions 2014 15MATLAB review questions 2014 15
MATLAB review questions 2014 15
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
 
EE380-4 Course project Experimental determination of a Ser.docx
EE380-4  Course project Experimental determination of a  Ser.docxEE380-4  Course project Experimental determination of a  Ser.docx
EE380-4 Course project Experimental determination of a Ser.docx
 
Mechanical Engineering Assignment Help
Mechanical Engineering Assignment HelpMechanical Engineering Assignment Help
Mechanical Engineering Assignment Help
 

Etienne_ME_a241ms

  • 1. 1 A241MS- Matlab and Simulink for Science and Engineering Research Coursework Coventry University Michael James Etienne SID: 4129406
  • 2. 2 Table of Contents A. Case Study A 1 a) Part a.........................................................................................................................................3 b) Part b.........................................................................................................................................4 B. Question A 2 creating a Matlab Function a) Part a..........................................................................................................................................5 b) Part b..........................................................................................................................................5 c) Part c..........................................................................................................................................5 d) Part d..........................................................................................................................................6 C. B2 Simulink a) B1...............................................................................................................................................7 b) B2c .............................................................................................................................................7 c) B2d............................................................................................................................................7 d) B2e.........................................................................................................................................8 & 9 D. C Image Processing a) Part a........................................................................................................................................10 b) Part b........................................................................................................................................11
  • 3. 3 A case study 1 a) As relevant to the question criteria my answers willbe in relation to the data supplemented fromgroup 1. Firstly I loaded the data fromM1_video fromthe respiratory data and displayed it below in a figure showing the data plotted in relation to amplitude (cm)and time (samples) for the whole data. To only select the M1_videoand not load any other data I implemented this code: %%loading the data specifically the M1_video and plotting 3 cycles %%specific to my student ID load('RespiratoryData2013.mat','M1_video') bi) The next part of the question was to extract 3 cyclesof data from the graph. To do this I had to create a Matlab code,which wouldselect the data within the 3 cyclesand it was unique for every person. This was your last digit in yourID+1. In my case this was 6+1=7 meaning I had to extract 3 cyclesof data from the fourth cycle.For this I used the followingcode to extract the 3 cyclesworthof data and plot it. This was named ME3. ME3 = M1_video(1,145:230); The result from using this codeto select this particular data and then plotting it gives the figure below.
  • 4. 4 bii) The three cyclesof data are then normalised so that it will begin at 0. Implementing this code below does this and it brings all the points down. I worked this out by looking at the first point (145) on the graph, which showed it to be 4.315. This was subtracted fromall the points to bring them all downby the same value. This data was then plotted again against the same axis and this produces the graph below: %%Normalising the 3 cycle so it begins at 0,0 A = M1_video(1,145); figure, plot(ME3-A); biii) The time vectorfor this question, which can be used to correspond with the 10Hz sampling time and in with the same length of the 3 cycles,is: %%Creating the time vector for the data fs = 10; Ts = 1/fs; TimeVector = [0:Ts:8.5]; %difference between 14.5-24 seconds M = ME3-A; figure, plot(TimeVector,M) The reason that 0.1 is used as the time sampling is that 10Hz is the sampling time and from the graph above this time is used from 0 to 8.5 as this is the time for3 cyclesto occur in-between 14.5-23 seconds which was calculated from the frequency being 10Hz=0.1 second, e.g. 145/0.1=14.5. biv & bv) Now applying the time vectorto the data and then plotting it with relevant axis gives the graph below. The axis were labeled in correspondence to the data which was the amplitude, this was in relation to the height of chest as it rose up and down when the person was breathing. The x-axis is the time period where the breathing was taking place. To edit the axis’s you clickon the insert tab on the top and scroll down to x or y label. The size and font of the writing of the axes can be edited at the bottom of the page as well as colour and other features to make the graph more interesting or eye grabbing.
  • 5. 5 A2 Creating a Matlab Function and fitting to data a) For this question I had to create a functionwith a formula to model the respiratory motion. The function implemented the followingformula: 𝑦(𝑡) = 𝑌𝑜𝑓𝑓𝑠𝑒𝑡 − 𝐴 ∗ 𝑐𝑜𝑠2𝑛( 𝜋𝑡 𝑇 ) With the inputs being: 𝑌𝑜𝑓𝑓𝑠𝑒𝑡 , A ,n ,T ,t and the outputs being: y(t).Along withthis I then created a Matlab Function incorporating this formula to create a coswavewhichwas plotted in the time vectorwhichwas t = (0: 0.1 : 8.5) whichwas used in A1.b.iii . Below was the Matlab Function, whichI implemented and then provided comments to make sure that I understood every step function Y= fctME(Yoffset,T,t,A,n) %creating a function that can be implemented and shows the inputs of this function Y = Yoffset-A*cos(pi*t/T).^(2*n); %formula which is used in the function %creating the function which the different inputs are linked to my SID Yoffset= 3.6; %3.SID which ends in a 6 t= (0:0.1:8.5); %the time vector previously defined in 1A for the 3 cycles of data T= 4.6; %4.SID which ends in a 6 A= 2.6; %2.SID which ends in a 6 n= 4;%given as 4 as my last number of my SID is an even number bi) I then moved onto creating the mfile that wouldcall this functionand creating the coswaveassociated with this formula. I had to define all the variables in the mfile. This is shown below: %%Initilisation A = 2.6; Yoffset = 3.6; T = 4.6; t = (0:0.1:8.5); n = 4; bii, biii) After this I then had to call the function into this mfile to calculatey(t) using the time vectorfromthe pervious question A1.b.iii. The time vectorused was t = (0: 0.1 : 8.5). Once the time vectorwas implemented and the function is called in the mfile, I was then able to plot the graph that is shown below. c) I then plotted this waveon top of my data but it became my y(est) as I reduced the amplitude in line withthe data so it became the estimate wave of the respiratory data. Toreduce the amplitude, the value A was reduced to be equal to the maximum value of A of the data, for my workthis was 0.8685. This was then plotted in a graph, whichis shown at the top of the next page with the relevant script workalong with it.
  • 6. 6 %%Initilisation A = 0.8685; this is the new value of the amplitude for the y(est) to fall in line with the y(t) Yoffset = 3.6; T = 4.6; t = (0:0.1:8.5); n = 4; %%plot the result figure(2) plot(TimeVector,Y-2.747,'ro');%normalise y(t) in relation to the function fctME hold on load('RespiratoryData2013.mat','M1_video') ME3 = M1_video(1,145:230); %using the previous 3 cycles of data from A1 A = M1_video(1,145); M =ME3-A; plot(TimeVector,M);%normalise this y(est) and then is plotted along with the fctME.m % create a string what will be displayed at the top of the figure (graph) title('3 cycles of respiratory data') % same but using num2str to display the value of f as opposed to the letter title('3 cycles of respiratory data') xlabel ('Time[s]') ylabel ('Amplitdue[cm]') d) Above is the fully documented plot containing two times of data including the y(t) (blue line) whichis the actual data fromprevious question, refer backto 1A, and the y(est) (red dotted line) whichis the function created in this question which includes the inputs; A, T, t, Yoffset. Left: This part of the script was used to create the titles on my figure including the two axes. If I wanted to change them at any time I would simply change it here and not have the trouble of doing it on the figure.
  • 7. 7 B2 Simulink B1) This question involvedusing the programme Simulink to model a free body diagram where different forcesare acting on a mass. With this model you have a transfer functionthat is used in first order model and it is given by: 𝑌(𝑠) 𝐹(𝑠) = 1 𝑀𝑠2 + 𝐵𝑠 + 𝐾 The variables used in this model are given as:  M = 300kg  B = 16000N/m  K = 1400 whichdoesn’t have a unit For these variables to be implemented into the models I had to create an initialisation file on Matlab that could be used to drive the model and also produce the signals. Below was the Initialisation file I created on Matlab to be used throughout this question, where the variables were also stated. %%Initialisation file used for the simulink model on question B M = 300; %measured in kg K = 16000; %measured in N/m B = 1400; %no value stated in the question This also included the amplitude at the value of 1000 and I chose the frequency tobe 0.2. This was chosen as I felt it gave me the correct sampling time in which I couldcapture all the dynamics created by the model. If it was any greater then it wouldn’t be clear enough or if it was any smaller I feltyou wouldn’t be capturing anything and would be seeing a small section of it. These twovariables will remain constant throughout the question. B2c) The next part of the question involved using the initialisation file and creating a first order model that in turn should create a signal with a square wave frequency.The model I created involveda signal generator, a transfer functionand scope. This is the model shown below: This was quite a simple model to create on simulink as it was just a second order with a transfer functionand once the variables were ran on Matlab as well as the model, the signal produced was this shown below. Ihad to also alter parameters on the model by changing the tolerance to 7 instead of 3 because this makes it a smoother curveas well as changing the maximum step to 100. Changing the step saves changing the zoomon the screen. Above: Screenshot of the history of how the model was constructed in Simulink
  • 8. 8 Youcan see as well there are areas of overdamping where the line goes above0 and there are areas of over damping which are points that are below 0. B2d) As well as using this model to produce this signal it can also be produced from a rearranged differential in a model. This is done when using an equation with the highest order of the differential equation being expressed as a functionof lowerorders. By this I mean that the original differential equation can be rearranged as: 𝑓( 𝑡) = 𝑀 𝑑2 𝑦(𝑡) 𝑑𝑡2 + 𝐵 𝑑𝑦(𝑡) 𝑑𝑡 + 𝐾𝑦( 𝑡) → 𝑑2 𝑦(𝑡) 𝑑𝑡2 = 1 𝑀 𝑓( 𝑡) − 𝐵 𝑀 𝑑𝑦( 𝑡) 𝑑𝑡 − 𝐾 𝑀 𝑦(𝑡) From this equation I am able to constructanother simulink model based around the first order model. This would be seen as a second order model as it would be in the transfer functionfrom the previous model. This was slightly trickier to construct. The only way in whichI could tell if I had constructed correctly wasif the output signal in the scope was identical to the first model scope. Below is the model that I created on simulink in relation to the differential equation. This model involvedmore blocks fromthe library including a gain, integrators and a summing junction. The same variables were used in this model as well and fromthis the signal produced from the scope was equal to the first model. The signal produced is shown below: Above: Changing the scope to an array for the Matlab and giving it a variable name
  • 9. 9 B2e) Now to clarify that both of my signals from both the signals are identical and the models are both correct,I would have to plot both signals onto one signal graph. To do this I wouldhave to create a Matlab script to allow me to plot the graph but before this I wouldhave to create arrays for the x points and y points for every signal whichthen allows me to plot both of them against eachother. First forboth signals I would have to change the signal to an array, clickingon scope parameters and select save data for the workspace and as an array as well (this is shown in the two images above where both of the scopes were selected to an array). It was important to remember the variable name as it wouldbe used in the script on Matlab and if it were wrong then it would come up with error. Below are the codes written to use the arrays and the graph produced from this: %%creating a file so I am able to see the graphs in Matlab and uses the %%variables above in the Simulink model TFscopex = TFscope(:,1); TFscopey = TFscope(:,2); plot(TFscopex,TFscopey); hold on %to compare two models Differentialx = Differential(:,1); Differentialy = Differential(:,2); plot(Differentialx,Differentialy, 'ro'); The second differential signal is the line represented with the red circles while the first order was the blue line. The x columnwas selected in the first column while the y column was selected in the second column as youcan see above. Then both x and y coordinates can then be plotted. From the graph I could definitely say that both models produced the same signals meaning that both models are correct. It shows there are periods of where there is a flatline and there is no displacement beforeit spikes positively and then negatively. The graph was created to the specific requirements from the question whichwere the text must be in times new roman and the dimensions were 17cm wide and 12 cm high.
  • 10. 10 C- Image Processing a) This question involvedusing image processing on a CT image that was relevant to my student ID (4129406). As before in 1A, as my last number ends in an even number, I was to be assigned to the data from EXct256from the CTcoursework.mat. The image number that I was going to be used was calculated by: Image Number = SID(end)+SID(end-1) Image Number = 6+0 = 6 In this part of the question I had to determine, using imtool, the CT number of the different structures present in the CT image of the phantom. I had to firstly write a few lines of code, to one load the data then extract the 6th image whichI would be using the image processing tool of imtool. This allows me to look at the pixels of the image and shown below is the code that was implemented along with the image with reference to different parts of the body shown on the scan. %%determining the number of different structures %first load the file and the CT image associated with that number load('CTcoursework.mat','EXct256'); A=EXct256(:,:,6); imtool(A); imshow(A); The next part of this task was to then determine the number of different structures present in the CT scan. The only means of doing this was to make a mesh; this shows different layers of the image. First I needed to make a filter that would allow me to plot the data in 3D form and it was applied to the original image. %%Applying the mesh tool to identify different layers of the CT scan figure(3) subplot(111) mesh(double(A)) %Using the original CT image Below:showing the different densities and revels where areas of bone including the spine and the ribs Lungs Ribs Spine
  • 11. 11 Bi) On part b of the question, I had to create an edge detection to obtain the contour of the CT image and to then plot the contour on the top of the CT. Firstly I had to apply an edge detector of my choice which in this case was sobel and I then checkedusing the imshow that the edge detector I used enabled me to see the outlines for the contour of the image. Below is the coding I used forthe edge detection as well as the CT image withthe sobel filter. %%edge detection on the image X = edge(A,'sobel'); figure, imshow(X); Bii & Biii) The final part of this question involvedtwo tasks, whichwere to use the command regionprops to obtain the list of pixels corresponding to the edge “PixelList” and then store them as twoarrays called xROI and yROI.As youcan see from the Matlab code below I used the command regionprops to create the pixel list, this was then sorted into the twoarrays, one for x axes and one for y axes. These sets of pixels will be important because I then plotted them on top of the image (A) used at the start as a red line whichappeared mapping the edges. I noticed that there was a region in whichthey were no pixels and that was due to a gap between the points so it couldn’t be joined. %%Using regioprops to identify to obtain the list of pixels corresponding %%to an edge of a pixel list B= regionprops(X,'PixelList'); C = B(1).PixelList; %showing where all the points have a grey level 1 xROI=C(:,1); %one array with the x points yROI=C(:,2); %one array with the y points figure, imshow(A) hold on plot(xROI,yROI,'r.') Left: The CT image contain pixels round the edge as shown in red. The gap in the image causing to be no pixels plotted in there so there is no red line shown.