You are on page 1of 8

Mackenzie Andrews

BIOEN 316
April 6, 2016

Homework 1

Problem B1

a) Import Samples

Explanation
The first line reads the csv file downloaded on the computer and the next three
lines pull out the data for leads I, II, and III into separate column vectors.

b) Mean Processing

Explanation
In order to take the mean of the half second of data around each point, the 250
points preceding and following any given point must be added, and divided by
500. Since the beginning points don’t have 250 numbers before them, and the
last points don’t have 250 numbers after them, the data must be padded by 250
zeros on either end to perform the running average calculation.

Explanation
The first for-loop processes the first 250 points and takes the mean of the
appropriate amount of numbers so that the 0s at the beginning of the data don’t
contribute to a decrease in the mean. The second for-loop takes the mean
between the 251st and 19,750th point taking the average of the 250 points
before and after the point being processed. The final for loop takes the mean of
the last 250 points, similarly to the first loop. Those means are subtracted from
the point being processed and the adjusted number is put into a new running
average adjusted data vector.
(This is an example of the code for lead I, the same for-loops were repeated for
leads II and III)

Plot of the original and mean processed data for leads I, II, and III (first 5
seconds). The shift is most apparent for leads II and III where the original mean
was around negative 1 and the processed data mean is close to 0.

c) Plot Heart Vector of Lead II vs Lead I

Explanation
The first 2 lines of code use the trig derivation (shown below) to create vectors
containing information of the angle (theta) and radius (Vh12) of the heart vector
to be plotted in the following 3 lines of code (first 5 seconds).
Trig derivation for Lead II vs Lead I

d) Plot Heart Vector of Lead III vs Lead I

Explanation
The first 2 lines of code use the trig derivation (shown below) to create vectors
containing information of the angle (theta) and radius (Vh13) of the heart vector
to be plotted in the following 3 lines of code (first 5 seconds).
Trig Derivation for Lead III vs Lead I

Comparison of II vs I and III vs I

The plots for Lead II vs Lead I and Lead III vs Lead I may be slightly different
because:
a) The leads may not be placed on the body in a perfect equilateral triangle
so the actual angle between any 2 lead vectors may not be perfectly 60
degrees. If the angle between I and II is different from the angle between I
and III, the plots may be slightly off from one another.
b) If either lead II or lead III have variable resistance or noise, the measured
signal will be slightly off from the actual signal from the heart. The lead
vector may be slightly shorter or longer in magnitude making the plot
slightly off when compared to the other.
Comparison with Unhealthy Heart

All of the code above was completed for healthy patient #104. I then repeated my
code for unhealthy patient #1 and compared the results graphically.
I generated plots of Lead II vs Lead I and Lead III vs Lead I for both a healthy
heart (patient 104) and an unhealthy heart (patient 1).The MATLAB generated
figure for the 4 plots are shown below.

The healthy patient’s heart vector graph is confined to the 4th quadrant and has
a smooth egg-like shape that remains consistent for each heart beat.
The unhealthy patient has a condition called cardiomyopathy which causes the
heart muscle to become enlarged, thick or rigid which in turn causes irregular
electrical rhythms called arrhythmias. The plot of this patient's heart vector is very
irregular and has components in all 4 quadrants.

Problem B2

● Input voltage: ±16 mV ---> Voltage range = 32 mV


● Resolution: 16 bit with 0.5 μV/LSB

Resolution (q) = voltage range/2​b ​ where b is the number of bits

Voltage range = 2​b​q ---> q = .5 μV, b = 16


Voltage range = 2​16​(.5*10​-6 ​V)
Voltage range = .03276V = 32.7 mV
MATLAB Code

%Part a - Import Data

%Import samples - Patient 104


samplesH = csvread('sampleshealthy.csv',2,1);

lead1 = samplesH(:,1);
lead2 = samplesH(:,2);
lead3 = samplesH(:,3);

%Part b - Mean Processing

%Add 0 padding to lead data


