Home > vbmeg > external > mne > mne_ex_read_evoked.m

mne_ex_read_evoked

PURPOSE ^

SYNOPSIS ^

function [res] = mne_ex_read_evoked(fname,setno,apply_proj,dest_comp,use_ctf_head)

DESCRIPTION ^

   Load one evoked-response data set and do various kinds
   of preprocessing

   [res] = mne_ex_read_evoked(fname,setno,apply_proj,dest_comp,use_ctf_head)

   fname           - Name of the data file
   setno           - Data set number (default = 1)
   apply_proj      - Apply SSP to the data (default = true)
   dest_comp       - Desired (CTF/4D) compensation in the output data (default = keep the one in the file)
   use_ctf_head    - Use the CTF/4D head coordinate system instead of the
                     Neuromag one if available

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [res] = mne_ex_read_evoked(fname,setno,apply_proj,dest_comp,use_ctf_head)
0002 %
0003 %   Load one evoked-response data set and do various kinds
0004 %   of preprocessing
0005 %
0006 %   [res] = mne_ex_read_evoked(fname,setno,apply_proj,dest_comp,use_ctf_head)
0007 %
0008 %   fname           - Name of the data file
0009 %   setno           - Data set number (default = 1)
0010 %   apply_proj      - Apply SSP to the data (default = true)
0011 %   dest_comp       - Desired (CTF/4D) compensation in the output data (default = keep the one in the file)
0012 %   use_ctf_head    - Use the CTF/4D head coordinate system instead of the
0013 %                     Neuromag one if available
0014 %
0015 
0016 %
0017 %   Author : Matti Hamalainen, MGH Martinos Center
0018 %   License : BSD 3-clause
0019 %
0020 %   Revision 1.3  2008/11/18 02:38:51  msh
0021 %   Modified mne_ex_read_evoked to apply projection and compensation
0022 %   Modified mne_ex_read_raw to call mne_set_current_comp
0023 %
0024 %   Revision 1.2  2006/04/23 15:29:40  msh
0025 %   Added MGH to the copyright
0026 %
0027 %   Revision 1.1  2006/04/21 17:31:07  msh
0028 %   Added the examples.
0029 %   Modified the formatting of some informative output.
0030 %
0031 %
0032 
0033 me='MNE:mne_ex_read_evoked';
0034 
0035 %
0036 %  Different cases for the input arguments
0037 %
0038 if nargin == 1
0039     setno = 1;
0040     apply_proj   = true;
0041     use_ctf_head = false;
0042     keep_comp    = true;
0043 elseif nargin == 2
0044     apply_proj   = true;
0045     use_ctf_head = false;
0046     keep_comp    = true;
0047 elseif nargin == 3
0048     use_ctf_head = false;
0049     keep_comp    = true;
0050 elseif nargin == 4
0051     use_ctf_head = false;
0052     keep_comp    = false;
0053 elseif nargin == 5
0054     keep_comp     = false;
0055 else
0056     error(me,'Incorrect number of arguments');
0057 end
0058 %
0059 %   Load the desired data
0060 %
0061 fprintf(1,'\nLoading set %d from %s...\n\n',setno,fname);
0062 %
0063 try
0064     res = fiff_read_evoked(fname,setno);
0065 catch
0066     error(me,'%s',mne_omit_first_line(lasterr));
0067 end
0068 %
0069 %   Go ahead and do all kinds of interesting stuff
0070 %
0071 fprintf(1,'\nPreprocessing...\n');
0072 %
0073 %   Omit bad channels and pick MEG
0074 %   (Change this according to your needs)
0075 %
0076 want_meg   = true;
0077 want_eeg   = false;
0078 want_stim  = false;
0079 %
0080 %include{1} = 'STI 014';
0081 include = [];
0082 %
0083 res = fiff_pick_types_evoked(res,want_meg,want_eeg,want_stim,include,res.info.bads);
0084 fprintf(1,'\t%d channels remain after picking\n',res.info.nchan);
0085 %
0086 %   Handle the software gradient compensation
0087 %
0088 comp=[];
0089 current_comp = mne_get_current_comp(res.info);
0090 if current_comp > 0
0091     fprintf(1,'\tCurrent compensation grade : %d\n',current_comp);
0092 end
0093 if keep_comp
0094     dest_comp = current_comp;
0095 end
0096 if current_comp ~= dest_comp
0097     try
0098         comp = mne_make_compensator(res.info,current_comp,dest_comp);
0099         res.info.chs  = mne_set_current_comp(res.info.chs,dest_comp);
0100         fprintf(1,'\tAppropriate compensator created to change to grade %d.\n',dest_comp);
0101     catch
0102         error(me,'%s',mne_omit_first_line(lasterr));
0103     end
0104 end
0105 if ~isempty(comp)
0106     for k = 1:length(res.evoked)
0107         res.evoked(k).epochs = comp*res.evoked(k).epochs;
0108     end
0109     fprintf(1,'\tThe data are now compensated to grade %d.\n',dest_comp);
0110 end
0111 %
0112 %   Set up projection
0113 %
0114 if apply_proj
0115     if isempty(res.info.projs)
0116         fprintf(1,'\tNo projector specified in these data\n');
0117     else
0118         %
0119         %   Activate the projection items
0120         %
0121         for k = 1:length(res.info.projs)
0122             res.info.projs(k).active = true;
0123         end
0124         fprintf(1,'\t%d projection items activated\n',length(res.info.projs));
0125         %
0126         %   Create the projector
0127         %
0128         [res.info.proj,nproj] = mne_make_projector_info(res.info);
0129         if nproj == 0
0130             fprintf(1,'\tThe projection vectors do not apply to these channels\n');
0131         else
0132             fprintf(1,'\tCreated an SSP operator (subspace dimension = %d)\n',nproj);
0133             for k = 1:length(res.evoked)
0134                 res.evoked(k).epochs = res.info.proj*res.evoked(k).epochs;
0135             end
0136             fprintf(1,'\tSSP operator applied to the evoked data\n');
0137         end
0138     end
0139 end
0140 %
0141 %   Select the head coordinate system
0142 %
0143 if use_ctf_head
0144     if isempty(res.info.dev_ctf_t)
0145         error(me,'No CTF head transformation available');
0146     end
0147     meg_trans = res.info.dev_ctf_t;
0148     eeg_trans = fiff_invert_transform(res.info.ctf_head_t);
0149     fprintf(1,'\tEmploying the CTF/4D head coordinate system\n');
0150 else
0151     meg_trans = res.info.dev_head_t;
0152     eeg_trans = [];
0153     fprintf(1,'\tEmploying the Neuromag head coordinate system\n');
0154 end
0155 %
0156 %   Transform coil and electrode locations to the desired coordinate frame
0157 %
0158 res.info.chs = fiff_transform_meg_chs(res.info.chs,meg_trans);
0159 res.info.chs = fiff_transform_eeg_chs(res.info.chs,eeg_trans);
0160 %
0161 %   Create the coil definitions
0162 %
0163 try
0164     accuracy = 1;       %   Use accuracy = 2 for accurate coil definitions
0165     res.info.chs = mne_add_coil_defs(res.info.chs,accuracy);
0166 catch
0167     fprintf(1,'\tCoil definitions not added\n');
0168 end
0169 %
0170 %   N.B. If a nonstandard (in MNE sense) coil def file is used, do
0171 %
0172 if false
0173     coil_def_file = 'whatever';
0174     templates = mne_load_coil_def(coil_def_file);
0175     res.info.chs = mne_add_coil_defs(res.info.chs,accuracy,templates);
0176 end
0177 
0178 fprintf(1,'\nReady.\n\n');
0179 
0180 return;
0181 
0182 end

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005