-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAPD.m
More file actions
79 lines (62 loc) · 1.72 KB
/
APD.m
File metadata and controls
79 lines (62 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
function [APD90, DI, locs, APD90Times, APD90Values, pks] = APD(APData, APTime)
% Determine peak AP value
[pks, locs] = findpeaks(APData, APTime, 'MinPeakProminence', 50);
TimeIndices = zeros(length(locs) + 1, 1);
for i = 1:length(locs)
for j = 1:length(APTime)
if APTime(j) == locs(i)
TimeIndices(i) = j;
end
end
end
TimeIndices(length(TimeIndices)) = length(APTime);
% Preallocate arrays to contain the values and times of the closest values to
% 90% of each peak value
APD90Values = zeros(length(pks), 1);
APD90Times = zeros(length(pks), 1);
% Find the index of the closest value to 90% of the peak value for each
% element of the pks array
i = 1;
for i = 1:length(pks)
% while i < length(pks)
% locs
% pks
% i
% if i > length(pks)
% break
% end
AP90 = pks(i)*0.1;
minDistance = pks(i);
for j = TimeIndices(i):TimeIndices(i + 1) %- 1
if abs(APData(j) - AP90) < minDistance
APD90Values(i) = APData(j);
APD90Times(i) = APTime(j);
minDistance = abs(APData(j) - AP90);
end
end
% i = i + 1;
if minDistance > pks(i)*0.05
pks(i) = [];
APD90Values(i) = [];
APD90Times(i) = [];
locs(i) = [];
% TimeIndices(i) = [];
% i = i - 1;
end
end
%Compute the differences in times between each element in APD90Times and
%locs to find the Action Potential Duration
APD90 = APD90Times - locs;
% Find the periods between AP peaks
Periods = zeros(length(locs), 1);
for i = 2:length(locs)
Periods(i - 1) = locs(i) - locs(i - 1);
end
% Find the Diastolic Interval, DI for each period of the AP
DI = Periods - APD90;
DI(length(DI)) = [];
APD90(1) = [];
% DI
% APD90
% locs
end