extract active trigger channels by reading status channel data [usage] [ch_list, bit_list] = vb_eeg_get_active_trigger_channel(status_data, bit_len) [input] status_data : <required> data of status channel [1 x N] bit_len : <optional> bit length of data [24] [output] ch_list : list of active trigger channels bit_list : list of bit of selected channel [note] [history] 2007-01-04 (Sako) initial version Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function [ch_list, bit_list] = ... 0002 vb_eeg_get_active_trigger_channel(status_data, bit_len) 0003 % extract active trigger channels by reading status channel data 0004 % [usage] 0005 % [ch_list, bit_list] = vb_eeg_get_active_trigger_channel(status_data, bit_len) 0006 % [input] 0007 % status_data : <required> data of status channel [1 x N] 0008 % bit_len : <optional> bit length of data [24] 0009 % [output] 0010 % ch_list : list of active trigger channels 0011 % bit_list : list of bit of selected channel 0012 % [note] 0013 % [history] 0014 % 2007-01-04 (Sako) initial version 0015 % 0016 % Copyright (C) 2011, ATR All Rights Reserved. 0017 % License : New BSD License(see VBMEG_LICENSE.txt) 0018 0019 % --- CHECK ARGUMENTS --- % 0020 if ~exist('status_data', 'var'), status_data = []; end; 0021 if ~exist('bit_len', 'var'), bit_len = []; end; 0022 [status_data, bit_len] = inner_check_arguments(status_data, bit_len); 0023 0024 0025 % --- MAIN PROCEDURE --------------------------------------------------------- % 0026 % 0027 ch_list = []; 0028 0029 data_len = size(status_data,2); 0030 BIT_LEN = bit_len; 0031 0032 result_box = zeros(1,data_len); 0033 all_bit_list = zeros(1,data_len); 0034 bit_list = zeros(1,data_len); 0035 0036 % VERBOSE = 0; 0037 VERBOSE = 1; 0038 if VERBOSE, fprintf(' >>> read status bit (%d) ', BIT_LEN); end; 0039 0040 list_cnt = 0; 0041 0042 for nbit = 1:BIT_LEN 0043 check_bit = 2 ^ (nbit-1); 0044 result_box = vb_bitand_ex(status_data(:,:),check_bit,BIT_LEN); 0045 all_bit_list = (result_box == check_bit); 0046 0047 % if all bit is high, it means not to be connected (maybe) 0048 if any(all_bit_list) && ~all(all_bit_list) 0049 ch_list = [ch_list, nbit]; 0050 bit_list(size(ch_list,2),:) = all_bit_list; 0051 end 0052 if VERBOSE, fprintf('.'); end; 0053 end 0054 if VERBOSE, fprintf(' done\n'); end; 0055 % 0056 % --- END OF MAIN PROCEDURE -------------------------------------------------- % 0057 0058 % --- INNER FUNCTIONS -------------------------------------------------------- % 0059 % 0060 % --- inner_check_arguments() 0061 % 0062 function [status_data, bit_len] = inner_check_arguments(status_data, bit_len) 0063 if isempty(status_data) 0064 error('status_data is a required parameter'); 0065 end 0066 0067 if isempty(bit_len), bit_len = 24; end; 0068 % 0069 % --- end of inner_check_arguments() 0070 0071 %%% END OF FILE %%%