Skip to content

Commit

Permalink
add option for splitting data into upper and lower 16 bits (#2428)
Browse files Browse the repository at this point in the history
* TYPO in comment

* ENH - allow for splitting lower and higher 16 bit
  • Loading branch information
schoffelen committed Jun 25, 2024
1 parent 72c7f16 commit b01eeef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion fileio/ft_read_event.m
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@
end

try
% read the trigger codes from the STIM channel, usefull for (pseudo) continuous data
% read the trigger codes from the STIM channel, useful for (pseudo) continuous data
% this splits the trigger channel into the lowers and highest 16 bits,
% corresponding with the front and back panel of the electronics cabinet at the Donders Centre
[backpanel, frontpanel] = read_ctf_trigger(filename);
Expand Down
19 changes: 17 additions & 2 deletions fileio/private/read_trigger.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
begsample = ft_getopt(varargin, 'begsample' );
endsample = ft_getopt(varargin, 'endsample' );
chanindx = ft_getopt(varargin, 'chanindx' ); % specify -1 in case you don't want to detect triggers
detectflank = ft_getopt(varargin, 'detectflank' ); % can be up, updiff, down, downdiff, both, any, biton, bitoff
detectflank = ft_getopt(varargin, 'detectflank' ); % can be up, updiff, down, downdiff, both, any, biton, bitoff, optionally appended with _split16bit
denoise = ft_getopt(varargin, 'denoise', true );
trigshift = ft_getopt(varargin, 'trigshift', 0); % causes the value of the trigger to be obtained from a sample that is shifted N samples away from the actual flank
trigpadding = ft_getopt(varargin, 'trigpadding', true );
Expand Down Expand Up @@ -255,9 +255,24 @@
end
end

label = hdr.label(chanindx);
if contains(detectflank, 'split16bit')
% split the trigger channel into lower and higher (bitshifted) trigger channels.
% this is the same functionality as read_ctf_trigger, consider merging
dat_high = fix(dat / 2^16);
dat_low = double(bitand(uint32(dat), 2^16-1));
dat = [dat_low; dat_high];

label = cat(1, cellfun(@sprintf, repmat({'%s_low16bit'},numel(label),1), label, 'UniformOutput', false), ...
cellfun(@sprintf, repmat({'%s_high16bit'},numel(label),1), label, 'UniformOutput', false));

tok = tokenize(detectflank, '_');
detectflank = tok{1};
end

for i = 1:size(dat,1)
% process each trigger channel independently
channel = hdr.label{chanindx(i)};
channel = label{i};
trig = dat(i,:);

if trigpadding
Expand Down

0 comments on commit b01eeef

Please sign in to comment.