Home > eeg > egis > scripts > run_eeg_csdm.m

run_eeg_csdm

PURPOSE ^

status = run_eeg_csdm(rawfname,add_bad_chan,windows,reference,max_freq,

SYNOPSIS ^

function status = run_eeg_csdm(rawfname,add_bad_chan,windows,reference,max_freq,Epoch,Max_microv,Min_Chan,LoPass,HiPass);

DESCRIPTION ^

status = run_eeg_csdm(rawfname,add_bad_chan,windows,reference,max_freq,
            Epoch,Max_microv,Min_Chan,LoPass,HiPass);

makes cross spectral density function files (version = -1 file)
from a NSFragger raw2  file. This is the main routine for spectral analysis

rawfname = cross spectral density filename. Can submit a blank [] for gui
add_bad_chan = additional bad channels over artifact editing (optional)
windows = epochs to use in the analysis.  By epochs I mean that the units 
    of this parameter are epochs which are either specified in the edit 
    code file or as the parameter Epoch, e.g. [2:4 7], means use epochs
    2,3,4 and 7 in the average.  If Epoch = 1 this is 4 seconds of EEG;
    if Epoch = 2 this is 8 seconds of EEG but still only 4 epochs in the 
    average (optional - default is whole file)
reference = reference to use legal values are: 'average', 'avgmast', 
    'perimeter','laplacian','vertex'. Or else a channel list can be
    submitted, e.g. [5 6 7], or 'cortical05', 'cortical10' for cortical
    filtering routines. 
    optional - default is 'average' 
max_freq = highest frequency to save data (must be less than SampRate/2)
            default is 50 Hz
If you have previously edited the file stop here. if not add the following 
params to edit 
Epoch = epoch length to use 
Max_microv = maximumvoltage in microvolts
Min_Chan = minimum number of channels
LoPass = optional lowpass filter settings (optional)
HiPass = optional hipass settings. (optional)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function status = run_eeg_csdm(rawfname,add_bad_chan,windows,reference,max_freq,Epoch,Max_microv,Min_Chan,LoPass,HiPass);
0002 %status = run_eeg_csdm(rawfname,add_bad_chan,windows,reference,max_freq,
0003 %            Epoch,Max_microv,Min_Chan,LoPass,HiPass);
0004 %
0005 %makes cross spectral density function files (version = -1 file)
0006 %from a NSFragger raw2  file. This is the main routine for spectral analysis
0007 %
0008 %rawfname = cross spectral density filename. Can submit a blank [] for gui
0009 %add_bad_chan = additional bad channels over artifact editing (optional)
0010 %windows = epochs to use in the analysis.  By epochs I mean that the units
0011 %    of this parameter are epochs which are either specified in the edit
0012 %    code file or as the parameter Epoch, e.g. [2:4 7], means use epochs
0013 %    2,3,4 and 7 in the average.  If Epoch = 1 this is 4 seconds of EEG;
0014 %    if Epoch = 2 this is 8 seconds of EEG but still only 4 epochs in the
0015 %    average (optional - default is whole file)
0016 %reference = reference to use legal values are: 'average', 'avgmast',
0017 %    'perimeter','laplacian','vertex'. Or else a channel list can be
0018 %    submitted, e.g. [5 6 7], or 'cortical05', 'cortical10' for cortical
0019 %    filtering routines.
0020 %    optional - default is 'average'
0021 %max_freq = highest frequency to save data (must be less than SampRate/2)
0022 %            default is 50 Hz
0023 %If you have previously edited the file stop here. if not add the following
0024 %params to edit
0025 %Epoch = epoch length to use
0026 %Max_microv = maximumvoltage in microvolts
0027 %Min_Chan = minimum number of channels
0028 %LoPass = optional lowpass filter settings (optional)
0029 %HiPass = optional hipass settings. (optional)
0030 if nargin < 1
0031     error('filename not specified');
0032 end;
0033 if isempty(rawfname)
0034     [fid, rawfname] = get_fid('rb');
0035     if (fid < 0)
0036         error('error opening data file')
0037         fclose('all')
0038     end;
0039     fclose(fid);
0040     fid = fopen(rawfname,'rb','b');
0041 else
0042     fid = fopen(rawfname,'rb','b');
0043     if (fid < 0)
0044         error('error opening data file')
0045         fclose('all')
0046     end;
0047 end;
0048 
0049 if ~(nargin ==1 | nargin ==2|nargin == 3| nargin ==4|nargin == 5|nargin == 9|nargin == 10|nargin == 8)
0050     error('inproper number of input arguments')
0051 end;
0052 if nargin < 8
0053     [Epoch,NEpoch,Max_microv,Min_Chan,Nbad_chan,bad_chan,mmask] = read_mask(rawfname);
0054 end;
0055 if nargin == 1
0056     add_bad_chan = [];
0057     windows = [1:size(mmask,1)];
0058     reference = ['average'];
0059     max_freq = 50;
0060 end;
0061 if nargin == 2
0062     windows = [1:size(mmask,1)];
0063     reference = ['average'];
0064     max_freq = 50;
0065 end;
0066 if nargin == 3
0067     reference = ['average'];
0068     max_freq = 50;
0069 end;
0070 if nargin == 4
0071     max_freq = 50;
0072 end;
0073 
0074 if (isempty(windows) & nargin < 8)
0075     windows = [1:size(mmask,1)];
0076 end;
0077 if isempty(reference)
0078     reference = 'average';
0079 end;
0080 if isempty(max_freq)
0081     max_freq = 50;
0082 end
0083 
0084 if nargin == 10
0085     [header_array, EventCodes,Samp_Rate, NChan, scale, NSamp, NEvenp] = rd_fragger_hdr(fid);
0086     [Epoch, NEpoch,Max_microv,Min_Chan,NBad_chan,bad_chan,mmask] = ns_artifact_edit(fid,Samp_Rate,NChan, NSamp, NEvent,scale,Epoch,Max_microv,Min_Chan,Lo_Pass,Hi_Pass); 
0087 end
0088 if nargin == 9
0089     [header_array, EventCodes,Samp_Rate, NChan, scale, NSamp, NEvent] = rd_fragger_hdr(fid);
0090     [Epoch, NEpoch,Max_microv,Min_Chan,NBad_chan,bad_chan,mmask] = ns_artifact_edit(fid,Samp_Rate,NChan, NSamp, NEvent,scale,Epoch,Max_microv,Min_Chan,Lo_Pass);
0091 end;
0092 if nargin == 8
0093     [header_array, EventCodes,Samp_Rate, NChan, scale, NSamp, NEvent] = rd_fragger_hdr(fid);
0094     [Epoch, NEpoch,Max_microv,Min_Chan,NBad_chan,bad_chan,mmask] = ns_artifact_edit(fid,Samp_Rate,NChan, NSamp, NEvent,scale,Epoch,Max_microv,Min_Chan);
0095 end;
0096 fclose(fid);
0097 if isempty(windows)
0098     windows = [1:size(mmask,2)];
0099 end;
0100 for i = 1:size(windows,1)
0101     if size(windows,1) > 1    
0102         if i < 10
0103             text_lab = ['.' reference(1,1:4) '.w.0'];
0104         else
0105             text_lab = ['.' reference(1,1:4) '.w.'];
0106         end;
0107         csdmfname = [rawfname(1:size(rawfname,2)-8) '.csdm.' text_lab int2str(i)];
0108     else
0109         csdmfname = [rawfname(1:size(rawfname,2)-8) '.' reference(1,1:4) '.csdm'];
0110     end;
0111     csdmfid = fopen(csdmfname,'wb');
0112     if nargin >= 8
0113         [Epoch,NEpoch_used,Nbad_chan,bad_chan,avgcsdm] = raw_eeg_csdm(rawfname,add_bad_chan,windows(i,:),reference,Epoch,NEpoch,Nbad_chan,bad_chan,mmask);
0114     else
0115         [Epoch,NEpoch_used,Nbad_chan,bad_chan,avgcsdm] = raw_eeg_csdm(rawfname,add_bad_chan,windows(i,:),reference);
0116     end;
0117     version = -1;
0118     fwrite(csdmfid,version,'integer*2');
0119     fwrite(csdmfid,Epoch,'integer*2');
0120     fwrite(csdmfid,size(windows,2)*Epoch,'integer*2')
0121     fwrite(csdmfid,NEpoch_used,'integer*2');    
0122     fwrite(csdmfid,Nbad_chan,'integer*2');
0123     fwrite(csdmfid,bad_chan,'integer*2');
0124     if strcmp(reference,'average')
0125         ref_flag = 1;
0126     elseif strcmp(reference,'avgmast')
0127         ref_flag = 2;
0128     elseif strcmp(reference,'perimeter');
0129         ref_flag = 3;
0130     elseif strcmp(reference,'vertex');
0131         ref_flag = 4;
0132     elseif strcmp(reference,'laplacian');
0133         ref_flag = 5;
0134     elseif strcmp(reference(1:8),'cortical');
0135         ref_flag = 7;
0136     else
0137         ref_flag = 6;
0138     end;
0139     fwrite(csdmfid,ref_flag,'integer*2');
0140     if ref_flag == 6
0141         fwrite(csdmfid, size(reference,2),'integer*2');
0142         fwrite(csdmfid, reference,'integer*2');
0143     end;
0144     if ref_flag == 7
0145         sigma_v = str2num(reference(9:10));
0146         fwrite(csdmfid,sigma_v,'integer*2');
0147     end;
0148     max_freq = max_freq*Epoch+1;
0149     fwrite(csdmfid,max_freq,'integer*2');
0150     fwrite(csdmfid,size(avgcsdm,2),'integer*2');
0151     fwrite(csdmfid,real(avgcsdm(1:max_freq,:))','real*4');
0152     fwrite(csdmfid,imag(avgcsdm(1:max_freq,:))','real*4');
0153     fclose(csdmfid);
0154 end;
0155 status = 1;
0156 fclose('all');
0157     
0158 
0159 
0160 
0161 
0162 
0163 
0164 
0165 
0166 
0167 
0168 
0169 
0170 
0171 
0172

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