-
Notifications
You must be signed in to change notification settings - Fork 0
/
AO_TTLextract.m
92 lines (59 loc) · 1.96 KB
/
AO_TTLextract.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
%% Figure out how many files where experimental files
cd('Y:\PreProcessEphysData\02_26_2015')
fdir = dir('*.mat');
tabdir = struct2table(fdir);
fileNames = tabdir.name;
expFiles = cell(length(fileNames),1);
expFNum = 0;
expCount = 1;
for fi = 1:length(fileNames)
filefront = fileNames{fi}(1);
if strcmp(filefront,'-')
continue
else
load(fileNames{fi})
end
if exist('C1_DI001_Up','var')
expFiles{expCount} = fileNames{fi};
expFNum = expFNum + 1;
expCount = expCount + 1;
else
clearvars -except fileNames expFiles expFNum expCount
continue
end
clearvars -except fileNames expFiles expFNum expCount
end
% Clean of exp fnames
expFiles = expFiles(cellfun(@(x) ~isempty(x), expFiles));
%%
load('AbvTrgt_23_11008.mat')
% Total Recording time
totalRecordTime = (timeEnd - timeStart)/60; % in minutes
% Duration of time before first Timestamp
expToffset = (ttlInfo.ttlTimeBegin - timeStart)/60; % in minutes
% Total experimental time
totalExptime = totalRecordTime - expToffset; % in minutes
timeVec = linspace(1,length(CElectrode1),length(CElectrode1)); %
timeVecSF = timeVec*sampFreqMER*1000;
%%
% Index start of timestamp
roundVal = 100000;
expToffSF = expToffset*ttlInfo.ttl_sf*1000;
zeroTimeVecSF = 1:1:length(CElectrode1);
zeroTimeVec = zeroTimeVecSF/(sampFreqMER*1000);
zeroTimeVR = round(zeroTimeVec*roundVal)/roundVal;
timeStampVecSF = ttlInfo.ttl_up + expToffSF;
timeStampVec = timeStampVecSF/(ttlInfo.ttl_sf*1000);
timeStampVR = round(timeStampVec*roundVal)/roundVal;
tsIndex = zeros(length(timeStampVR),1);
for tsI = 1:length(timeStampVR)
ts = timeStampVR(tsI);
if isempty(find(ismember(zeroTimeVR,ts),1))
[~, tsIndex(tsI)] = min(abs(zeroTimeVR - ts));
else
tsIndex(tsI) = find(ismember(zeroTimeVR,ts));
end
end
%%
ttlInfo.ttlTimeBegin*sampFreqMER*1000 + ttlInfo.ttl_up(1)
% Start raw index value for beginning of stiched trace.