-
Notifications
You must be signed in to change notification settings - Fork 0
/
Salvatore_AlignBehPhotoM.m
69 lines (35 loc) · 1.98 KB
/
Salvatore_AlignBehPhotoM.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
function [TrialTimingData_aligned,lag] = Salvatore_AlignBehPhotoM(TrialTimingData,SynchData,sample_rate)
%Align times from Behaviour and photoM datafile (regression of reward analog time and reward time in the beh block file)
% Armin Dec 2017
reward_Times = SynchData';
% Think about this timing issue
if length(reward_Times) > length(TrialTimingData(TrialTimingData(:,9)==1,14))
reward_Times(end) = []; % we ignore the last trial
end
figure; hold on
plot(diff(reward_Times),'r')
plot(0.1 + diff((TrialTimingData(TrialTimingData(:,9)==1,14))),'b')
legend('analog','TrialTimingData')
ylabel('inter event interval')
%a=TrialTimingData(TrialTimingData(:,9)==1,14);
%s=regstats(reward_Times(4:30),a(4:30,:)); % find the time lag between beh file and neuronal file (regress water delivery time)
s=regstats(reward_Times,TrialTimingData(TrialTimingData(:,9)==1,14)); % find the time lag between beh file and neuronal file (regress water delivery time)
lag = s.beta(1) % neuronal data preceding beh data with this lag
TrialTimingData_aligned(:,[10, 12:14, 16]) = TrialTimingData(:,[10, 12:14, 16]) + lag;
%unacounted_lag = nanmean(reward_Times(1:50)' - a(50))
unacounted_lag = nanmean(reward_Times' - TrialTimingData_aligned(TrialTimingData(:,9)==1,14))
% to here
TrialTimingData_aligned(:,[10, 12:14,16]) = TrialTimingData_aligned(:,[10, 12:14,16]); % - unacounted_lag;
TrialTimingData_aligned(:,[1:9 , 11]) = TrialTimingData(:,[1:9 , 11]);
TrialTimingData_aligned(:,15) = TrialTimingData(:,15);
% fig for aligment check
figure
% plot(AnalogTiming(1:5000000),'r')
% hold on
z = zeros(1, floor(reward_Times(end)) * sample_rate);
z(floor(reward_Times* sample_rate))= 100;
plot(z(1:5000000) * -20)
zz=TrialTimingData_aligned(TrialTimingData(:,9)==1,14);
z = zeros(1, floor(zz(end) * sample_rate));
z(floor(zz* sample_rate))= -100;
plot(z(1:5000000)* -40 , 'k')