CTF res4 File format

Talsma D D.Talsma at PSY.VU.NL
Mon May 23 12:41:37 CEST 2005


Hi Everybody,

Looking through the matlab code, I traced the coil-error back to a res4
file read error somewhat earlier:

On line 100, of read_ctf_res4.m, the file pointer is set to position
1839, and only a single byte of data is read from this position. As far
as I know, this read should start immediately after the preceding one,
and the field is defined as an 32-byte integer. So changig the code to
the snippet below fixed the problem. IFAICT, the old code would work, as
long as you had run descriptor fields that were shorter than 256
characters. In our case we had a descriptor length of 572 chars. 

% 2005-05-23: The following statement needed to be commented out 
% In order to make this file work with the VUMC data (Durk)
%fseek(fid,1839,'bof');
% Read in the run description length 
rd_len=fread(fid,1,'uint32');
% Go to the run description and read it in
fseek(fid,1844,'bof');
run_desc=setstr(fread(fid,rd_len,'char')');

Next, changing the above byte read also eliminates the additional
requirement of reading one extra short int before reading the filter
parameters. In addition, as far as I can tell, reading in the filter
definition as 18 8-byte integers is not correct either: Each filter
definition should consist of the following fields:
frequency (double)
class     (int)
type      (int)
num_params    (short int)

Therefore, the real value of num_fparams is stored in the last two byte
(17, and 18). Again, the original code would work, as long as you have
255 or less parameters.

% read in the filter information
% Filter read code modified dd; 2005-05-23 Durk)
num_filt=fread(fid,1,'uint16'); %num_filt=temp(1);
for fi=0:(num_filt-1),
  %filt_info=fread(fid,18,'uint8');
  filt_freq =fread(fid,1, 'double'); 
  filt_class=fread(fid,1, 'uint32');
  filt_type =fread(fid,1, 'uint32');
  num_fparm=fread(fid, 1, 'uint16');
  %num_fparm=filt_info(18);
  if num_fparm ~= 0,
    filt_parm=fread(fid,8*num_fparm,'uint8');
  end % if
end % for fi

Any comments?

Cheers
Durk



More information about the fieldtrip mailing list