-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfind_time_to_peak.m
33 lines (29 loc) · 1.02 KB
/
find_time_to_peak.m
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
function [p, slopes, highest_peaks] = find_time_to_peak(R, RT_tp)
%Loop through different traces of same animal, same condition
p = [];
slopes = [];
%high_peak = [];
for i = 1:size(R,1)
if RT_tp(i) >0
trace = R(i,:);
trace_of_interest = R(i,200:300);
figure; hold on; plot(trace)
ylim([0 100])
[p, idx] = findpeaks(trace_of_interest, 'MinPeakProminence',0);
highest_peaks(i) = max(p);
delay = 200;
if isempty(idx)
Warning('no peak')
else
%Loop through different peaks and plot them (to do quality check)
for j =1:length(idx)
hold on; plot(idx(j)+delay, trace(idx(j)+delay), 'k*')
%trace lines passing from RT point to peak(s)
hold on; plot([RT_tp(i) idx(j)+delay], [trace(RT_tp(i)) trace(idx(j)+delay)], '-.r', 'LineWidth',3)
%compute slope between points
slopes(i,j) = (trace(idx(j)+delay) - trace(RT_tp(i)))./(idx(j)+delay - RT_tp(i));
end
end
end
end
%highest_peaks = max(p, [], 2);