Home > eeg > egis > scripts > make_eeg_phase.m

make_eeg_phase

PURPOSE ^

status = make_eeg_phase(csdmfname,powerfname,obs_labels,add_bad);

SYNOPSIS ^

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

DESCRIPTION ^

status = make_eeg_phase(csdmfname,powerfname,obs_labels,add_bad);
generate multisubject/multistate phasefile from multiple csdm
mat files
csdmfname = 
    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)
phasefname = output filename - can be gui. 
obs_labels = labels for observations (optional),default = csdmfname 
add_bad = even more bad channels
in cases of multiple files and publication/presentation quality graphics
it is STRONGLY SUGGESTED that you make a short (2-6character) label for each 
observation. 
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
 
csdmfname = [010_12.EEG.RAW.csdm.aver.w01;010_12.EEG.RAW.csdm.aver.w02;
             010_12.EEG.RAW.csdm.aver.w10];
make_eeg_phase(csdmfname)
or
make_eeg_phase(csdmfname,'010_12.phase',[Obs_01;Obs_02;Obs_10]);

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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

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