% eegplugin_eye_eeg() - Preprocess, synchronize, and analyze simultaneously % recorded eye tracking and EEG data % % Description: % EYE-EEG is an extension for EEGLAB written to facilitate joint analyses % of eye tracking and electroencephalographic (EEG) data. Among other % things, it can be used for fixation control, objective eye artifact % rejection, pupillometry, saccade and fixation detection, control of % microsaccades, eye tracker-supported ICA component selection, basic % oculomotor research, or computing fixation-related potentials (FRPs). % % EYE-EEG was developed by Olaf Dimigen and Ulrich Reinacher at % Humboldt University at Berlin, Germany, 2009-2017 % % >> web: http://www2.hu-berlin.de/eyetracking-eeg % % Copyright (C): Olaf Dimigen & Ulrich Reinacher, 2009-2017 % User feedback welcome: email: olaf.dimigen@hu-berlin.de % % Project made possible by a grant from Deutsche Forschungsgemeinschaft % to Research Group 868, http://mbd.uni-potsdam.de % % If you use functions of this toolbox, please cite this reference: % ------------------------------------------------------------------ % Dimigen, O., Sommer, W., Hohlfeld, A., Jacobs, A., & Kliegl, R. (2011). % Coregistration of eye movements and EEG in natural reading: Analyses % & Review, J Exp Psychol: General, Vol. 140 (4), 552-572. % % If you use the saccade/fixation detection, please additionally cite: % % Engbert, R., & Mergenthaler, K. (2006). Microsaccades are triggered % by low retinal image slip, PNAS, Vol. 103 (18), 7192-7197 % % If you select independent components based on the sac/fix variance % ratio criterion, make sure to also cite: % % Plöchl, M., Ossandon, J.P., & König, P. (2012). Combining EEG and % eye tracking: identification, characterization, and correction of % eye movement artifacts in electroencephalographic data. Frontiers in % Human Neuroscience, doi: 10.3389/fnhum.2012.00278 % % Please clarify that you have used the implementation of these methods % in EYE-EEG, as they may differ from the original versions in some % regards % % Installation: % Simply copy the folder called "eye_eegX.XX" containing the toolbox's m-files % as a subdirectory into the EEGLAB plugin directory and restart EEGLAB. % % GUI functions % ------------------------------------------------------------------ % pop_applytochannels - apply EEGLAB functions to selected channels % pop_detecteyemovements - detect saccades and fixations % pop_ploteyemovements - plot properties of saccades and fixations % pop_eyetrackerica - identify ICs that covary with eye tracker % pop_importeyetracker - import & synchronized eye tracking data % pop_parseeyelink - preprocess eye tracking data from SR Research % pop_parsesmi - preprocess eye tracking data from Sensomot. Instr. % pop_parsetobii - preprocess eye tracking data from Tobii % pop_rej_eyecontin - reject cont. data with out-of-range eye track % pop_rej_eyeepochs - reject epochs with out-of-range eye track % pop_checksync - assess quality of ET/EEG synchronization via cross-correlation % pop_ploteventrate - plot rate of saccades or fixations relative to the epoch time-locking event % Non-GUI functions % ---------------------------------------------------- % addevents - add many events/urevents to cont. or epoched data % applytochannels - see pop function % detecteyemovements - see pop function % eyetrackerica - see pop function % geticvariance - compute IC variance inside/outside saccades % parseeyelink - see pop function % parsesmi - see pop function % parsetobii - see pop function % rej_eyecontin - see pop function % hist2d - 2-dimensional histogram % cleantrigger - helper function % findmatchingevents - helper function % findsequence2 - helper function % ploteyemovements - plot properties of saccades & fixations % synchronize - synchronize ET/EEG data % checksync - assess quality of ET/EEG synchronization via cross-correlation % % Non-GUI functions for saccade & fixation detection % ---------------------------------------------------- % vecvel - compute eye velocities (*) % velthresh - compute relative velocity-thresholds (*) % microsacc_plugin - detect (micro)saccades (*) % binsacc - identify binocular saccades (*) % saccpar - compute saccade parameters (*) % mergesacc - handle temporal saccade clusters % % (*) Copyright: Ralf Engbert et al., University of Potsdam % http://mbd.psych.uni-potsdam.de/~ralfweb, included with permission % Notes: % vecvel() was modified to include different data smoothing options % velthresh() outsources code that was originally part of microsacc(). % microsacc() was therefore renamed to microsacc_plugin(). % % Third-party helper functions % ---------------------------------------------------- % parseq - Copyright: R. Kliegl & J. Laubrock, University of Potsdam % searchclosest - Copyright: Dr. Murtaza Khan, drkhanmurtaza@gmail.com % % Functions that control the GUI dialogues % ---------------------------------------------------- % dlg_applytochannels % dlg_calcvisangle % dlg_detecteyenovements % dlg_eyetrackerica % dlg_loadeyetracker % dlg_parser % dlg_ploteyemovements % dlg_rej_eyecontin % dlg_rej_eyeepochs % dlg_syncsettings % dlg_ploteventrate % dlg_checksync % ---------------------------------------------------- % % This program is free software; you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by % the Free Software Foundation; either version 2 of the License, or % (at your option) any later version. % % This program is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % GNU General Public License for more details. % % You should have received a copy of the GNU General Public License % along with this program; if not, write to the Free Software % Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA % % SMI (TM) is a trademark of SensoMotoric Instruments GmbH, Germany % Eyelink (TM) is a trademark of SR Research Ltd., Mississauga, Canada function vers = eegplugin_eye_eeg(fig,try_strings,catch_strings) vers = 'eye_eeg_v0.80'; % add subfolder for dialogues and other helpers addpath(fullfile(fileparts(which(mfilename)),'internal')); %% callbacks for menu items % PARSE EYE TRACKER RAW DATA cb_parsesmi = [try_strings.no_check, '[ET LASTCOM] = pop_parsesmi; clear ET;', catch_strings.add_to_hist]; cb_parseeyelink = [try_strings.no_check, '[ET LASTCOM] = pop_parseeyelink; clear ET;', catch_strings.add_to_hist]; cb_parsetobii = [try_strings.no_check, '[ET LASTCOM] = pop_parsetobii; clear ET;', catch_strings.add_to_hist]; % IMPORT & SYNCHRONIZE EYE TRACK cb_importeyetracker = [try_strings.check_cont, '[EEG LASTCOM] = pop_importeyetracker(EEG);', catch_strings.new_and_hist]; cb_checksync = [try_strings.check_data, '[EEG LASTCOM] = pop_checksync(EEG);', catch_strings.add_to_hist]; % PREPROCESS EYE TRACK cb_rej_eyeepochs = [try_strings.check_epoch, '[EEG LASTCOM] = pop_rej_eyeepochs(EEG);', catch_strings.new_and_hist]; cb_rej_eyecontin = [try_strings.check_cont, '[EEG LASTCOM] = pop_rej_eyecontin(EEG);', catch_strings.new_and_hist]; % APPLY EEGLAB FUNCTION TO SELECTED CHANNELS ONLY check4chanlocs = '[EEG LASTCOM] = eeg_checkset(EEG,''chanloc''); if ~isempty(LASTCOM), if LASTCOM(1) == -1, LASTCOM = ''''; return; end; end;'; cb_envelope_f1 = [try_strings.check_data, '[EEG LASTCOM] = pop_applytochannels(EEG,[],''pop_eegfilt(EEG);'');', catch_strings.new_and_hist]; cb_envelope_f2 = [try_strings.check_data, '[EEG LASTCOM] = pop_applytochannels(EEG,[],''pop_ERPLAB_butter1(EEG);'');', catch_strings.new_and_hist]; cb_envelope_f3 = [try_strings.check_data, '[EEG LASTCOM] = pop_applytochannels(EEG,[],''pop_ERPLAB_polydetrend(EEG);'');', catch_strings.new_and_hist]; cb_envelope_f4 = [try_strings.check_data, '[EEG LASTCOM] = pop_applytochannels(EEG,[],''pop_iirfilt(EEG);'');', catch_strings.new_and_hist]; cb_envelope_f5 = [try_strings.check_data, '[EEG LASTCOM] = pop_applytochannels(EEG,[],''pop_eegfiltnew(EEG);'');', catch_strings.new_and_hist]; cb_envelope_f6 = [try_strings.check_data, '[EEG LASTCOM] = pop_applytochannels(EEG,[],''pop_firma(EEG);'');', catch_strings.new_and_hist]; cb_envelope_f7 = [try_strings.check_data, '[EEG LASTCOM] = pop_applytochannels(EEG,[],''pop_firpm(EEG);'');', catch_strings.new_and_hist]; cb_envelope_f8 = [try_strings.check_data, '[EEG LASTCOM] = pop_applytochannels(EEG,[],''pop_firws(EEG);'');', catch_strings.new_and_hist]; cb_envelope_2 = [try_strings.check_data, '[EEG tmp LASTCOM] = pop_epoch(EEG); clear tmp;' catch_strings.new_and_hist]; cb_envelope_3 = [try_strings.check_data, '[EEG LASTCOM] = pop_applytochannels(EEG,[],''pop_rmbase(EEG);'');' catch_strings.new_and_hist]; cb_envelope_4 = [try_strings.check_data, check4chanlocs '[EEG LASTCOM] = pop_applytochannels(EEG,[],''pop_timtopo(EEG);'');' catch_strings.add_to_hist]; % DETECT SACCADES & FIXATIONS cb_detectem_1 = [try_strings.no_check, '[EEG LASTCOM] = pop_detecteyemovements(EEG);', catch_strings.new_and_hist]; % PLOT SACCADES & FIXATIONS cb_plotem_1 = [try_strings.no_check, '[EEG LASTCOM] = pop_ploteyemovements(EEG);', catch_strings.add_to_hist]; % PLOT SACCADES & FIXATIONS cb_plotrate = [try_strings.no_check, '[LASTCOM] = pop_ploteventrate(EEG);', catch_strings.add_to_hist]; % EYETRACKER-SUPPORTED ICA cb_etICA = [try_strings.check_ica, '[EEG vartable LASTCOM] = pop_eyetrackerica(EEG);', catch_strings.add_to_hist]; %% create GUI menus W_MAIN = findobj('tag','EEGLAB'); % "EYETRACKER" % attempt to make "Eyetracker" the last menu item before "Help" % (note: menu position may change if more plugins are added, e.g. "ERPLAB") eyetracker_m = uimenu( W_MAIN, 'Label', 'Eyetracker', 'tag','eyetracker'); try nitems = get(eyetracker_m,'position'); set(eyetracker_m,'position',nitems-1); catch set(eyetracker_m,'position',nitems); end % set "Eyetracker" menu to default color for plugin menus icadefs; % get PLUGINMENUCOLOR set(eyetracker_m, 'foregroundcolor', PLUGINMENUCOLOR); % "PARSE EYETRACKER RAW DATA" parseEyetracker_m = uimenu( eyetracker_m, 'Label', 'Parse eyetracker raw data', 'Separator', 'on'); uimenu( parseEyetracker_m, 'Label', 'text file from Eyelink', 'CallBack', cb_parseeyelink); uimenu( parseEyetracker_m, 'Label', 'text file from SMI', 'CallBack', cb_parsesmi); uimenu( parseEyetracker_m, 'Label', 'text file from Tobii', 'CallBack', cb_parsetobii); % "IMPORT & SYNCHRONIZE ET" uimenu( eyetracker_m, 'Label', 'Import & synchronize ET', 'CallBack', cb_importeyetracker, 'Separator', 'off', 'userdata', 'epoch:off; '); uimenu( eyetracker_m, 'Label', 'Evaluate synchronization (cross-corr.)', 'CallBack', cb_checksync, 'Separator', 'off', 'userdata', 'startup:off;'); % epoch:off;' %uimenu( eyetracker_m, 'Label', 'Evaluate synchronization (cross-corr.)', 'CallBack', cb_checksync, 'Separator', 'off', 'userdata', 'epoch:off; '); % APPLY FUNCTION TO SELECTED CHANNELS helpers_m = uimenu( eyetracker_m, 'Label', 'Apply function to selected channels', 'Separator', 'on', 'userdata', 'startup:off;'); filters_m = uimenu( helpers_m, 'Label', 'Filter the data (selected channels)', 'Separator', 'on', 'userdata', 'startup:off;'); uimenu( filters_m, 'Label', 'Basic FIR filter (legacy)', 'CallBack', cb_envelope_f1, 'Separator', 'off', 'userdata', 'startup:off;'); % test whether filter functions from bundled plugins are available % ...from ERPLAB if exist('pop_ERPLAB_butter1','file') uimenu( filters_m, 'Label', 'ERPLAB Butterworth filter' , 'CallBack', cb_envelope_f2, 'Separator', 'on', 'userdata', 'startup:off; '); end if exist('pop_ERPLAB_polydetrend','file') uimenu( filters_m, 'Label', 'ERPLAB Polynomial Detrending', 'CallBack', cb_envelope_f3, 'Separator', 'off', 'userdata', 'startup:off; '); end % ...from other plugins (not yet added to EEGLAB path) eegplugpath = fullfile(fileparts(which('eeglab')),'/plugins'); try placeHolder = ''; % placeHolder = ' '; % use this if error occurs with exotic MacOS/Unix versions % folders for IIR and FIR filter plugins dir_iir = dir([eegplugpath placeHolder '/iirfilt*']); dir_fir = dir([eegplugpath placeHolder '/firfilt*']); % iirfilt plugin installed? if so, add menu entry if ~isempty(dir_iir) filtName = 'iirfilt.m'; if exist(fullfile(eegplugpath,dir_iir(1).name,filtName),'file') uimenu( filters_m, 'Label', 'Short non-linear IIR filter', 'CallBack', cb_envelope_f4, 'Separator', 'on', 'userdata', 'startup:off; '); end else %warning('iirfilt plugin not found in plugin folder)') % #bugfix OD: removed this warning in v0.44, since iirfilt.m is not "shipped" with EEGLAB per default anymore end % firfilt plugin installed? if so, add menu entries if ~isempty(dir_fir) filtName = { 'pop_eegfiltnew.m' 'pop_firws.m' 'pop_firpm.m' 'pop_firma.m'}; filtMenuLabel = { 'Basic FIR filter (new)', 'Windowed sinc FIR filter' 'Parks-McClellan (equiripple) FIR filter' 'Moving average FIR filter'}; filtMenuCb = { cb_envelope_f5 cb_envelope_f8 cb_envelope_f7 cb_envelope_f6 }; for loop = 1:length(filtName) if exist(fullfile(eegplugpath,dir_fir(1).name,filtName{loop}),'file') uimenu( filters_m, 'Label', filtMenuLabel{loop}, 'CallBack', filtMenuCb{loop}, 'Separator', 'off', 'Position' , loop); end end else warning('firfilt plugin not found in plugin folder') end catch dir_error fprintf('\n%s(): Could not add filter functions to plugin menu. Skipping this step.\n',mfilename) end uimenu( helpers_m, 'Label', 'Extract epochs (without baseline removal)', 'CallBack', cb_envelope_2, 'Separator', 'off', 'userdata', 'startup:off;'); uimenu( helpers_m, 'Label', 'Remove baseline (selected channels)' , 'CallBack', cb_envelope_3, 'Separator', 'off', 'userdata', 'startup:off;'); uimenu( helpers_m, 'Label', 'Channel ERPs - with scalp maps' , 'CallBack', cb_envelope_4, 'Separator', 'off', 'userdata', 'startup:off;'); % "REJECT DATA BASED ON ET" rejectEyetrack_m = uimenu( eyetracker_m, 'Label', 'Reject data based on eye track' , 'Separator', 'on', 'userdata', 'startup:off; '); uimenu( rejectEyetrack_m, 'Label', 'Reject bad cont. data', 'CallBack', cb_rej_eyecontin, 'Separator', 'off', 'userdata', 'startup:off; epoch:off;'); uimenu( rejectEyetrack_m, 'Label', 'Reject bad epochs', 'CallBack', cb_rej_eyeepochs, 'Separator', 'off', 'userdata', 'startup:off; continuous:off;'); % "DETECT SACCADES & FIXATIONS" uimenu( eyetracker_m, 'Label', 'Detect saccades & fixations', 'CallBack', cb_detectem_1, 'Separator', 'off', 'userdata', 'startup:off; '); % "PLOT SACCADES & FIXATIONS" uimenu( eyetracker_m, 'Label', 'Plot eye movement properties', 'CallBack', cb_plotem_1, 'Separator', 'off', 'userdata', 'startup:off; '); % "PLOT SACCADES & FIXATIONS" uimenu( eyetracker_m, 'Label', 'Plot eye movement rate', 'CallBack', cb_plotrate, 'Separator', 'off', 'userdata', 'startup:off; '); % "REJECT COMPONENTS WITH ET" uimenu( eyetracker_m, 'Label', 'Reject components with eyetracker', 'CallBack', cb_etICA, 'Separator', 'off', 'userdata', 'startup:off; '); % "ABOUT THE TOOLBOX" uimenu( eyetracker_m, 'Label', 'About this toolbox', 'CallBack', 'pophelp(''eegplugin_eye_eeg.m'');', 'Separator', 'on', 'userdata', 'startup:on;');