Home > functions > device > eeg > biosemi > vb_load_eeg_ch_data.m

vb_load_eeg_ch_data

PURPOSE ^

load eeg data from channel data file

SYNOPSIS ^

function [data] = vb_load_eeg_ch_data(ch_file)

DESCRIPTION ^

 load eeg data from channel data file
 [usage]
   [data] = vb_load_eeg_ch_data(ch_file)
 [input]
   ch_file : <required> <<file>> cell array of channel data file {1 x N}
 [output]
      data : loaded data [N x Nsample]
 [note]
   without processing loaded data
 [history]
   2007-08-31 (Sako) initial version

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [data] = vb_load_eeg_ch_data(ch_file)
0002 % load eeg data from channel data file
0003 % [usage]
0004 %   [data] = vb_load_eeg_ch_data(ch_file)
0005 % [input]
0006 %   ch_file : <required> <<file>> cell array of channel data file {1 x N}
0007 % [output]
0008 %      data : loaded data [N x Nsample]
0009 % [note]
0010 %   without processing loaded data
0011 % [history]
0012 %   2007-08-31 (Sako) initial version
0013 %
0014 % Copyright (C) 2011, ATR All Rights Reserved.
0015 % License : New BSD License(see VBMEG_LICENSE.txt)
0016 
0017 % --- CHECK ARGUMENTS --- %
0018 if ~exist('ch_file', 'var') ch_file = []; end
0019 [ch_file] = inner_check_arguments(ch_file);
0020 
0021 % --- MAIN PROCEDURE --------------------------------------------------------- %
0022 %
0023 func_ = mfilename;
0024 
0025 [data_type,status_ch] = inner_check_status_channel(ch_file)
0026 
0027 file_num = size(ch_file, 2);
0028 
0029 for file_cnt = 1:file_num
0030   
0031   file_path = ch_file{file_cnt};
0032 
0033   if exist(file_path, 'file') ~= 2
0034     error('(%s)cannot find file : %s', func_, file_path);
0035   end
0036 
0037   fid = fopen(file_path, 'r');
0038   if fid < 0
0039     error('(%s)cannot open : %s', func_, file_path); 
0040   end
0041 
0042   this_data = fread(fid, data_type{file_cnt});
0043 
0044   if status_ch(file_cnt)
0045     data(file_cnt,:) = this_data';
0046   else
0047     data(file_cnt,:) = this_data;
0048 %     data(file_cnt,:) = this_data * EDF.Cal(idx) + EDF.Off(idx);
0049   end
0050   
0051   fclose(fid);
0052 
0053   % for DEBUG
0054 %   fprintf(' --  read file: ''%s''\n', file_path);
0055 end
0056 %
0057 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0058 
0059 % --- INNER FUNCTIONS -------------------------------------------------------- %
0060 %
0061 % --- inner_check_arguments()
0062 %
0063 function [ch_file] = inner_check_arguments(ch_file)
0064 func_ = mfilename;
0065 
0066 if isempty(ch_file)
0067   error('(%s)ch_file is required parameter', func_);
0068 end
0069 
0070 if ~iscell(ch_file)
0071   warning('(%s)ch_file must be cell array', func_);
0072   ch_file = {ch_file};
0073 end
0074 return;
0075 %
0076 % --- end of inner_check_arguments()
0077 
0078 % --- inner_check_status_channel()
0079 %
0080 function [data_type, status_ch] = inner_check_status_channel(ch_file)
0081 % data_type is {1 x N}
0082 func_ = mfilename;
0083 
0084 vb_define_device;
0085 
0086 file_num = size(ch_file,2);
0087 data_type = cell(1, file_num);
0088 status_ch = zeros(file_num, 1);
0089 
0090 for file_cnt = 1:file_num
0091   [fpath,fname,fext] = vb_get_file_parts(ch_file{file_cnt});
0092   
0093   if isempty(findstr(fname, STATUS_CH_LABEL))
0094     data_type{file_cnt} = STANDARD_BIN_DATA_TYPE;
0095     status_ch(file_cnt) = 0;
0096   else
0097     data_type{file_cnt} = STATUS_CH_DATA_TYPE;
0098     status_ch(file_cnt) = 1;
0099   end
0100 end
0101 
0102 return;
0103 %
0104 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0105 
0106 
0107 %%% END OF FILE %%%

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005