Find time points that event signal changes to the specified value 'status' ix = vb_event_start(y,status) ix = vb_event_start(y,status,t_stay) y : event signal status : status value t_stay : minimum length to stay the specified value [default = 10] 'y' should be stay at the value 'status' for more than t_stay ix : index corresponding to the start point 'y' changes to 'status' from other value 2009-6-11 Masa-aki Sato 2012-1-8 Masa-aki Sato Bug fix Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function ix = vb_event_start(y,status,t_stay) 0002 % Find time points that event signal changes to the specified value 'status' 0003 % ix = vb_event_start(y,status) 0004 % ix = vb_event_start(y,status,t_stay) 0005 % y : event signal 0006 % status : status value 0007 % t_stay : minimum length to stay the specified value [default = 10] 0008 % 'y' should be stay at the value 'status' for more than t_stay 0009 % 0010 % ix : index corresponding to the start point 0011 % 'y' changes to 'status' from other value 0012 % 0013 % 2009-6-11 Masa-aki Sato 0014 % 2012-1-8 Masa-aki Sato Bug fix 0015 % 0016 % Copyright (C) 2011, ATR All Rights Reserved. 0017 % License : New BSD License(see VBMEG_LICENSE.txt) 0018 0019 if nargin < 3, t_stay = 10; end; 0020 0021 T = length(y); 0022 0023 flg = ones(1,T-t_stay); 0024 tt = 1:T-t_stay; 0025 0026 % 'y' is not 'status' value beforehand 0027 flg = flg .* (y(tt) ~= status); 0028 0029 % 'y' should be stay at the value 'status' for more than t_stay 0030 for t=1:t_stay 0031 flg = flg .* (y(tt + t) == status); 0032 end 0033 0034 ix = find(flg == 1); 0035 0036 return 0037 0038 % Status value 'y' should be stay at the value 'status' for more than t_stay 0039 ix = find( y(2:T-t_stay) == status ... 0040 & y(2+t_stay:T) == status ... 0041 & y(1:T-1-t_stay) ~= status);