TEAP (Toolbox for Emotion Analysis using Physiological Signals) doc
trigg.m
Go to the documentation of this file.
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.
4 %
5 % [X,sz] = trigg(s, TRIG, PRE, PST [, GAP])
6 %
7 % INPUT:
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
14 %
15 % OUTPUT:
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)
21 %
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
24 %
25 % see also: GETTRIGGER
26 
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://biosig.sf.net/
30 
31 
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.
36 %
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.
41 %
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.
45 
46 if nargin<5,
47  gap = 0;
48 end;
49 
50 post=round(post);
51 
52 [nr,nc] = size(s);
53 
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)];
60  TRIG = TRIG-off;
61 end;
62 
63 % devide into segments
64 N = post-pre+1+gap;
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)',:).';
69 end;
70 
trigg
function trigg(in s, in TRIG, in pre, in post, in gap)