-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathload_sync.m
58 lines (52 loc) · 1.87 KB
/
load_sync.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
function sync = load_sync(SUBJ, YYYY, MM, DD, ARRAY, BLOCK, rootdir)
%LOAD_SYNC Loads processed sync data
%
% Syntax:
% sync = io.load_sync(SUBJ, YYYY, MM, DD, ARRAY, BLOCK)
%
% Example:
% emg = io.load_sync('Forrest', 2022, 1, 25, "A", 7);
% % This would return a sync struct for block 7 for Forrest on 1/25/2022
% % that was obtained for streams on NHP-A TMSiSAGA.
%
% Inputs:
% SUBJ - String: should be name of subject (e.g. "Rupert" or "Frank")
% YYYY - year (numeric scalar)
% MM - month (numeric scalar)
% DD - day (numeric scalar)
% ARRAY - String: "A" or "B" etc. for array identifier
% BLOCK - Recording block index (numeric scalar)
% rootdir - (Opt) The root folder where all the generated data is kept.
% This should normally stay the same unless we move
% our data share.
% Output:
% sync - Data struct with fields:
% - onset : Vector of sync RISING transition sample indices
% - offset : Vector of sync FALLING transitions (note this is
% typically the actual stim "onset" due to inverted
% logic used by TMSi).
% - sync_data : The actual sync data vector.
%
% See also: Contents, io.load_tmsi_raw, io.load_tmsi_triggers
if nargin < 7
rootdir = parameters('generated_data_folder');
end
if (numel(ARRAY) > 1) || (numel(BLOCK) > 1)
sync = cell(numel(BLOCK), numel(ARRAY));
for iB = 1:numel(BLOCK)
for iA = 1:numel(ARRAY)
sync{iB, iA} = io.load_sync(SUBJ, YYYY, MM, DD, ARRAY(iA), BLOCK(iB), rootdir);
end
end
return;
end
f = utils.get_block_name(SUBJ, YYYY, MM, DD, ARRAY, BLOCK, ...
'rootdir_gen', rootdir);
sync = load(f.Generated.Sync);
% Fix mismatch in pairs of stim start/stop pairs
if numel(sync.offset) > numel(sync.onset)
if sync.offset(end) > sync.onset(end)
sync.offset(end) = [];
end
end
end