Home > eeg > egis > scripts > laplacian_ave.m

laplacian_ave

PURPOSE ^

function status=laplacian_ave(bad_chan,infname)

SYNOPSIS ^

function status=laplacian_ave(bad_chan,infname)

DESCRIPTION ^

function status=laplacian_ave(bad_chan,infname) 
calculate surface laplacian of an average ERP file.  Do not use this 
on power or coherence files.  

parameters
    bad_chan = bad_channels (optional).  If bad channels are specified
    there must be one row for every observation in the egis file
    infname = input filename (optional)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function status=laplacian_ave(bad_chan,infname)
0002 %function status=laplacian_ave(bad_chan,infname)
0003 %calculate surface laplacian of an average ERP file.  Do not use this
0004 %on power or coherence files.
0005 %
0006 %parameters
0007 %    bad_chan = bad_channels (optional).  If bad channels are specified
0008 %    there must be one row for every observation in the egis file
0009 %    infname = input filename (optional)
0010 
0011 %Modification History
0012 %    2/96 Created by Ramesh Srinivasan, master of the universe
0013 %
0014 %comments on modification history
0015 %
0016 status = -1;
0017 
0018 %Check number of input arguments
0019 if ~((nargin == 1)|(nargin == 2)|(nargin == 0))
0020     error('Number of input arguments must be either 1 2 or 0 moron.');
0021 end
0022 %Initialize fids
0023 srcfid = -1;
0024 destfid = -1;
0025 if nargin == 0
0026     bad_chan = [];
0027 end;
0028 %First try batch mode
0029 if nargin == 2
0030     srcfid = fopen(infname, 'r','b');
0031     if srcfid == -1
0032         error(['Could not open input file ' infname '.']);
0033     end
0034     outfname = [infname '_lap'];
0035     destfid = fopen(outfname, 'wb','b');
0036     if destfid == -1
0037         temp =fclose(srcfid);
0038         error(['Could not open output file ' outfname '.']);
0039     end
0040 %Otherwise run interactive mode
0041 else
0042     while srcfid == -1
0043         [srcfid, infname]=get_fid('r','*', 'Open Average File:');
0044     end
0045     outfname = [infname '_lap'];
0046     destfid = fopen(outfname, 'wb');
0047     if destfid == -1
0048         temp =fclose(srcfid);
0049         error(['Could not open output file ' outfname '.']);
0050     end
0051     end
0052 end
0053 
0054 %Call EGIS hdr index script
0055 ave_hdr_offsets_v;
0056 %Read in the EGIS header
0057 [fhdr,chdr,ename,czeros,cgains,cnames,fcom,ftext, coff]=rd_egis_hdr_v(srcfid);
0058 
0059 
0060 % Copy source header to destination file
0061 frewind(srcfid);
0062 [temp, countin] = fread(srcfid, fhdr(LHeader), 'char');
0063 countout = fwrite(destfid, temp, 'char');
0064 if countin ~= countout
0065   error('Error copying header information');
0066 end
0067 % CREATE CHANNEL MASK
0068 good_chan_mask = ones(chdr(1,NObs),fhdr(NChan));
0069 
0070 
0071 if bad_chan ~= []
0072   % Check to see if number of rows in obs and bad_chans jives
0073   nrows_bad = size(bad_chan,1);
0074   if chdr(1,NObs) ~= nrows_bad
0075     disp(['WARNING: Number of observations (' int2str(nobs) ') doesn''t match number of rows in bad_chan (' int2str(nrows_bad) ')']);
0076     if nrows_bad == 1
0077       disp('Assuming bad_chan applies to all observations');
0078       bad_chan = ones(size(good_chan_mask,1))*bad_chan;
0079     else
0080       error('Drastic mismatch between nobs and bad_chan')
0081     end
0082   end
0083   
0084   for isub = 1:size(good_chan_mask,1)
0085         bchan = find(bad_chan(isub,:));
0086   good_chan_mask(isub,bad_chan(isub,bchan)) = zeros(1,size(bchan,2));
0087       end;
0088  
0089       
0090 end;
0091 
0092 [xelec,yelec,zelec] = electrodes(fhdr(NChan));
0093 
0094 %Begin looping through cells
0095 for c=1:fhdr(NCells)
0096     disp(['Processing cell: ' int2str(c)]);
0097 
0098     %Loop through subject averages
0099     for t=1:chdr(c,NObs)
0100         trialdata = rd_onetr_allch(srcfid, coff(c), t, fhdr(NChan), chdr(c, NPoints));
0101         lap_trialdata = zeros(size(trialdata,1),size(trialdata,2));
0102         good_chan = find(good_chan_mask(t,:));
0103         lap_trialdata = laplacian_trial(trialdata,good_chan,xelec,yelec,zelec);
0104         fwrite(destfid, lap_trialdata', 'int16');
0105         
0106         
0107     end     %for t=1:chdr(c,NObs)
0108 end     %for c=1:fhdr(NCells)
0109 
0110 disp('Finished running laplacian_ave. Have a nice day');
0111 temp=fclose(srcfid);
0112 temp=fclose(destfid);
0113 status = 1;

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