1 function [x,sz] =
trigg(s,TRIG,pre,post,gap)
2 % TRIGG cuts continous sequence into segments.
3 % Missing values (in
case s is to
short) are substituted by NaN
's.
5 % [X,sz] = trigg(s, TRIG, PRE, PST [, GAP])
8 % S is the continous data sequence (1 channel per column)
9 % TRIG defines the trigger points
10 % PRE offset of the start of each segment (relative to trigger)
11 % PST offset of the end of each segment (relative to trigger)
12 % GAP number of NaN's to separate trials (
default=0)
13 % TRIG, pre, post and gap are counted in samples
16 % X is a matrix of size [sz(1), sz(2)*sz(3)]
17 % sz [size(s,2), post-pre+1+gap, length(TRIG)]
18 % sz(1) is the number of channels NS
19 % sz(2) is the number of samples per trial
20 % sz(3) is the number of trials i.e. length(TRIG)
22 % X3D = reshape(X,sz) returns a 3-dimensional matrix
23 % X2D = reshape(X(K,:),sz(2:3)) returns channel K in a 2-dimensional matrix
25 % see also: GETTRIGGER
27 % $Id:
trigg.m 2202 2009-10-27 12:06:45Z schloegl $
28 % Copyright (c) 1999-2005 by Alois Schloegl <a.schloegl@ieee.org>
29 % This is part of the BIOSIG-toolbox http:
32 % This program is free software; you can redistribute it and/or
33 % modify it under the terms of the GNU General Public License
34 % as published by the Free Software Foundation; either version 2
35 % of the License, or (at your option) any later version.
37 % This program is distributed in the hope that it will be useful,
38 % but WITHOUT ANY WARRANTY; without even the implied warranty of
39 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 % GNU General Public License for more details.
42 % You should have received a copy of the GNU General Public License
43 % along with this program; if not, write to the Free Software
44 % Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
54 % include leading nan's
55 off = min(min([TRIG(:);+Inf])+pre-1,0);
56 % include following nan's
57 off2 = max(max([TRIG(:);-Inf])+post-length(s),0);
58 if ((off~=0) || (off2~=0))
59 s = [repmat(nan,-off,nc);s;repmat(nan,off2,nc)];
63 % devide into segments
65 sz = [nc, post-pre+1+gap, length(TRIG)];
66 x = repmat(NaN, [sz(1), sz(2)*sz(3)]);
67 for m = 1:length(TRIG),
68 x(:,m*N + (1-N:-gap)) = s(TRIG(m)+(pre:post)',:).';