Home > NoiseTools > nt_epochify.m

nt_epochify

PURPOSE ^

y=nt_epochify(x,tidx,bounds) - extract epochs based on trigger indices

SYNOPSIS ^

function y=nt_epochify(x,tidx,bounds);

DESCRIPTION ^

y=nt_epochify(x,tidx,bounds) - extract epochs based on trigger indices

  y: 3D array of epoched data (time*channels*trials)

  x: raw data (time*channels)
  tidx: array of trigger indices
  bounds: (samples) start and stop of epoch
  
  if elements or tidx are fractionnary, the epochs are extracted by
  interpolation

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function y=nt_epochify(x,tidx,bounds);
0002 %y=nt_epochify(x,tidx,bounds) - extract epochs based on trigger indices
0003 %
0004 %  y: 3D array of epoched data (time*channels*trials)
0005 %
0006 %  x: raw data (time*channels)
0007 %  tidx: array of trigger indices
0008 %  bounds: (samples) start and stop of epoch
0009 %
0010 %  if elements or tidx are fractionnary, the epochs are extracted by
0011 %  interpolation
0012 
0013 
0014 if nargin<3; error('!'); end
0015 
0016 if numel(bounds)==1; bounds=[0 bounds]; end
0017 
0018 if max(tidx)+bounds(2)>size(x,1);
0019     [max(tidx) bounds(2) size(x,1)]
0020     error('epoch stops after end of data');
0021 end
0022 if min(tidx)+bounds(1)<1;
0023     error('epoch starts before beginning of data');
0024 end
0025 
0026 y=zeros(bounds(2)-bounds(1)+1, size(x,2), numel(tidx));
0027 
0028 if tidx == round(tidx)
0029     % integer positions
0030     for k=1:numel(tidx);
0031         y(:,:,k)=x(tidx(k)+(bounds(1):bounds(2)),:);
0032     end
0033 else
0034     % fractionnary positions
0035     warning('nointeger tidx, using interpolation'); 
0036     for k=1:numel(tidx);
0037         y(:,:,k)=interp1(1:size(x,1),x,tidx(k)+(bounds(1):bounds(2)));
0038     end
0039 end

Generated on Tue 01-Oct-2019 14:47:27 by m2html © 2005