Home > eeg > egis > scripts > make_eeg_coherence.m

make_eeg_coherence

PURPOSE ^

status = make_eeg_coherence(csdmfname,coherencefname,obs_labels,add_bad);

SYNOPSIS ^

function status = make_eeg_coherence(csdmfname,powerfname,obs_labels,add_bad);

DESCRIPTION ^

status = make_eeg_coherence(csdmfname,coherencefname,obs_labels,add_bad);
generate multisubject/multistate coherence file from multiple csdm
files
csdmfname = root (everything short of the numbers at the end) of the csdm
    file or the entire csdmfilename or csdmfilenames
    if you plan to use the indices option then what you
    need to do is have the root without the indice which must be 
    then appended. 
    you can only do a single file if you use gui by submitting a blank
    or no parameters
    you can submit a list of csdm file names as rows in csdmfname.  In 
    this case all the csdm filenames must have the same length.
    default is a gui for a single csdm file  (optional)
coherence_fname = name of coherence file.
obs_labels = labels for obbservations (optional),default = csdmfname 
add_bad = even more bad_channels
example: to process the csdm files 
    010_12.EEG.RAW.csdm.aver.w01
    010_12.EEG.RAW.csdm.aver.w02
    010_12.EEG.RAW.csdm.aver.w10

or you could list all the csdm files
csdmfname = [010_12.EEG.RAW.csdm.aver.w01;010_12.EEG.RAW.csdm.aver.w02;
             010_12.EEG.RAW.csdm.aver.w10];
make_eeg_coherence(csdmfname)
or
make_eeg_coherence(csdmfname,'010_12.coh',[Obs_01;Obs_02;Obs_10]);

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function status = make_eeg_coherence(csdmfname,powerfname,obs_labels,add_bad);
0002 %status = make_eeg_coherence(csdmfname,coherencefname,obs_labels,add_bad);
0003 %generate multisubject/multistate coherence file from multiple csdm
0004 %files
0005 %csdmfname = root (everything short of the numbers at the end) of the csdm
0006 %    file or the entire csdmfilename or csdmfilenames
0007 %    if you plan to use the indices option then what you
0008 %    need to do is have the root without the indice which must be
0009 %    then appended.
0010 %    you can only do a single file if you use gui by submitting a blank
0011 %    or no parameters
0012 %    you can submit a list of csdm file names as rows in csdmfname.  In
0013 %    this case all the csdm filenames must have the same length.
0014 %    default is a gui for a single csdm file  (optional)
0015 %coherence_fname = name of coherence file.
0016 %obs_labels = labels for obbservations (optional),default = csdmfname
0017 %add_bad = even more bad_channels
0018 %example: to process the csdm files
0019 %    010_12.EEG.RAW.csdm.aver.w01
0020 %    010_12.EEG.RAW.csdm.aver.w02
0021 %    010_12.EEG.RAW.csdm.aver.w10
0022 %
0023 %or you could list all the csdm files
0024 %csdmfname = [010_12.EEG.RAW.csdm.aver.w01;010_12.EEG.RAW.csdm.aver.w02;
0025 %             010_12.EEG.RAW.csdm.aver.w10];
0026 %make_eeg_coherence(csdmfname)
0027 %or
0028 %make_eeg_coherence(csdmfname,'010_12.coh',[Obs_01;Obs_02;Obs_10]);
0029 %
0030 if nargin < 1
0031     [fid, csdmfname] = get_fid('rb');
0032     if fid < 0
0033         error('invalid filename')
0034     end;
0035     fclose(fid);
0036 end;
0037 
0038 if nargin < 2
0039     [pfid,powerfname] = put_fid('rb');
0040     obs_labels = csdmfname;
0041     fclose(pfid);
0042 end;
0043 
0044 if nargin < 3
0045     obs_labels = csdmfname;
0046 end;
0047 if isempty(powerfname)
0048     [pfid,powerfname] = put_fid('rb');
0049     fclose(pfid);
0050 end;
0051 version = -2;
0052 pfid = fopen(powerfname,'wb');
0053 fwrite(pfid,version,'int16');
0054 fwrite(pfid,size(csdmfname,1),'int16');
0055 
0056 fwrite(pfid,size(obs_labels,2),'int16');
0057 for i = 1:size(obs_labels,1)
0058     fwrite(pfid,obs_labels(i,:),'char');
0059 end;
0060 nfiles = size(csdmfname,1);
0061 
0062 
0063 PEpoch = zeros(1,nfiles);
0064 PWindow_Length = zeros(1,nfiles);
0065 PNEpoch = zeros(1,nfiles);
0066 PNbad_chan = zeros(1,nfiles);
0067 Pbad_chan = zeros(nfiles,129);
0068 Pref_flag = zeros(1,nfiles);
0069 PNchan = zeros(1,nfiles);
0070 PNfreq = zeros(1,nfiles); 
0071 Preference = zeros(nfiles,129);
0072 
0073     for i = 1:size(csdmfname,1)
0074         fid = fopen(csdmfname(i,:),'rb');
0075         frewind(fid);
0076         version = fread(fid,1,'int16');
0077         if version ~= -1
0078             error(['file: ' csdmfname(i,:) 'is not a csdm file']);
0079             fclose(fid)
0080         end;
0081         [PEpoch(i),PWindow_Length(i),PNEpoch(i),PNbad_chan(i),bad_chan,Pref_flag(i),reference,PNchan(i),PNfreq(i)] = rd_csdm_hdr(fid);
0082         
0083         if Pref_flag(i) ~= 6
0084         Preference(i,1:size(reference,2)) = reference;
0085         else
0086         Preference(i,1:size(reference,2)) = int2str(reference);
0087         end;
0088         if strcmp(reference,'laplacian')
0089             bad_chan = [bad_chan 22 26 33 39 45 57 64 70 75 83 90 96 101 115 121 1 8 14];
0090         end
0091         if nargin == 4
0092         bad_chan = [bad_chan add_bad(i,:)];
0093         end;
0094         Pbad_chan(i,1:size(bad_chan,2)) = bad_chan;    
0095         PNBad_chan(i) = size(bad_chan,2);
0096         fclose(fid);
0097     end;
0098 
0099 fwrite(pfid,PEpoch,'int16');
0100 fwrite(pfid,PWindow_Length,'int16')
0101 fwrite(pfid,PNEpoch,'int16');    
0102 fwrite(pfid,PNbad_chan,'int16');
0103 fwrite(pfid,Pbad_chan,'int16');
0104 fwrite(pfid,Pref_flag,'int16');
0105 fwrite(pfid,Preference,'char');
0106 PNchan = (PNchan.*(PNchan+ones(1,nfiles)))/2;        
0107 fwrite(pfid,PNchan,'int16');
0108 fwrite(pfid,PNfreq,'int16');
0109 
0110     for i = 1:size(csdmfname,1)
0111         fid = open_file_w_byte_order(csdmfname(i,:),-1);
0112         version = fread(fid,1,'int16');
0113         if version ~= -1
0114             error(['file: ' csdmfname(i,:) 'is not a csdm file']);
0115             fclose(fid)
0116         end;
0117         [Epoch,Window_Length,NEpoch,Nbad_chan,bad_chan,reference,ravgcsdm,iavgcsdm] = rd_csdm(fid);
0118         avg_coherence = eeg_coherence(ravgcsdm,iavgcsdm,bad_chan);
0119         fwrite(pfid,avg_coherence','float');
0120         fclose(fid);
0121     end;
0122 
0123 fclose(pfid)
0124 status = 1;
0125     
0126     
0127 
0128 
0129

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003