Repository navigation
Expand file tree
/
Copy pathAUCStartFinder.m
More file actions
34 lines (30 loc) · 1.51 KB
/
Copy pathAUCStartFinder.m
File metadata and controls
34 lines (30 loc) · 1.51 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
% AHPstart_time = Results(sweep).AHPstart_time
function [AUCstartidx] = AUCStartFinder(data,si,bl,startsearch)
start_idx = startsearch; %startsearchtime/(si/1000); being the search at the stop idx of baseline
% start_idx = str2double(sprintf('%16.f',start_idx));
% if ~isempty(AHPstart_idx) % if there is an AHPstart - but you can do this in the script
numconsecreturn = 10/(si/1000);
aboveblidx = find(data(start_idx:end) >= bl); % find data points above baseline after start_idx
if ~isempty(aboveblidx) && length(aboveblidx) > numconsecreturn % if there are points above
diffbtwn = diff(aboveblidx); % if consecutive bins are above threshold, diff should be 1 for each
possible = [];
counter = 1;
while isempty(possible)
if sum(diffbtwn(counter:counter+numconsecreturn-1)) == numconsecreturn
possible = counter;
end
counter = counter + 1;
if counter >= length(diffbtwn)-numconsecreturn
break
end
end
if ~isempty(possible) % if there is AUC start point that meets criteria
AUCstartidx = start_idx+aboveblidx(possible);
else % if there isn't an AUC start idx
figure, plot(data) % to show why
error('Could not detect AUC start idx');
end
else
error('Not enough data points are above baseline for specified minimum duration to detect AUC start idx')
end
end