MonkeyLogic

Behavioral Control in MATLAB

 



Getting Started

System Requirements
Directory Setup & Starting MonkeyLogic
Task Elements

 



System Requirements

What you need:

Modern PC running Windows XP/Vista/7
(either 32-bit or 64-bit versions of Windows OS)

Important requirement if using Windows 7:
Must set the desktop to a non-"Aero" theme.

DirectX must be installed.

MATLAB (32-bit version, at least r2007b)
32-bit MATLAB works on both 32-bit and 64-bit OSs
Data Aquisition Toolbox
Image Processing Toolbox

Important: Older versions of MonkeyLogic require MATLAB to be run with JAVA disabled (from the command line, launch MATLAB using the "-nojvm" option), whereas newer versions can run with JAVA enabled.

One or two DAQ cards
(tested with National Instruments brand PCI & USB cards)

Dual-head Video Card with at least two monitors.
SVI Toolbox (Included in the Monkeylogic download)

Tested Configuration

The system used for testing in the first two published methods papers consisted of a computer with a 2 GHz Core 2 Duo processor, 512 Mb RAM, a dual-headed video card with 128 Mb video RAM, and two National Instruments 6229 PCI DAQ cards with two BNC 2090 break-out boxes. Considerably improved temporal performance can be achieved with more modern PCs. For example, our most recent methods paper (J Neurophys, 2013) used a system consisting of a Dell Optiplex 980 computer with a Core i5 processor clocked at 3.60 GHz, with 4GB or RAM and running on Windows 7. The video system in that machine consisted of two Radeon HD 3400 graphics cards with 2GB of video RAM. Unsurpisingly, even faster performance (with typical cycle intervals around 0.3 ms and video refreshes requiring only 1.5 ms) has been observed on a Core i7 system (unpublished).

We typically use National Instruments PCI 6221 DAQ cards because they are the least expensive option that have the minimum number of analog and digital inputs/outputs that we require.

A typical experimental set-up includes two or three monitors: the dual video card output is divided among two displays, one which shows the experimental "control screen" and the other for use as the subject's screen. The subject's display output is often sent to two monitors using a VGA or DVI signal splitter so that the experimenter can see what the subject sees and simultaneously provide the subject with a separate, optimally-positioned display.

Data Acquisition (DAQ) devices

The Matlab Data Acquisition Toolbox supports a variety of DAQ devices by several manufacturers. In addition to those from National Instruments, devices from Measurement Computing are also known to work with MonkeyLogic. A list of manufacturers supported by the Data Acquisition Toolbox is availabe on the Mathworks site. Note, however, that boards must allow sampling in the free-running state (i.e., the device has not been "started" for data logging, yet samples can still be retrieved with "getsample"), in order to work with MonkeyLogic when two boards are used in parallel (see next section) for more rapid behavioral signal sampling. Devices from Agilent do not have this capability, and so are not recommended.

Connector panel(s)

We use two National Instruments BNC 2090 connector boxes, to interface the PCI cards to BNC cables and digital inputs/outputs. Some labs have developed their own home-built "break-out" boxes.

Utility of two DAQ cards

A second PCI DAQ card (identical to the first) allows for more rapid sampling of the analog inputs (see Asaad & Eskandar, 2008a). Specifically, the maximum possible sampling rate jumps from ~30-50 Hz to several kHz when the second card is added. This is due to limitations in the way the DAQ hardware communicates with the PC when simultaneously storing analog data for post-hoc analysis and using that data in real-time to monitor and control behavior.

Utility of a PC parallel port

If using an older computer system (pre-"Core" processor), having a parallel port is recommended if behavioral event-markers are to be sent to a separate neural data acquisition system, because the per-operation speed of a parallel port (~0.5ms) was much faster than that of DAQ-based digital-IO ports (> 4ms per operation, as per earlier testing with MATLAB r2007b). Newer systems appear to have per-operation speeds on the DAQ DIO subsystem that are similar to the parallel port.

PCI vs USB DAQ devices

