Home > eeg > egis > scripts > make_eeg_power.m

make_eeg_power

PURPOSE ^

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

SYNOPSIS ^

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

DESCRIPTION ^

status = make_eeg_power(csdmfname,powerfname,obs_labels,add_bad);
generate multisubject/multistate powerfile 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)
powerfname = output filename - can be gui. 
obs_labels = labels for observations (optional),default = csdmfname 
add_bad = channels to declare bad
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_power(csdmfname)
or
make_eeg_power(csdmfname,'010_12.power',[Obs_01;Obs_02;Obs_10]);

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function status = make_eeg_power(csdmfname,powerfname,obs_labels,add_bad);
0002 %status = make_eeg_power(csdmfname,powerfname,obs_labels,add_bad);
0003 %generate multisubject/multistate powerfile 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 %powerfname = output filename - can be gui.
0012 %obs_labels = labels for observations (optional),default = csdmfname
0013 %add_bad = channels to declare bad
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_power(csdmfname)
0025 %or
0026 %make_eeg_power(csdmfname,'010_12.power',[Obs_01;Obs_02;Obs_10]);
0027 %
0028 if nargin < 1
0029     [fid, csdmfname] = get_fid('rb');
0030     if fid < 0
0031         error('invalid filename')
0032     end;
0033     fclose(fid);
0034 end;
0035 
0036 if nargin < 2
0037     [pfid,powerfname] = put_fid('rb');
0038     obs_labels = csdmfname;
0039     fclose(pfid);
0040 end;
0041 
0042 if nargin < 3
0043     obs_labels = csdmfname;
0044 end;
0045 if isempty(powerfname)
0046     [pfid,powerfname] = put_fid('rb');
0047     fclose(pfid);
0048 end;
0049 version = -3;
0050 pfid = fopen(powerfname,'wb');
0051 fwrite(pfid,version,'int16');
0052 fwrite(pfid,size(csdmfname,1),'int16');
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 PEpoch = zeros(1,nfiles);
0059 PWindow_Length = zeros(1,nfiles);
0060 PNEpoch = zeros(1,nfiles);
0061 PNbad_chan = zeros(1,nfiles);
0062 Pbad_chan = zeros(nfiles,129);
0063 Pref_flag = zeros(1,nfiles);
0064 PNchan = zeros(1,nfiles);
0065 PNfreq = zeros(1,nfiles); 
0066 Preference = zeros(nfiles,129);
0067 
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         if Pref_flag(i) ~= 6
0078         Preference(i,1:size(reference,2)) = reference;
0079         else
0080         Preference(i,1:size(reference,2)) = int2str(reference);
0081         end;
0082         if strcmp(reference,'laplacian')
0083             bad_chan = [bad_chan 22 26 33 39 45 57 64 70 75 83 90 96 101 115 121 1 8 14];
0084         end
0085         if nargin == 4
0086         bad_chan = [bad_chan add_bad(i,:)];
0087         end;
0088         Pbad_chan(i,1:size(bad_chan,2)) = bad_chan;
0089         PNbad_chan(i) = size(bad_chan,2);
0090         fclose(fid);
0091     end;
0092 
0093 fwrite(pfid,PEpoch,'int16');
0094 fwrite(pfid,PWindow_Length,'int16')
0095 fwrite(pfid,PNEpoch,'int16');    
0096 fwrite(pfid,PNbad_chan,'int16');
0097 fwrite(pfid,Pbad_chan,'int16');
0098 fwrite(pfid,Pref_flag,'int16');
0099 fwrite(pfid,Preference,'char');        
0100 fwrite(pfid,PNchan,'int16');
0101 fwrite(pfid,PNfreq,'int16');
0102 
0103     for i = 1:size(csdmfname,1)
0104         fid = fopen(csdmfname(i,:),'rb');
0105         version = fread(fid,1,'int16');
0106         if version ~= -1
0107             error(['file: ' csdmfname(i,:) 'is not a csdm file']);
0108             fclose(fid)
0109         end;
0110         [Epoch,Window_Length,NEpoch,Nbad_chan,bad_chan,reference,ravgcsdm,iavgcsdm] = rd_csdm(fid);
0111         power = eeg_power(ravgcsdm);
0112         fwrite(pfid,power','float');
0113         fclose(fid);
0114     end;
0115 
0116 fclose(pfid)
0117 status = 1;
0118     
0119     
0120 
0121 
0122 
0123 
0124 
0125 
0126 
0127 
0128 
0129 
0130 
0131 
0132 
0133

Generated on Wed 20-Mar-2019 04:00:51 by m2html © 2003