-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_latencyfrompeak.m
124 lines (100 loc) · 3.91 KB
/
get_latencyfrompeak.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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
function [platencies]=get_latencyfrompeak(trials,peaks,type,info,alpha)
%function [latencies]=get_latencyfrompeak(trials,peaks,type,alpha)
% get latency of burst of activity in trials starting from peak activity
%
% type: 'spk' or 'lfp'
%
% see also get_latency get_peakfromlatency
%
% Corentin Massot
% Cognition and Sensorimotor Integration Lab, Neeraj J. Gandhi
% University of Pittsburgh
% created 11/09/2016 last modified 07/24/2017
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
debug=0;
%time ttest stays positive
pos_time=1;
%dprime values
switch info.align
case 'targ'
dprime_spk=1;
dprime_lfp=1;
winsearch=60
case 'sacc'
dprime_spk=1;
dprime_lfp=1;
winsearch=30;
end
[nchannels ~]=size(trials);
H=zeros(nchannels,1);
platencies=zeros(nchannels,3);
platencies(:,2)=1;
if debug,
histo=nan(winsearch,2);
end
%trials_w=zeros(nchannels,winsearch);
for ch=1:nchannels
%check peak
%if peaks(ch,1)>winsearch/2+1+1
if peaks(ch,1)>3*winsearch/4+1+1
%peak window
%peak_w=trials(ch,peaks(ch,1)-winsearch/2+1:peaks(ch,1)+winsearch/2);
peak_w=trials(ch,peaks(ch,1)-floor(3*winsearch/4)+1:peaks(ch,1)+winsearch/3);
for w=peaks(ch,1):-1:winsearch+1
trials_w=trials(ch,w-winsearch+1:w);
if platencies(ch,1)~=pos_time,%channel did not reach significance for pos_time
if debug
%plot
hdlfig=figure;
subplot(1,2,1);hold on;
plot(1:winsearch,trials_w(:),'b');
plot(1:winsearch,peak_w(:),'r');
%histo
subplot(1,2,2);hold on;
histo(:,1)=trials_w(:)';
histo(:,2)=peak_w(:)';
edges=[-50:10:250];
hist=histc(histo,edges);
bar(edges,hist,'histc')
end
%one tailed ttest
switch type
case 'spk'
%H(ch)=ttest2(trials_w(:),peak_w(:),'alpha',alpha,'tail','left');
%[P(ch) H(ch)]=ranksum(trials_w(ch,:),peaks(ch,:),'alpha',alpha);
H(ch)=compute_dprime(trials_w(:),peak_w(:),dprime_spk);
case 'lfp'
%H(ch)=ttest2(trials_w(:),peak_w(:),'alpha',alpha,'tail','both');
%[P(ch) H(ch)]=ranksum(trials_w(ch,:),peaks(ch,:),'alpha',alpha);
H(ch)=compute_dprime(trials_w(:),peak_w(:),dprime_lfp);
end
if H(ch)==1
%count
platencies(ch,1)=platencies(ch,1)+1;
if platencies(ch,1)==1
%latency
platencies(ch,2)=w-round(winsearch/2);
%magnitude at latency
platencies(ch,3)=mean(trials_w(:));
end
else
platencies(ch,1)=0;
platencies(ch,2)=1;
platencies(ch,3)=0;
end
% display(['H of ch ' num2str(ch) ' :' num2str(H(ch))]);
if debug
ch
platencies(ch,:)
pause
%close(hdlfig)
end
end
end
%check if all latencies have been found
if sum(platencies(:,1)~=pos_time)==0,
% w
return;
end
end
end