Home > reduc > support > mainsWrapper.m

mainsWrapper

PURPOSE ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

SYNOPSIS ^

function d = mainsWrapper(d, plotparams, parm, field);

DESCRIPTION ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  function d = mainsWrapper(d, plotparams, parm, field);

    reduceData function that clears the data of the mains hum
    This works on the switched data ie use before rfactor and alpha

    sjcm
    4-nov-2010 act : forced to work on switched data 

    30-mar-2011 sjcm:  no plotting but can save plots
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function d = mainsWrapper(d, plotparams, parm, field);
0002 
0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0004 %
0005 %  function d = mainsWrapper(d, plotparams, parm, field);
0006 %
0007 %    reduceData function that clears the data of the mains hum
0008 %    This works on the switched data ie use before rfactor and alpha
0009 %
0010 %    sjcm
0011 %    4-nov-2010 act : forced to work on switched data
0012 %
0013 %    30-mar-2011 sjcm:  no plotting but can save plots
0014 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0015 
0016 useSwitch = 1;
0017 
0018 [d,q] = logcal(d, 'mains');
0019 if (q)
0020   disp('Mains correction has been applied');
0021   disp(' ')
0022 %  d=checkstatus(d, useSwitch);
0023   return
0024 end
0025 
0026 if(useSwitch)
0027   numChannels = 24;
0028 else
0029   numChannels = 6;
0030 end
0031 
0032 
0033 
0034 % check if we have the flagging parameters
0035 parFlag = checkpar(parm, 'mains');
0036 if(parFlag)
0037   filterParams = reshape(parm.mains.tukey, [4 length(parm.mains.tukey)/4])';
0038 else
0039   display('Using Default mains filtering parameters about 40Hz (alias of 60Hz mains)');
0040   filterParams = [38.9 39.9 40.1 41.1];
0041 end
0042 
0043 % THIS METHOD TAKES TOO LONG.  LET'S PUT A FILTER ABOUT 60Hz.
0044 % now we remove the mains
0045 %[mains_factors, indices] = calculate_mains(d, useSwitch);
0046 %d.correction.mains.factors = mains_factors;
0047 %d.correction.mains.indices = indices;
0048 
0049 %if(issubfield(d, 'correction', 'alpha', 'type'))
0050 %  if(d.correction.alpha.type==0)
0051 %    % using filtered data. no need for mains correction
0052 %    display('You are using filtered data');
0053 %    display('And therefore have no need for mains corrections');
0054 %    d = logcal(d, 'mains');
0055 %    return
0056 %  end
0057 %end
0058 
0059 % apply the correction.
0060 dcorr = d;
0061 for m=1:size(filterParams,1)
0062   for nn=1:numChannels
0063     dcorr = filter_data(dcorr, useSwitch, nn, filterParams(m,1), ...
0064     filterParams(m,2), filterParams(m,3), filterParams(m,4), 0);
0065   end
0066 end
0067 
0068 
0069 setPlotDisplay(plotparams.plot);
0070 
0071 % next we plot to see if there was any effect at all
0072 
0073 % only plot data that is on the blank stare
0074 if(isempty(find(dcorr.index.blank.fast)))
0075   display('No blank data to plot effect of filter');
0076 else
0077   display('Plotting Power Spectrum');
0078   display('No flagging will be allowed');
0079   if(useSwitch)
0080     d = packd(dcorr, [], 'none', 'mainsSwitch', plotparams, 'Main Plots', field, d);
0081       
0082   else
0083     d = packd(dcorr, [], 'none', 'mainsReg', plotparams, 'Main Plots', field, d);  
0084   end
0085 end
0086 
0087 
0088 
0089 % log that it has been applied
0090 d = dcorr;
0091 
0092 d = logcal(d, 'mains');
0093 
0094 
0095 return;
0096 
0097 
0098 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0099 function d=checkstatus(d, useSwitch)
0100 
0101 disp('Would you like to view the plots?')
0102 
0103 if (query)
0104   if(useSwitch)
0105     d = packd(d, [], 'none', 'mainsSwitch', 0, 'Main Plots', '');
0106   else
0107     d = packd(d, [], 'none', 'mainsReg', 0, 'Main Plots', '');  
0108   end
0109 end
0110 
0111 disp(' ')
0112 
0113

Generated on Sun 14-Jun-2015 17:12:45 by m2html © 2005