A simple experiment: data collection code


In this page you can find a simple but complete experiment aiming at provigind you a programming paradigm and example/starting point for developing your experiments for the MEG lab. The experimental paradigm is very basic and consist in pressing the red/blue button on the response box if the stimulus, after a cue, was a tone/gabor. Eyes are tracked by means of the Eye Tracker. Photodiode based techniques are used to assure 1 msec hig precision real synchronization.


The code is very simple and its aim is to illustrate how to use MEG lab devices for a visual experiment, involving stimuli presentation, response collection, eye-tacking and triggers (with photodiode correction). The not MEG-related code is intended to be only a suggestion, since here the focus is not the experimental paradigm itself, but how commands related to MEG devices integrate into it. The aim is that the reader can understand & re-use code snippets from here in experiment programming.


Matlab & PsychToolbox knoweledge is assumed. If not the case, we suggest to follow a good tutorial before.


The experiment consists of a cue followed by a stimulus and has the following instructions:

  • press the red button if stimulus is a beep, press the blue button if stimulus is a gabor ;
  • keep the gaze at fixation


The script is structured as follows:

  • A few "INIT" sections:
    • General experiment-level parameters initializations
    • Datapixx (blue boxes) initialization
    • Psychtoolbox initialization
    • Eyelink initialization
    • Eyelink calibration
  • INSTRUCTIONS to the subject
  • A "TRIAL LOOP", cycling trough trials and containing:
    • A "INIT TRIAL" section, in which all trial-dependent parameters are initialized
    • A session in which "EYELINK RECORDING" starts
    • A "PRESENTATION LOOP", allowing for fine control of the trial at each single screen refresh (frame)
  • A "CLOSINGS" session, in which devices are gracefully closed and data are locally saved


Here you can download the MATLAB code. Don't esitate to contact the MEG core staff for any question. 

Image SampleExperiment


Created by davide.tabarelli. Last Modification: Friday 07 of May, 2021 11:55:41 CEST by davide.tabarelli.