Home > bml > signal > bml_event2raw.m

bml_event2raw

PURPOSE ^

BML_EVENT2RAW creates a raw of zeros with ones at event times

SYNOPSIS ^

function raw = bml_event2raw(cfg, event)

DESCRIPTION ^

 BML_EVENT2RAW creates a raw of zeros with ones at event times

 Use as
   raw = bml_event2raw(cfg, event)
   raw = bml_event2raw(roi, event)

 cfg.roi - roi table: raw is created from s1 to s2
 cfg.event_type - cells of char: event types selected
 cfg.sample_type - 'auto' (default'), 'second' or 'sample'. If 'auto', it
         asumes 'sample' if event.sample is integer, 'second' otherwise. 

 returns a raw

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function raw = bml_event2raw(cfg, event)
0002 
0003 % BML_EVENT2RAW creates a raw of zeros with ones at event times
0004 %
0005 % Use as
0006 %   raw = bml_event2raw(cfg, event)
0007 %   raw = bml_event2raw(roi, event)
0008 %
0009 % cfg.roi - roi table: raw is created from s1 to s2
0010 % cfg.event_type - cells of char: event types selected
0011 % cfg.sample_type - 'auto' (default'), 'second' or 'sample'. If 'auto', it
0012 %         asumes 'sample' if event.sample is integer, 'second' otherwise.
0013 %
0014 % returns a raw
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 %selecting events
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 %creating raw
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 %s",sample_type);
0060 end

Generated on Tue 25-Sep-2018 10:08:19 by m2html © 2005