Psychtoolbox is a popular MATLAB toolbox for neuroscience and psychology experiments. Building experiments in MATLAB with Psychtoolbox allows a degree of flexibility and precision that is essential in many research niches. However, it can be a technical and time consuming process. Redundancy is also a problem as reusing stimuli and functionality means refactored code across different experiments, or even reinventing it across labs.
PsychBench is software for MATLAB built on Psychtoolbox. It adds a layer to make building Psychtoolbox-based experiments faster, more accessible, and less repetitive. It aims to do this while retaining both the flexibility and precision of Psychtoolbox. You can choose between the visual method based in any spreadsheet app (Google Sheets allows dropdown menus and quick docs) or the coding method using a MATLAB script. An open-source library comes with a range of object types for stimuli and functionality. You can also add your own stimulus types to the library in MATLAB + Psychtoolbox code.
This link downloads the MATLAB function pb_install.m. Put it in the location where you want to install PsychBench, set your MATLAB current folder to there, and run it from the MATLAB command line. You can type help pb_install for more information.
Windows / macOS / Linux – 64-bit
MATLAB R2017a or later
(R2019a+ for visual method of making experiments, R2021a+ recommended)
PsychBench does not run in GNU Octave.
Psychtoolbox most recent version (free)
Psychtoolbox requires GStreamer (free):
Windows: GStreamer 64-bit MSVC runtime 1.22.5
macOS – Intel and ARM: GStreamer runtime 1.22.1
Linux: (generally already installed)
In earlier versions, bugs in Google's cloud API may preventing updating (newer versions use a different cloud service). If you get an error using pb_update, please update manually: delete the PsychBench folder, remove it and its subfolders from the MATLAB search path (MATLAB toolbar → Set Path), and reinstall with the most recent version using the download link above.
In the visual method, lay trials out in one or more tables in a spreadsheet. You can use any spreadsheet app, but Google Sheets is most common since it gives you dropdown menus and quick docs. Rows are trial definitions. Columns are object properties. Values are MATLAB values or expressions. You only need to write each distinct row once, and in any order. Then use one more MATLAB expression to set a list of trial definitions to run through, including any repetition and ordering. Save to an Excel file, use the command loadExperiment in MATLAB to load it, and runExperiment to run.
For example, the two tables below would make an experiment that runs two repetitions of three distinct trials, all in random order. In each trial, a picture of an animal shows at a height of 10 degrees visual angle. The picture stops showing when the subject presses any key. Experiment results report picture file name and response latency for each trial. (This is an extremely minimal example! See examples and demos for more.)
You can always use the coding method instead if you prefer. Here make objects, set properties, and define trials in a MATLAB script. You can use for loops through conditions to automate defining trials. This isn't really code in the usual sense—more like a list of statements setting parameters. For example, this script would build and run the same experiment as above:
Just for comparison, here is some compact Psychtoolbox code that would run the same experiment, with the same timing precision and error handling. The difference with/without PsychBench is noticeable here but it balloons up for more realistic experiments.
PsychBench comes with a library of open-source (MATLAB + Psychtoolbox) object types.
We add new object types regularly. Please contact us with requests.
If the library doesn't have the stimuli you need for an experiment, you can write your own code in MATLAB + Psychtoolbox. The approach is to write it as a new object type in your library—this allows you to use the code anywhere and have it work with all core functionality (timing, core visual options, staircasing, results output, etc.). You can make a quick type, or you can make a durable type with more flexibility and a fuller interface for other users. All the standard types that come with PsychBench are open source, so you can use them as examples and/or build off them.
You can share an object type with other people just by zipping the type's folder and emailing it.
You can also contribute a type to the library that comes with PsychBench. If you would like to do this, please contact us. We would be happy to credit you. And thank-you!