Home > eeg > egis > scripts > laplacian_ses.m

laplacian_ses

PURPOSE ^

function status=laplacian_ses(bad_chan,infname)

SYNOPSIS ^

function status=laplacian_ses(bad_chan,infname)

DESCRIPTION ^

function status=laplacian_ses(bad_chan,infname)
calculate surface laplacian of a session file.  

parameters
    infname = input filename
    outfname = output filename.  
Modification History
    2/96 Created by Ramesh Srinivasan, master of the universe

comments on modification history

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function status=laplacian_ses(bad_chan,infname)
0002 %function status=laplacian_ses(bad_chan,infname)
0003 %calculate surface laplacian of a session file.
0004 %
0005 %parameters
0006 %    infname = input filename
0007 %    outfname = output filename.
0008 %Modification History
0009 %    2/96 Created by Ramesh Srinivasan, master of the universe
0010 %
0011 %comments on modification history
0012 %
0013 status = -1;
0014 %Check number of input arguments
0015 if ~((nargin == 1)|(nargin == 2)|(nargin == 0))
0016     error('Number of input arguments must be either 1 2 or 0 moron.');
0017 end
0018 %Initialize fids
0019 srcfid = -1;
0020 destfid = -1;
0021 if nargin == 0
0022     bad_chan = [];
0023 end;
0024 %First try batch mode
0025 if nargin == 2
0026     srcfid = fopen(infname, 'r');
0027     if srcfid == -1
0028         error(['Could not open input file ' infname '.']);
0029     end
0030     outfname = [infname '_lap'];
0031     destfid = fopen(outfname, 'wb');
0032     if destfid == -1
0033         temp =fclose(srcfid);
0034         error(['Could not open output file ' outfname '.']);
0035     end
0036 %Otherwise run interactive mode
0037 else
0038     while srcfid == -1
0039         [srcfid, infname]=get_fid('r','*', 'Open Session File:');
0040     end
0041     outfname = [infname '_lap'];
0042     destfid = fopen(outfname, 'wb');
0043     if destfid == -1
0044         temp =fclose(srcfid);
0045         error(['Could not open output file ' outfname '.']);
0046     end
0047     end
0048 end
0049 
0050 %Call EGIS hdr index script
0051 ses_hdr_offsets_v;
0052 %Read in the EGIS header
0053 [fhdr,chdr,ename,czeros,cgains,cnames,fcom,ftext, coff]=rd_egis_hdr_v(srcfid);
0054 
0055 
0056 % Copy source header to destination file
0057 frewind(srcfid);
0058 [temp, countin] = fread(srcfid, fhdr(LHeader), 'char');
0059 countout = fwrite(destfid, temp, 'char');
0060 if countin ~= countout
0061   error('Error copying header information');
0062 end
0063 % CREATE CHANNEL MASK
0064 [xelec,yelec,zelec] = electrodes(fhdr(NChan)+1);
0065 ses_mask = artifact_edit(infname, fhdr, chdr,0);
0066 
0067 %Begin looping through cells
0068 for c=1:fhdr(NCells)
0069     disp(['Processing cell: ' int2str(c)]);
0070 
0071     %Loop through observations
0072     for t=1:chdr(c,NObs)
0073         ses_mask_cell_offset = sum(chdr(1:c, NTrials)) - chdr(c,NTrials);
0074         ref_trialdata = zeros(chdr(c,NPoints), fhdr(NChan));        
0075         if sum(ses_mask(ses_mask_cell_offset + t,:)) > min_good_chan
0076             trialdata = rd_onetr_allch(srcfid, coff(c), t, fhdr(NChan), chdr(c, NPoints));
0077             avref_trialdata= average_reference(trialdata, ses_mask(ses_mask_cell_offset + t,:));
0078             lap_trialdata = zeros(size(avref_trialdata,1),size(avref_trialdata,2));
0079             
0080             good_chan = find(ses_mask(ses_mask_cell_offset + t,:));
0081             lap_trialdata = laplacian_trial(trialdata,good_chan,xelec,yelec,zelec)
0082             ref_trialdata = rereference(lap_trialdata);
0083         end;
0084         fwrite(destfid, ref_trialdata', 'int16');
0085     end     %for t=1:chdr(c,NObs)
0086 end     %for c=1:fhdr(NCells)
0087 
0088 disp('Finished running laplacian_ses. Have a nice day');
0089 temp=fclose(srcfid);
0090 temp=fclose(destfid);
0091 status = 1;

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