Home > vbmeg > external > mne > mne_ex_read_raw.m

mne_ex_read_raw

PURPOSE ^

SYNOPSIS ^

function [data,times] = mne_ex_read_raw(fname,from,to,in_samples,dest_comp)

DESCRIPTION ^

   Example of reading raw data

   [ data, times ] = mne_ex_read_raw(fname,from,to,in_samples,dest_comp);

   data        - The data read, compensated and projected, channel by
                 channel
   times       - The time points of the samples, in seconds


   fname       - The name of the input file
   from        - Starting time or sample
   to          - Ending time or sample
   in_samples  - Are from and to given in samples rather than in seconds
                 (optional)
   dest_comp   - Desired (CTF) compensation in the output data (optional)

   NOTE: The purpose of this function is to demonstrate the raw data reading
   routines. In real world, you probably make multiple calls to
   fiff_read_raw_segment_times or fiff_read_raw_segment
   between open and close

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [data,times] = mne_ex_read_raw(fname,from,to,in_samples,dest_comp)
0002 %
0003 %   Example of reading raw data
0004 %
0005 %   [ data, times ] = mne_ex_read_raw(fname,from,to,in_samples,dest_comp);
0006 %
0007 %   data        - The data read, compensated and projected, channel by
0008 %                 channel
0009 %   times       - The time points of the samples, in seconds
0010 %
0011 %
0012 %   fname       - The name of the input file
0013 %   from        - Starting time or sample
0014 %   to          - Ending time or sample
0015 %   in_samples  - Are from and to given in samples rather than in seconds
0016 %                 (optional)
0017 %   dest_comp   - Desired (CTF) compensation in the output data (optional)
0018 %
0019 %   NOTE: The purpose of this function is to demonstrate the raw data reading
0020 %   routines. In real world, you probably make multiple calls to
0021 %   fiff_read_raw_segment_times or fiff_read_raw_segment
0022 %   between open and close
0023 %
0024 
0025 %
0026 %   Author : Matti Hamalainen, MGH Martinos Center
0027 %   License : BSD 3-clause
0028 %
0029 %   Revision 1.5  2008/11/18 02:38:51  msh
0030 %   Modified mne_ex_read_evoked to apply projection and compensation
0031 %   Modified mne_ex_read_raw to call mne_set_current_comp
0032 %
0033 %   Revision 1.4  2006/05/16 00:39:32  msh
0034 %   Fixed error in mne_ex_read_raw: All projection items were not activated.
0035 %   List the initial states of projection items when they are loaded.
0036 %
0037 %   Revision 1.3  2006/05/05 03:50:40  msh
0038 %   Added routines to compute L2-norm inverse solutions.
0039 %   Added mne_write_inverse_sol_stc to write them in stc files
0040 %   Several bug fixes in other files
0041 %
0042 %   Revision 1.2  2006/04/23 15:29:40  msh
0043 %   Added MGH to the copyright
0044 %
0045 %   Revision 1.1  2006/04/21 17:31:07  msh
0046 %   Added the examples.
0047 %   Modified the formatting of some informative output.
0048 %
0049 %
0050 
0051 %
0052 %   Fiddle with the arguments
0053 %
0054 me='MNE:mne_ex_read_raw';
0055 
0056 keep_comp = false;
0057 if nargin == 3
0058     in_samples = false;
0059     keep_comp = true;
0060 elseif nargin == 4
0061     keep_comp = true;
0062 elseif nargin ~= 5
0063     error(me,'Incorrect number of arguments');
0064 end
0065 %
0066 %   Setup for reading the raw data
0067 %
0068 try
0069     raw = fiff_setup_read_raw(fname);
0070 catch
0071     error(me,'%s',mne_omit_first_line(lasterr));
0072 end
0073 %
0074 %   Set up pick list: MEG + STI 014 - bad channels
0075 %
0076 include{1} = 'STI 014';
0077 want_meg   = true;
0078 want_eeg   = false;
0079 want_stim  = false;
0080 %
0081 picks = fiff_pick_types(raw.info,want_meg,want_eeg,want_stim,include,raw.info.bads);
0082 %
0083 %   Set up projection
0084 %
0085 if isempty(raw.info.projs)
0086     fprintf(1,'No projector specified for these data\n');
0087     raw.proj = [];
0088 else
0089     %
0090     %   Activate the projection items
0091     %
0092     for k = 1:length(raw.info.projs)
0093         raw.info.projs(k).active = true;
0094     end
0095     fprintf(1,'%d projection items activated\n',length(raw.info.projs));
0096     %
0097     %   Create the projector
0098     %
0099     [proj,nproj] = mne_make_projector_info(raw.info);
0100     if nproj == 0
0101         fprintf(1,'The projection vectors do not apply to these channels\n');
0102         raw.proj = [];
0103     else
0104         fprintf(1,'Created an SSP operator (subspace dimension = %d)\n',nproj);
0105         raw.proj = proj;
0106     end
0107 end
0108 %
0109 %   Set up the CTF compensator
0110 %
0111 current_comp = mne_get_current_comp(raw.info);
0112 if current_comp > 0
0113     fprintf(1,'Current compensation grade : %d\n',current_comp);
0114 end
0115 if keep_comp
0116     dest_comp = current_comp;
0117 end
0118 if current_comp ~= dest_comp
0119     try
0120         raw.comp = mne_make_compensator(raw.info,current_comp,dest_comp);
0121         raw.info.chs  = mne_set_current_comp(raw.info.chs,dest_comp);
0122         fprintf(1,'Appropriate compensator added to change to grade %d.\n',dest_comp);
0123     catch
0124         error(me,'%s',mne_omit_first_line(lasterr));
0125     end
0126 end
0127 %
0128 %   Read a data segment
0129 %   times output argument is optional
0130 %
0131 try
0132     if in_samples
0133         [ data, times ] = fiff_read_raw_segment(raw,from,to,picks);
0134     else
0135         [ data, times ] = fiff_read_raw_segment_times(raw,from,to,picks);
0136     end
0137 catch
0138     fclose(raw.fid);
0139     error(me,'%s',mne_omit_first_line(lasterr));
0140 end
0141 fprintf(1,'Read %d samples.\n',size(data,2));
0142 
0143 return;
0144 
0145 end

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