📄 ctf_read_res4.m
字号:
function [ctf] = ctf_read_res4(folder,VERBOSE,COEFS);% ctf_read_res4 - Read a CTF .res4 file%% ctf = ctf_read_res4( [folder], [verbose], [coefs])% % This function reads the resource information from a CTF .ds folder. This% resource information must be read before reading the .meg4 data file.% All input arguments are optional.%% INPUTS%% folder: the .ds directory containing the data to be read. With% no input, it will prompt with a gui folder locator.%% verbose: If verbose = 1, display 'ctf.setup' structure (default)% If verbose = 0, do not display 'ctf.setup' structure%% coefs: an option to read the sensory coefficients, which give the% weights for calculation of synthetic 2nd or 3rd order% gradiometers.% If coefs = 1, read the sensor coefficients% If coefs = 0, do not read the sensor coefficients (default)% % OUTPUTS%% ctf.folder - path of the .ds folder%% ctf.res4.file - data file path/name% ctf.res4.header - data format header%% ctf.setup - a header structure consisting of date, time, run name, run% title, subject, run description, operator, number of channels, number% of samples, sample rate, number of trials, duration, pretrigger_samples,% sensor filename, head zeroing, and number of filters.% % ctf.sensor.index - a sensor structure consisting of EEG sensors, MEG% sensors, reference sensors, and other sensors.% % ctf.sensor.info - a structure with gain and offset information consisting% of proper gain, Q gain, io gain, io offset, and index.%% <>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>% < >% < DISCLAIMER: >% < >% < THIS PROGRAM IS INTENDED FOR RESEARCH PURPOSES ONLY. >% < THIS PROGRAM IS IN NO WAY INTENDED FOR CLINICAL OR >% < OFFICIAL USE. >% < >% <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>%% $Revision: 1.12 $ $Date: 2004/07/18 06:10:17 $% Copyright (C) 2003 Darren L. Weber% % This program is free software; you can redistribute it and/or% modify it under the terms of the GNU General Public License% as published by the Free Software Foundation; either version 2% of the License, or (at your option) any later version.% % This program is distributed in the hope that it will be useful,% but WITHOUT ANY WARRANTY; without even the implied warranty of% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the% GNU General Public License for more details.% % You should have received a copy of the GNU General Public License% along with this program; if not, write to the Free Software% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.% Modified: 11/2003, Darren.Weber_at_radiology.ucsf.edu% - modified from NIH code readresfile.m%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%ver = '$Revision: 1.12 $';fprintf('\nCTF_READ_RES4 [v %s]\n',ver(11:15)); tic;if ~exist('folder','var'), ctf = ctf_folder;else ctf = ctf_folder(folder);endif ~exist('VERBOSE','var'), VERBOSE = true; endif ~exist('COEFS','var'), COEFS = false; end[folderPath,folderName,folderExt] = fileparts(ctf.folder);ctf.res4.file = findres4file(ctf.folder);%----------------------------------------------------------------% open the data file[fid,message] = fopen(ctf.res4.file,'rb','ieee-be.l64');if fid < 0, error('cannot open .res4 file'); end%-------------------------------------------------------------% READ HEADERfseek(fid,0,-1);ctf.res4.header = char(fread(fid,8,'char'))';% check for the right formatif strmatch('MEG41RS',ctf.res4.header), % OK, we can handle this formatelse msg = sprintf('This function is designed to read MEG41RS format.\nIt may not read "%s" format correctly',ctf.res4.header); warning(msg);end%-------------------------------------------------------------% READ SETUP%---DATE/TIMEfseek(fid, 778,-1);ctf.setup.time = char(fread(fid,255,'char'))';fseek(fid,1033,-1);ctf.setup.date = char(fread(fid,255,'char'))';%---NUMBER OF SAMPLESfseek(fid,1288,-1);ctf.setup.number_samples = (fread(fid,1,'int32')');%---NUMBER OF CHANNELSfseek(fid,1292,-1);ctf.setup.number_channels = (fread(fid,1,'int16')');%---SAMPLE RATEfseek(fid,1296,-1);ctf.setup.sample_rate = fread(fid,1,'double')';ctf.setup.sample_msec = 1000 / ctf.setup.sample_rate;ctf.setup.sample_sec = 1 / ctf.setup.sample_rate;%---NUMBER OF TRIALSfseek(fid,1312,-1);ctf.setup.number_trials = fread(fid,1,'int16')';fseek(fid, 776,-1);ctf.setup.number_trials_averaged = fread(fid,1,'int16');%---DURATIONfseek(fid,1304,-1);ctf.setup.duration_total = fread(fid,1,'double');ctf.setup.duration_trial = ctf.setup.duration_total / ctf.setup.number_trials;%---PRE_TRIG POINTSfseek(fid,1316,-1);ctf.setup.pretrigger_samples = fread(fid,1,'int32');ctf.setup.pretrigger_msec = (ctf.setup.pretrigger_samples / ctf.setup.sample_rate) * 1000;%---HEAD ZEROINGfseek(fid,1348,-1);h_zero = fread(fid,1,'int32')';no_yes = {'no','yes'};ctf.setup.head_zero = no_yes{h_zero+1};%---RUN NAMEfseek(fid,1360,-1);ctf.setup.run_name = char(fread(fid,32,'char'))';%---RUN TITLEfseek(fid,1392,-1);ctf.setup.run_title = char(fread(fid,256,'char'))';%---SUBJECTfseek(fid,1712,-1);ctf.setup.subject = char(fread(fid,32,'char'))';%---OPERATORfseek(fid,1744,-1);ctf.setup.operator = char(fread(fid,32,'char'))';%---SENSOR FILE NAMEfseek(fid,1776,-1);ctf.setup.sensor_file_name = char(fread(fid,60,'char'))';%---RUN DESCRIPTION & FILTERSfseek(fid,1836,-1);run_size = fread(fid,1,'int32');fseek(fid,1844,-1);ctf.setup.run_description = char(fread(fid,run_size,'char'));ctf.setup.number_filters = fread(fid,1,'int16');for i = 1:ctf.setup.number_filters, ctf.setup.filters(i).freq = fread(fid,1,'double'); ctf.setup.filters(i).class = fread(fid,1,'int32'); ctf.setup.filters(i).type = fread(fid,1,'int32'); ctf.setup.filters(i).numparam = fread(fid,1,'int16'); ctf.setup.filters(i).params = fread(fid,ctf.setup.filters(i).numparam,'double');endif(COEFS) b = 1846 + run_size; if(ctf.setup.number_filters == 0) np = 0; else np = ctf.setup.filters.numparam; warning('3rd gradient + hardware filter parameters not fully tested! let''s see what happens... :)'); end nf = ctf.setup.number_filters; f = ( nf * 18 ) + ( np * 8 ); offset = b + f + ctf.setup.number_channels * 1360;end%-------------------------------------------------------------% CREATE TIME ARRAYS% the time arrays must be based on increments of the sample_msecctf.setup.time_msec = [0:ctf.setup.number_samples - 1]' * ctf.setup.sample_msec;ctf.setup.time_msec = ctf.setup.time_msec - ctf.setup.pretrigger_msec;% adjust the sample point closest to zero so that it is zero, if it% is reasonably close to zero, say within 3 decimal places for msec timingzero_index = find(abs(ctf.setup.time_msec) == min(abs(ctf.setup.time_msec)));zero_value = ctf.setup.time_msec(zero_index);if (-0.0001 < zero_value) & (zero_value < 0.0001), ctf.setup.time_msec(zero_index) = 0;endctf.setup.start_msec = ctf.setup.time_msec(1);ctf.setup.end_msec = ctf.setup.time_msec(end);ctf.setup.time_sec = ctf.setup.time_msec / 1000;ctf.setup.start_sec = ctf.setup.time_sec(1);ctf.setup.end_sec = ctf.setup.time_sec(end);%-------------------------------------------------------------% PRINT SETUPif VERBOSE, ctf_print_setup(ctf);end%-------------------------------------------------------------% READ SENSOR INFORMATIONctf.sensor.info = struct(... 'proper_gain',[],... 'q_gain',[],... 'io_gain',[],... 'io_offset',[],... 'index',[],... 'extra',[],... 'label',[],... 'grad_order_no',[]);% read channel names (not trivial!)for chan = 1:ctf.setup.number_channels, temp = fread(fid,32,'char'); temp(temp>127) = 0; temp(temp<0) = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -