Home > vbmeg > functions > device > eeg > brainamp > in_events_brainamp.m

in_events_brainamp

PURPOSE ^

IN_EVENTS_BRAINAMP: Open a BrainVision BrainAmp .vmrk file.

SYNOPSIS ^

function events = in_events_brainamp(sFile, EventFile)

DESCRIPTION ^

 IN_EVENTS_BRAINAMP: Open a BrainVision BrainAmp .vmrk file.

 OUTPUT:
    - events(i): array of structures with following fields (one structure per event type) 
        |- label   : Identifier of event #i
        |- samples : Array of unique time indices for event #i in the corresponding raw file
        |- times   : Array of unique time latencies (in seconds) for event #i in the corresponding raw file
                     => Not defined for files read from -eve.fif files

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function events = in_events_brainamp(sFile, EventFile)
0002 % IN_EVENTS_BRAINAMP: Open a BrainVision BrainAmp .vmrk file.
0003 %
0004 % OUTPUT:
0005 %    - events(i): array of structures with following fields (one structure per event type)
0006 %        |- label   : Identifier of event #i
0007 %        |- samples : Array of unique time indices for event #i in the corresponding raw file
0008 %        |- times   : Array of unique time latencies (in seconds) for event #i in the corresponding raw file
0009 %                     => Not defined for files read from -eve.fif files
0010 
0011 % @=============================================================================
0012 % This software is part of the Brainstorm software:
0013 % http://neuroimage.usc.edu/brainstorm
0014 %
0015 % Copyright (c)2000-2013 Brainstorm by the University of Southern California
0016 % This software is distributed under the terms of the GNU General Public License
0017 % as published by the Free Software Foundation. Further details on the GPL
0018 % license can be found at http://www.gnu.org/copyleft/gpl.html.
0019 %
0020 % FOR RESEARCH PURPOSES ONLY. THE SOFTWARE IS PROVIDED "AS IS," AND THE
0021 % UNIVERSITY OF SOUTHERN CALIFORNIA AND ITS COLLABORATORS DO NOT MAKE ANY
0022 % WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
0023 % MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, NOR DO THEY ASSUME ANY
0024 % LIABILITY OR RESPONSIBILITY FOR THE USE OF THIS SOFTWARE.
0025 %
0026 % For more information type "brainstorm license" at command prompt.
0027 % =============================================================================@
0028 %
0029 % Authors: Francois Tadel, 2012
0030 
0031 
0032 % Open and read file
0033 fid = fopen(EventFile,'r');
0034 % Markers list
0035 Markers = {};
0036 isMarkerSection = 0;
0037 % Read file line by line
0038 while 1
0039     % Read one line
0040     newLine = fgetl(fid);
0041     if ~ischar(newLine)
0042         break;
0043     end
0044     % Lines to skip
0045     if isempty(newLine)
0046         continue;
0047     elseif ~isempty(strfind(newLine, '[Marker Infos]'))
0048         isMarkerSection = 1;
0049     elseif ~isMarkerSection || ismember(newLine(1), {'[', ';', char(10), char(13)}) || ~any(newLine == '=')
0050         continue;
0051     end
0052     % Split around the '=' and ','
0053     argLine = strtrim(str_split(newLine, '=,', 0));
0054     if (length(argLine) < 6) || (length(argLine{1}) < 2)
0055         continue;
0056     end
0057     % Markers start with 'Mk'
0058     if ~strcmpi(argLine{1}(1:2), 'Mk')
0059         continue;
0060     end
0061     % Marker label
0062     if ~isempty(argLine{3})
0063         mlabel = argLine{3};
0064     else
0065         mlabel = 'Mk';
0066     end
0067     % Add markers entry: {name, type, start, length}
0068     Markers(end+1,:) = {mlabel, argLine{2}, str2num(argLine{4}), str2num(argLine{5})};
0069 end
0070 % Close file
0071 fclose(fid);
0072 
0073 % List of events
0074 uniqueEvt = unique(Markers(:,1)');
0075 % Initialize returned structure
0076 events = repmat(db_template('event'), [1, length(uniqueEvt)]);
0077 % Create events list
0078 for iEvt = 1:length(uniqueEvt)
0079     % Find all the occurrences of event #iEvt
0080     iMrk = find(strcmpi(Markers(:,1)', uniqueEvt{iEvt}));
0081     % Add event structure
0082     events(iEvt).label   = uniqueEvt{iEvt};
0083     events(iEvt).epochs  = ones(1, length(iMrk));   
0084     events(iEvt).samples = [Markers{iMrk,3}];
0085     if any([Markers{iMrk,4}] > 1)
0086         events(iEvt).samples(2,:) = [Markers{iMrk,3}] + [Markers{iMrk,4}];
0087     end
0088     events(iEvt).times      = events(iEvt).samples ./ sFile.prop.sfreq;
0089     events(iEvt).reactTimes = [];
0090     events(iEvt).select     = 1;
0091 end
0092 
0093 
0094

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