Adequate performance for training was achieved on a much simpler system (laptop with 1.6 GHz Pentium M, 1.5 Gb RAM, a dual-headed video card with 32 Mb video RAM, and a National Instruments 6008 USB DAQ card.  Note, however, that USB cards do not allow for high-rate on-line analog input sampling (even when using two USB DAQ devices, data refreshes from the USB card occur only every ~25 milliseconds). While such delays may not be perceptible to subjects under many conditions, PCI cards allow for sampling rates well over 1 kHz and are therefore preferred for more closely approximating real-time control.

Additional software required

A collection of SVI toolbox functions is also required. Specifically, the XGL, PRT, and KBD functions. These are provided with MonkeyLogic.

Additional hardware

While some behavioral tasks may rely upon simple keyboard input, most users employ an eye-tracker, joystick, or button-box. In the Asaad Lab, we use the Penny Giles JC200 joystick for human and nonhuman primates. Eye-tracking is currently performed with SR Research systems in both the Freedman and Asaad labs, and we have also used Iscan systems in the past; any eye-tracker that can output separate X and Y (and optionally pupil) measurements via analog signal should work.

MonkeyLogic has built-in routines for eye- and joystick-calibration and tracking, as well as for reading analog or digital buttons or levers (see the eyejoytrack command for more detailed information on monitoring these inputs). Eye-trackers and joysticks are expected to provide separate X and Y voltages, and these can be calibrated from within MonkeyLogic to correct for differences in offset, scaling, and 2-D skew (see Input Calibration for details).

 


Directory Setup & Launching MonkeyLogic

Create a directory called "monkeylogic" and add it to the MATLAB path, copying the unzipped contents of the downloaded package into it. Also add the directory containing the SVI toolbox functions to the MATLAB path. Next, create directories for each experiment; in each directory, you will place an experiment's conditions file, timing script , stimulus images, and any other needed files (e.g., block-selection routines, etc). Behavioral data files for a that particular experiment will be written into this directory as well. These experiment directories do not need to be added to the MATLAB path.

Launch the MonkeyLogic menu by typing "monkeylogic" at the MATLAB command prompt. Once a conditions file and timing script(s) have been created, clicking on the "Load Conditions File" button at the top of the menu will allow you to select that conditions file to import, along with any stimuli used by that file and the timing scripts associated with it. In addition, once the various parameters on the main menu have been configured, these settings can be saved by clicking on the "Save Settings" button (note: these settings will also be saved whenever an experiment is launched using the "Run" button).

A joystick and eye-tracking system are optional (keyboard input is minimally required for an interactive task). Pre-calibrating the inputs (e.g., on the eye-tracker system itself rather than in Matlab through the main menu) allows faster task execution, though even when performing an on-line calibrated transformation the operating frequency should be greater than 1 kHz.

A separate data acquisition system is assumed to be in use to store neural events (for example single units and LFPs) and other continuous inputs (such as eye position, joystick position, photodiode state, etc). Note: slow analog data (e.g., eye-position) will be stored locally in the BHV file as well, but splitting these signals into the neural data acquisition system is prudent because it provides exact, sub-millisecond alignment of these signals in relation to the neural events. Behavioral codes (event-markers) will be stored locally allowing complete analysis of behavior, and can be exported in real-time to the acquisition system to allow temporal alignment of the behavioral events with those data acquired separately.

If you are running an experiment in which eventmarkers are not frequently sent to a neural data acquisition system (e.g., running an fMRI experiment where MonkeyLogic and the scanner are started simultaneously, but then do not communicate once the task has begun), you will need to rely on the BHV file variable AbsoluteTrialStartTime. Because Windows occasionally updates its clock with respect to a remote server, there can be discontinuties or inaccuracies in the clock over time, making these values inaccurate. Rarely, this may happen during an experiment. To stop clock syncing during an experiment, you should edit the Windows Registry.

For older versions of MonkeyLogic: While most main menu functions work when MATLAB is running in standard mode (with Java enabled), some functions -- and the behavioral task itself -- will not work reliably so long as Java is enabled, either in the Matlab environment or in another application (e.g., web browser). If Java is currently running, unexpected and sporadic crashes will occur. To run MATLAB without Java, type:

matlab -nojvm

from the Windows command prompt after navigating into the Matlab exe folder (located, for example, at: c:\progra~1\ matlab\r2006a\bin\win32). Creating a dos batch file (".bat") to navigate to this directory and launch matlab facilitates this process.

 


Task Elements

A behavioral task is constructed of the following elements:

A tab-delimited text file listing the applicable timing script and the set of stimuli for each condition.
A MATLAB m-file which monitors the subject's behavior, presents stimuli, and handles the contingencies between behavior and stimuli (using special functions designed for these purposes, as well as standard MATLAB and user-provided functions)
A tab-delimited text file which lists the description for every numerical event-marker
The main menu video and I/O settings used for the experiment, as well as basic task parameters. After selecting the appropriate options in the GUI, clicking "save" will preserve these settings so that loading the associated Conditions File in the future will automatically retrieve these settings.
A MATLAB m-file which determines how the conditions are to be selected on a trial-by-trial basis (used if the options built-in to the main menu are insufficient or inapplicable).
A MATLAB m-file which determines how the next block is to be selected, called at the end of the previous block (used if the options built-in to the main menu are insufficient or inapplicable).
A MATLAB m-file which determines when to change blocks (but not which block is actually selected). Useful if block switches depend upon on-going behavior or other factors not knowable a priori.
A MATLAB m-file which determines what to display in the control-screen figure area normally occupied by the reaction time graph.

For a more concrete introduction to building an experiment, see the example task (a conditions table and timing script for a delayed match-to-sample task).



This site last updated: May, 2014
© 2008-2014