Home > eeg > egis > net_utils > new_reference.m

new_reference

PURPOSE ^

SYNOPSIS ^

function [ref_trialdata,mask] = new_reference(trialdata,mask,reference);

DESCRIPTION ^

ref_trialdata = new_reference(trialdata,mask,reference);

 trialdata = trial of data, obviously
 mask = array of zeros and ones with ones indicating good chan
 reference = text or channel_list indicating valid reference type: 
these types are:
    'average' = average reference
    'avgmast' = mathematically averaged mastoids 
    'perimeter' = perimeter reference (see Shaw thesis for logic)
    channel_list = list of channels to average together and use as 
        reference, e.g. [7 86], will reference the data to the average
        of channels 7 and 86.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [ref_trialdata,mask] = new_reference(trialdata,mask,reference);
0002 %
0003 %ref_trialdata = new_reference(trialdata,mask,reference);
0004 %
0005 % trialdata = trial of data, obviously
0006 % mask = array of zeros and ones with ones indicating good chan
0007 % reference = text or channel_list indicating valid reference type:
0008 %these types are:
0009 %    'average' = average reference
0010 %    'avgmast' = mathematically averaged mastoids
0011 %    'perimeter' = perimeter reference (see Shaw thesis for logic)
0012 %    channel_list = list of channels to average together and use as
0013 %        reference, e.g. [7 86], will reference the data to the average
0014 %        of channels 7 and 86.
0015 %
0016 if ~(nargin  == 2|nargin == 3)
0017     error('incorrect number of input arguments')
0018 end
0019 
0020 if nargin == 2
0021     reference = 'average';
0022 end;
0023 
0024 if size(trialdata,2)+1 ~= size(mask,2)
0025     error('mismatch between trialdata and mask');
0026 end;
0027 
0028 if strcmp(reference,'average')
0029     ref_trialdata = average_reference(trialdata,mask);
0030 end;
0031 
0032 if strcmp(reference,'vertex')
0033     ref_trialdata = zeros(size(trialdata,1),size(trialdata,2)+1);
0034     ref_trialdata(1:size(trialdata,1),1:size(trialdata,2)) = trialdata;
0035 end
0036 if strcmp(reference,'avgmast')
0037     channel_list = [57 101];
0038 elseif strcmp(reference,'perimeter')
0039     channel_list = [14 8 1 121 115 101 96 90 83 75 70 64 57 45 39 33 26 22];
0040 end;
0041 
0042 if ~(strcmp(reference,'average')|strcmp(reference,'vertex'))
0043     if size(channel_list,2) > 1    
0044         cmask = zeros(1,size(mask,2));
0045         cmask(channel_list) = ones(1,size(channel_list,2));
0046         cmask = mask.*cmask;
0047         chan_list = find(cmask);
0048         ref_trialdata = zeros(size(trialdata,1),size(mask,2));
0049         ref_trialdata(:,1:size(trialdata,2)) = trialdata;
0050         if size(chan_list,2) > 1
0051         ref_sig = (mean(trialdata(:,chan_list)'))';
0052         ref_trialdata = ref_trialdata - ref_sig*ones(1,size(ref_trialdata,2));
0053         else
0054         mask == zeros(1,size(cmask,2));
0055         end;
0056     else
0057         cmask = zeros(1,size(mask,2));
0058         cmask(channel_list) = ones(1,size(channel_list,2));
0059         cmask = mask.*cmask;
0060         chan_list = find(cmask);
0061         ref_trialdata = zeros(size(trialdata,1),size(mask,2));
0062         if chan_list == []
0063             mask = zeros(1,size(mask,2))
0064         else
0065             ref_sig = trialdata(:,chan_list);
0066             ref_trialdata = ref_trialdata - ref_sig*ones(1,size(ref_trialdata,2));
0067         end;
0068     end
0069 end;
0070 
0071 
0072 
0073 
0074 
0075 
0076

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