Behavioral Control in MATLAB


Input / Output System and Calibration

General Organization
I/O Assignment Guidelines

Input Calibration
Analog Input Duplication

NEW! MonkeyLogic User's Forum 


General Organization of the I/O System

The I/O system is responsible for monitoring eye-position and joystick-position, delivering reward, sending event-markers to a separate acquisition system, and delivering electrical stimulation or TTL pulses. A data acquisition (DAQ) board is useful for these functions. National Instruments PCI boards were used in the development of this software; DAQ boards from other vendors may work, but have not been tested. Hardware drivers provided by the manufacturer must be installed, and the MATLAB Data Acquisition Toolbox must be installed.

I/O Panel

An input or output is defined by the software driver and associated board (piece of installed hardware), the subsystem (analog in, analog out, digital i/o), and the channel (if analog) or port + line (if digital).

The assignment of specific functions (e.g., eye-signal x and y inputs or reward delivery) to particular channels or lines is determined by the assignments made in the main menu. To make an assignment, select the signal in the list-box (e.g., "Joystick X"), and select the board, subsystem and channel or line(s) in the boxes above. Finally, press the "assign" button. Pressing the "check" button will test the ability to properly initialize these assignments, turning green if successful.


Input / Output Assignment Guidelines

Several guidelines should be followed when making I/O assignments:

  • All analog inputs must reside on the same board.
  • If an eye signal input is defined, both (x and y) must be defined.
  • Likewise, if a joystick input is defined, both (x and y) must be defined.
  • If button inputs are defined, they must be either all analog or all digital. Note: analog buttons can be sampled more quickly than digital ones. Analog buttons also allow for setting a variable threshold for tracking.
  • Analog Inputs are by default set as "differential." If another input type is required, this can be set in the main menu in the Analog Inputs section of the I/O panel.
  • Analog Inputs are initially set to acquire at 1000 Hz. This can be changed in the Analog Input subsection of the main menu..
  • There is no fundamental difference between eye inputs and joystick inputs. However, these assignments determine which timing script sub-function (within the eyejoytrack function) accesses each data stream (acquirefix and holdfix for eye signals, and acquiretarget and holdtarget for joystick signals). Furthermore, turning on the subject's cursor (using the showcursor command) will activate a cursor-image that follows the movements of the joystick signal, not the eye-signal.
  • Reward can be assigned to either an analog or a digital output. Reward activation is assumed to require a change from 0 to +5V. However, this can be reversed (so that a drop from 5V to 0V occurs to trigger reward) by toggling the drop-down menu option available when the monkeylogic main menu is run with JAVA enabled. Specifically, go to I/O >> Invert Reward Polarity.
  • If the same I/O line is used for more than one function, an error may or may not occur, depending on the specific board and subsystem being used.
  • The digitial I/O subsystem of most boards is organized into "ports." When assigning a function to digital I/O, a menu will appear to prompt for the specific line(s) you wish to assign.
  • When using digital I/O, whether adjacent lines are individually configurable as inputs or outputs depends on whether they lie on the same “port” and if the DAQ board is “port configurable.”
  • Behavioral codes (event-markers) are sent via the "behavioral codes" option on the I/O menu. When a board, subsystem, and port have been selected, pressing the "assign" button while this option is selected from the list box will bring up a menu with the available lines displayed. Select all those lines you wish to use for the digital word output (e.g., select 8 lines to represent event markers ranging from 1-255). You must also select a "Codes Strobe" line (just one this time) that is separate from any of the previously selected lines; this line indicates to the receiving system when a word is ready to be read (See also, "Strobe Bit Trigger-Edge" option in the main menu). Note: To write codes to a parallel port, use Port 0 for the 8-bit digital word (lines 0 through 7) and use Port 2 (line 0) for the strobe bit.
  • A stimulation port can be activated (with "toggleobject") only once within any single trial.
  • Visual stimuli, reward, sounds, and TTLs, however can be toggled on and off repeatedly.

I/O menu settings are described in more detail on the main menu page.

The default parameters for data acquisition and output are relatively minimal and should work on nearly any DAQ. However, if there are problems making I/O assignments, the properties of the DAQ system can be set manually by editing the header section of initio.m. See the literature for your specific hardware, and consult the MATLAB DAQ toolbox documentation.

Input Calibration

The eye- and joystick-signals can be used raw (pre-calibrated) or can be calibrated as needed. To calibrate a signal, click on the "Calibrate Eye-Position" or "Calibrate Joystick" button on the main menu. This will launch a new window with options for selecting the screen coordinates (in degrees) used for calibration and the option to deliver reward upon accepting each calibration point. Clicking on the main figure to the right will display a grid and allow the selection of a calibration point with the mouse.


To begin calibration, press the "start calibration" button. The subject's display will show a single fixation point corresponding to the point visible on the control screen. Once calibration has begun, hitting the space bar will accept the current eye or joystick voltages as corresponding to the current point (actually, one hundred milliseconds of data beginning about 250ms before the space bar is pressed will be averaged, in order to prevent late deviations from skewing the intended values). Hitting "n" will display the next point and "p" will display the previous point, as dictated by the list shown to the left. Once calibration is complete, hit "q" and then press "save & exit." This calibration can then be saved in the full configuration file along with all the other task parameters in the main menu (by pressing "Save" in the main menu or by launching the behavioral task, which also saves the current configuration).

Eye and / or joystick position can also be calibrated from within a task. To activate calibration, hit the [Escape] key and wait until the task pauses between trials. If eye or joystick signals have been defined in the main menu I/O panel, you will be given the option to press [e] or [j] to calibrate these inputs, respectively.

Analog Input Duplication

In order to allow MonkeyLogic to use analog signals both for real-time experimental control and for offline storage for later analysis, DAQ cards such as those from National Instruments must be used in two incompatible modes.

In the first mode, for real-time behavioral control, analog signals are sampled from the DAQ card as fast as possible, at irregular intervals, limited only by the intervening computations for stimulus presentation, control screen updates, and target checking. Here, the DAQ card is left in a "free running" state, in which the most recent sample is queried over and over.

In the second mode, the DAQ card is set to acquire analog data samples at regular intervals (e.g., 1000 Hz), so that these signals can be viewed and analyzed offline for later behavioral data analysis. In this strictly clocked mode, the DAQ cards only upload data in "chunks" every 20 to 50 milliseconds. This limits the frequency with which one can observe behavior to 20 to 50 Hz, rather than the 1 kHz which is generally the goal of "real-time" behavioral control.

From: Asaad & Eskandar, Achieving Behavioral Control with Millisecond Resolution in a High-Level Programming Environment
Journal of Neuroscience Methods, 2008, vol. 173, pp. 235-240

For this reason, the solution MonkeyLogic has adopted is to employ two analog cards: one for real-time sampling in a free-running mode, and another for clocked data acquisition to be used offline. While requiring a bit of extra expense, this is nonetheless currently the best solution given the underlying hardware limitations.

To enable this feature:

1) Install two identical DAQ boards, and split the analog signals into them so that each signal feeds into the analogous input on each board.

2) Enable "Analog Input Duplication" on the main menu.

3) Assign all of the analog inputs two one of the two boards. The second, identical DAQ will automatically be detected and used appropriately.


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