padlead1 = [zeros(250,1);lead1;zeros(250,1)];
padlead2 = [zeros(250,1);lead2;zeros(250,1)];
padlead3 = [zeros(250,1);lead3;zeros(250,1)];

%process lead1
avglead1 = zeros(10000,1);
for i = 251:500
set = padlead1(i-250:i+250);
tot = sum(set);
mean = tot/(i-1);
diff = padlead1(i)-mean;
avglead1(i-250) = diff;
end

for i = 501:10000
set = padlead1(i-250:i+250);
tot = sum(set);
mean = tot/500;
diff = padlead1(i)-mean;
avglead1(i-250) = diff;
end

for i = 10001:10250
set = padlead1(i-250:i+250);
tot = sum(set);
mean = tot/(10500-i);
diff = padlead1(i)-mean;
avglead1(i-250) = diff;
end

%process lead2
avglead2 = zeros(10000,1);
for i = 251:500
set = padlead2(i-250:i+250);
tot = sum(set);
mean = tot/(i-1);
diff = padlead2(i)-mean;
avglead2(i-250) = diff;
end

for i = 501:10000
set = padlead2(i-250:i+250);
tot = sum(set);
mean = tot/500;
diff = padlead2(i)-mean;
avglead2(i-250) = diff;
end

for i = 10001:10250
set = padlead2(i-250:i+250);
tot = sum(set);
mean = tot/(10500-i);
diff = padlead2(i)-mean;
avglead2(i-250) = diff;
end

%process lead3
avglead3 = zeros(10000,1);
for i = 251:500
set = padlead3(i-250:i+250);
tot = sum(set);
mean = tot/(i-1);
diff = padlead3(i)-mean;
avglead3(i-250) = diff;
end

for i = 501:10000
set = padlead3(i-250:i+250);
tot = sum(set);
mean = tot/500;
diff = padlead3(i)-mean;
avglead3(i-250) = diff;
end

for i = 10001:10250
set = padlead3(i-250:i+250);
tot = sum(set);
mean = tot/(10500-i);
diff = padlead3(i)-mean;
avglead3(i-250) = diff;
end

%Create time vector


time = [.001:.001:10];

%Plot original and mean processed data for lead I


subplot(3,1,1)
plot(time(0:.001:5000),lead1(0:.001:5000)); hold on;
plot(time(0:.001:5000),avglead1(0:.001:5000));
title('Original vs. Mean Processed Data - Lead I');
legend('Original','Mean Processed');
xlabel('time (s)');
ylabel('Voltage (mV)');

%Plot original and mean processed data for lead II


subplot(3,1,2)
plot(time(0:.001:5000),lead2(0:.001:5000)); hold on;
plot(time(0:.001:5000),avglead2(0:.001:5000));
title('Original vs. Mean Processed Data - Lead II');
legend('Original','Mean Processed');
xlabel('time (s)');
ylabel('Voltage (mV)');

%Plot original and mean processed data for lead III


subplot(3,1,3)
plot(time(0:.001:5000),lead3(0:.001:5000)); hold on;
plot(time(0:.001:5000),avglead3(0:.001:5000));
title('Original vs. Mean Processed Data - Lead III');
legend('Original','Mean Processed');
xlabel('time (s)');
ylabel('Voltage (mV)');

%Part c - Plot Heart Vector of Lead II vs Lead I

theta12 = -atan((2/sqrt(3))*(avglead2./avglead1)-(1/sqrt(3)));
Vh12 = avglead1./(cos(theta12));

%plot
subplot(2,2,1)
polarplot(theta12(1:5000),Vh12(1:5000))
title('Leads I & II Healthy')

%Part d - Plot Heart Vector of Lead III vs Lead I

theta13 = -atan((2/sqrt(3))*(avglead3./avglead1)+(1/sqrt(3)));
Vh13 = avglead1./(cos(theta13));

%plot
subplot(2,2,2)
polarplot(theta13(1:5000),Vh13(1:5000))
title('Leads I & III Heathy')

You might also like