SkillAgentSearch skills...

Opticka

Opticka is an experiment manager built on top of the Psychophysics toolbox (PTB) for MATLAB. It runs experimental tasks using flexible state machine logic and easily does dynamic methods-of-constants type experiments with full behavioural control. It uses a class system to create simple to use visual stimuli using experimenter friendly units. Opticka can use an Eyelink eyetracker, Plexon Omniplex neurophysiology data collection and general TTL control using either a cheap LabJack (ms precision) or DataPixx/Display++ (µs precision). It contains analysis routines linked to Fieldtrip for spike and LFP data easily parsed in terms of the experimental variables.

Install / Use

/learn @iandol/Opticka

README

Opticka: Behavioural Experiment Manager

DOI GitHub Release GitHub Commits Since GitHub last commit DeepWiki Docs Open in Visual Studio Code Maintenance GPLv3 license

Opticka is an object-oriented framework with optional GUI for the Psychophysics toolbox (PTB), allowing full experimental presentation of complex visual or other stimuli. It is designed to work on Linux, macOS or Windows. It interfaces via strobed words and/or ethernet for recording neurophysiological and behavioural data. Full behavioural task control is available by use of a Finite State-Machine controller, in addition to simple method of constants (MOC) experiments. Opticka uses the TCP interface for Eyelink, Tobii Pro and iRecHS2 eyetrackers affording better control, reliability and data recording over depending on analog voltage output (we don't need a DAQ card for eye data). The base classes can be used without the need to run the GUI (see optickatest.m for an example), and plug-n-play stimuli provide a unified interface (setup, animate, draw, update, reset) to integrate into other PTB routines. Opticka's methods take care of all the background geometry and normalisation, meaning stimuli are much easier to use than “raw” PTB commands alone. Analysis routines are also present, eye data can be parsed into trials for any supported eyetracker, and for taking e.g. Plexon files (.PL2 or .PLX), Eyelink files (.EDF), and behavioural responses and parsing them into a consistent structure, interfacing directly with Fieldtrip for further spike, LFP, and spike-LFP analysis. Opticka is more modular and affords much better stimulus control (most stimuli are optimised OpenGL with advanced control thanks to PTB) than e.g. MonkeyLogic.

Sample hardware setup

The diagram below shows a sample Opticka configuration setup. Note that the eyetracker, display, synchronisation and electrophysiology systems can be swapped for other hardware (see the list below). While I prefer using a Display++ or a DataPixx/ViewPixx to guarantee temporal fidelity, you can use either a LabJack or Arduino/XIAO for synchronisation (where a photodiode becomes more important, which we integrate as an option):

Example hardware setup to run Opticka

GUI

A GUI can be used to control the hardware, stimuli and variables needed for both method of constant (MOC) and more complex behavioural tasks that use the state machine. GUI supports protocol files that are useful for cases where staff running an experiment are not themselves programmers, and when you need to change experiment or stimulus parameters quickly between runs: you make protocol files for each task, then load and run them as needed. The GUI is not required to utilise the underlying classes…

o = opticka; %==run the GUI, returns an object 'o' for introspection from the command window...

Opticka Screenshot

State machine control

For more complex behavioural tasks, a state machine is used. You can still edit visual stimuli and task variables in the GUI, and then edit a StateInfo.m file that specifies states (like paused, prefixation, stimulus, correct, breakfix etc.) to be run and for each state which methods/functions are executed (cell arrays of functions that run on ENTER, WITHIN & EXIT of states). States can switch (TRANSITION) based on logic, for example a particular saccade or fixation or button responses to transition to a correct state… See an example StateInfo.m file here; and you can test a minimal generic state machine run using:

sM = stateMachine;
demo(sM);

Hardware currently supported

  • Display & Digital I/O: high quality display (high bit depths, great colour management) and microsecond precise frame-locked digital I/O: Display++ by CRS.
  • Display & Digital I/O: high quality display (high bit depths) and easy-to-use microsecond precise digital I/O: DataPixx / ViewPixx / ProPixx.
  • Display: any normal monitor; remember that PTB can support 10bits and higher output, steroscopic display, HDR output etc.
  • Digital I/O: LabJack USB U3/U6 or T4/T7 DAQs, strobed words up to 12bits. The T4/T7 are preferred as the I/O is asynchronous and work on all platforms.
  • Digital I/O: Arduino boards for simple TTL triggers for reward systems, MagStim etc. In particular, digitial TTLs are asynchronous so they do not block the experimental loop. The seeeduino Xiao is small, cheap, fast and works well, as does the Raspberry Pi Pico (using the Arduino IDE interface), but the Uno is also well supported.
  • TouchScreen: PTB can interface many kinds of touchscreen types and we have tested against many different brands. Our [touchManager](touchManager.m add support for touch windows, exclusion zones and more...
  • Eyetracking: Eyelink Eyetrackers -- uses the native ethernet link API. This enables much better two-way control, sending markers and stimulus data while drawing stimuli and experiment values onto the eyelink screen. EDF files are stored after each run and eyelinkAnalysis.m class uses native EDF loading (not ascii proxies) for full trial-by-trial analysis without conversion. See also eyelinkManager.
  • Eyetracking: Tobii Pro Eyetrackers -- using the excellent Titta toolbox to manage calibration, command-response and recording. Tobii Pro eyetrackers do not require head fixation. See tobiiManager.
  • Eyetracking: iRecHS2 -- this low-cost eyetracker nevertheless offers good quality eyetracking, see their paper: A Widely Applicable Real-Time Mono/Binocular Eye Tracking System Using a High Frame-Rate Digital Camera (2017). We use a 500Hz Chameleon camera from FLIR. See See iRecManager.
  • Electrophysiology: in theory any recording system that accepts digital triggers / strobed words; we have dedicated code for the Plexon Omniplex system and can control Intan amplifier software. Opticka can use TCP communication over ethernet to transmit current variable data to allow online data visualisation (PSTHs etc. for each experiment variable) on the Omniplex machine. Digital triggers can be generated with good temporal fidelity.
  • Visual Calibration: we support use of a CRS SpectrolCal II (preferred but expensive) or ColorCal 2, or a VPixx i1Pro, or manual interfacing with most other photometers that PTB supports. See the calibrateLuminance class.
  • Photodiode boxes: we use TSL251R light-to-voltage photodiodes, which can be recorded directy into your electrophysiology system or can generate digital triggers via an Arduino interface.

Quick Documentation

optickatest.m is a minimal example showing a simple script-based method of constants (MOC) experiment with 11 different animated stimuli varying across angle, contrast and orientation. Read the Matlab-generated documentation here: optickatest.m Report. More complex behavioural control (gaze-contingent experiments with variable logic per trial) utilises a state machine, see optickaBehaviourTest.m Report. You can see examples of stateMachine control files in the CoreProtocols folder.

There is auto-generated class documentation here: Opticka Class Docs, that details the major classes and their methods and properties. This is generated from the comments in the code, which as always could be improved…

Basic Install Instructions

Opticka prefers the latest Psychophysics Toolbox (V3.0.17+) and at least MATLAB 2017a (it uses object-oriented property validation introduced in that version). It has been tested on 64bit Ubuntu 20.04 & macOS 12.x with MATLAB 2021b (newer versions are generally faster). You

View on GitHub
GitHub Stars53
CategoryDevelopment
Updated1d ago
Forks26

Languages

MATLAB

Security Score

85/100

Audited on Mar 26, 2026

No findings