0001 function tidx=nt_find_triggers(x,threshold,type,guard)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 if nargin<4 || isempty(guard) ; guard=0; end
0013 if nargin<3 || isempty(type) ; type='up'; end
0014 if nargin<2 threshold=[]; end
0015 if nargin<1; error('!'); end
0016
0017 if strcmp(type,'down');
0018 tidx=nt_find_triggers(-x,threshold,'up',guard);
0019 return;
0020 end
0021
0022 if ~strcmp(type,'up'); error('!'); end
0023
0024 if x ~= x(:); error('trigger waveform should be column vector'); end
0025
0026 if isempty(threshold);
0027 threshold=(max(x)+min(x))/2;
0028 end
0029
0030 xx=x(1:end-1)<threshold & x(2:end)>=threshold;
0031
0032
0033
0034
0035 tidx=find(xx);