0001 function raw = bml_event2raw(cfg, event)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 if istable(cfg)
0017 cfg = struct('roi',cfg);
0018 end
0019 roi = bml_getopt(cfg,'roi');
0020 event_type = bml_getopt(cfg,'event_type');
0021 sample_type = bml_getopt_single(cfg,'sample_type','auto');
0022
0023 if strcmp(sample_type,'auto')
0024 if isinteger([event.sample])
0025 sample_type = 'sample';
0026 else
0027 sample_type = 'second';
0028 end
0029 end
0030
0031
0032 if isempty(event_type)
0033 event_type = unique({event.type});
0034 else
0035 event_type = event_type(ismember(event_type,unique({event.type})));
0036 end
0037
0038
0039 roi = bml_sync_consolidate(bml_roi_confluence(roi));
0040 assert(height(roi)==1,"can't deal with more than one sync chunk after consolidation for now");
0041
0042 raw=[];
0043 raw.time={bml_idx2time(roi,roi.s1:roi.s2)};
0044 raw.trial={zeros(length(event_type),size(raw.time{1},2))};
0045 raw.label=event_type;
0046 raw.fsample=roi.Fs;
0047
0048 if strcmp(sample_type,'sample')
0049 for i=1:length(event_type)
0050 i_event = event(ismember({event.type},event_type(i)));
0051 raw.trial{1}(i,[i_event.sample])=1;
0052 end
0053 elseif strcmp(sample_type,'second')
0054 for i=1:length(event_type)
0055 i_event = event(ismember({event.type},event_type(i)));
0056 raw.trial{1}(i,round([i_event.sample].*raw.fsample))=1;
0057 end
0058 else
0059 error("Unknown sample_type
0060 end