Find time points that signal differ from the specified value 'status' ix = vb_event_end(y,status) ix = vb_event_end(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 Then, 'y' changes to other value from 'status' ix : index corresponding to the end point 'y' changes from 'status' to 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_end(y,status,t_stay) 0002 % Find time points that signal differ from the specified value 'status' 0003 % ix = vb_event_end(y,status) 0004 % ix = vb_event_end(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 % Then, 'y' changes to other value from 'status' 0010 % ix : index corresponding to the end point 0011 % 'y' changes from 'status' to 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 % take bitwise AND to ignore irrelevant bit 0024 y = bitand(y,status); 0025 0026 flg = ones(1,T-t_stay); 0027 tt = 1:T-t_stay; 0028 0029 % 'y' is not 'status' value afterward 0030 flg = flg .* (y(tt + t_stay) ~= status); 0031 0032 % 'y' should be stay at the value 'status' for more than t_stay 0033 for t=0:t_stay-1 0034 flg = flg .* (y(tt + t) == status); 0035 end 0036 0037 ix = find(flg == 1); 0038 ix = ix + t_stay - 1; 0039 0040 return 0041 0042 % Status value 'y' should be stay at the value ~='status' for more than t_stay 0043 ix = find( y(2:T-t_stay) ~= status ... 0044 & y(2+t_stay:T) ~= status ... 0045 & y(1:T-1-t_stay) == status); 0046 0047 %ix = find( y(2:T) ~= status & y(1:T-1) == status);