get status bit pattern from tnteger status signal [usage] [result] = vb_get_status_bit_pattern(status,bit_ptn,bit_max) [input] status : integer status signal [ 1 x n_sample ] bit_ptn : bit number list to get specified bit data from status signal = [1:8] : get 1 to 8 bit from status bit_max : bit length of original status signal before converted to integer = [24] for Biosemi [output] result : status bit (0/1) pattern [length(bit_ptn) x n_sample] 2009-6-25 Masa-aki Sato Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function [result] = vb_get_status_bit_pattern(status,bit_ptn,bit_max) 0002 % get status bit pattern from tnteger status signal 0003 % [usage] 0004 % [result] = vb_get_status_bit_pattern(status,bit_ptn,bit_max) 0005 % [input] 0006 % status : integer status signal [ 1 x n_sample ] 0007 % bit_ptn : bit number list to get specified bit data from status signal 0008 % = [1:8] : get 1 to 8 bit from status 0009 % bit_max : bit length of original status signal before converted to integer 0010 % = [24] for Biosemi 0011 % [output] 0012 % result : status bit (0/1) pattern [length(bit_ptn) x n_sample] 0013 % 2009-6-25 Masa-aki Sato 0014 % 0015 % Copyright (C) 2011, ATR All Rights Reserved. 0016 % License : New BSD License(see VBMEG_LICENSE.txt) 0017 0018 % 0019 result=[]; 0020 [M, T] = size(status); 0021 if T==1 && M > 1, status = status'; T = M; M = 1; end; 0022 0023 if M > 1, error('status should be 1 x T'); end; 0024 if nargin < 2, bit_ptn = 1:8; end; 0025 if nargin < 3, bit_max = 24; end; 0026 0027 status = double(status); 0028 0029 % convert negative integer to positive integer 0030 ix = find( status < 0 ); 0031 status(ix) = status(ix) + 2^bit_max; 0032 0033 bit_len = length(bit_ptn); 0034 0035 result = zeros(bit_len, T); 0036 0037 for i_bit = 1:bit_len 0038 % get specified bit as 0/1 0039 i_val = 2^bit_ptn(i_bit); 0040 result(i_bit,:) = bitand(status, i_val)/i_val; 0041 end 0042 0043 % BITAND ビット単位の論理積 0044 % C = BITAND(A,B) は、2つの引数 A と B のビット単位の論理積を出力します。 0045 % A と B は、符号なしの整数でなければなりません。 0046 0047 % BITGET ビットの取り出し 0048 % C = BITGET(A,BIT) 0049 % A の中の位置 BIT にあるビット値を出力します。 0050 % A は、符号なし整数で、 0051 % BIT は 1 と A の符号なし整数のクラスのビット数 0052 % (UINT32では32)の間の値でなければなりません。 0053 % 0054 return; 0055 % 0056 % --- END OF MAIN PROCEDURE --- %