-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathADPend.m
More file actions
43 lines (39 loc) · 2.01 KB
/
ADPend.m
File metadata and controls
43 lines (39 loc) · 2.01 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
function [output] = ADPend(data,si,bl,FAHPstart_time)
FAHPstart_idx = FAHPstart_time/(si/1000);
FAHPstart_idx = str2double(sprintf('%16.f',FAHPstart_idx));
numconsecreturn = 10/(si/1000);
returnADPbelowblidx = find(data(FAHPstart_idx:end) <= bl); % find data points below baseline after FAHPstart_idx
if ~isempty(returnADPbelowblidx) % if there are points below
returnADPdiffbtwn = diff(returnADPbelowblidx); % if consecutive bins are below threshold, diff should be 1 for each
returnADPpossible = [];
counter = 1;
while isempty(returnADPpossible)
if sum(returnADPdiffbtwn(counter:counter+numconsecreturn-1)) == numconsecreturn
returnADPpossible = counter;
end
counter = counter + 1;
if counter >= length(returnADPdiffbtwn)-numconsecreturn
break
end
end
if ~isempty(returnADPpossible) % if there is ADP end point that meets criteria
ADPend_time = FAHPstart_idx+returnADPbelowblidx(returnADPpossible);
else % if there isn't an AHP end point
ADPend_time = length(data);
end
ADPend_amplitude = data(ADPend_time);
ADPduration = ADPend_time - FAHPstart_idx;
ADP_AUC = trapz(abs(data(FAHPstart_idx:ADPend_time)-bl)); % area under the curve using trapezoidal numerical integration
output.ADPend_time = ADPend_time*(si/1000);
output.ADPend_idx = ADPend_time;
output.ADPend_amplitude = ADPend_amplitude;
output.ADPduration = ADPduration*(si/1000);
output.ADP_AreaUnderCurve = (ADP_AUC*(si/1000))/1000;
else
output.ADPend_idx = length(data);
output.ADPend_time = output.ADPend_idx*(si/1000);
output.ADPend_amplitude = data(output.ADPend_idx);
output.ADPduration = output.ADPend_time - FAHPstart_time;
output.ADP_AreaUnderCurve = ((trapz(abs(data(FAHPstart_idx:output.ADPend_idx))))*(si/1000))/1000;
end
end