Application of Psychtoolbox for MATLAB in Experimental Psychology

Application of Psychtoolbox for MATLAB in Experimental Psychology

Abstract: MATLAB stands for “Matrix Laboratory”, which is a numerical computing software environment and fourth-generation programming language, and Psychtoolbox (i.e. Psychophysics Toolbox) is a set of MATLAB and GNU Octave functions for basic psychology research, especially in vision research. With the assistance of MATLAB and Psychtoolbox, not only the designing and processing of an experiment could be significantly facilitated, but also the data statics and analyze. The two provide an effective method of software solution for the control of behavioral experiments. This paper proposed to make a brief overview of how MATLAB and Psychtoolbox work, as well their diverse functions and application fields of research. Also a comparison of MATLAB with other software frequently used is presented.

I. INTRODUCTION
With the development of computer science and technology, it’s necessary and desirable to use some applicable software to carry out of the entire experiment via computer. The software solution, undoubtedly, can facilitate the designing and processing of a research, with a high-precision control. MATLAB has been widely used as an effective software solution to implement a research, with its abundant functions [1]. MATLAB stands for "Matrix Laboratory" and is a numerical computing environment and fourth-generation programming language. Developed by the MathWorks, MATLAB allows matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages, including C, C++, and Fortran. Moreover, “simulink”, as an additional package of MATLAB, adds functions of graphical multi-domain simulation and model-based designing for dynamic and embedded systems, which are widely used in fields of automatization and intelligentization.
The functions and files in MATLAB are categorized in various sets according various features. Like a box of tools, a particular set of files and functions is called toolbox. And toolbox can be divided into two types that functional toolbox and disciplinary toolbox. Usually the former type is used to enhance the symbolic computation, and the latter to complete some particular disciplinary task. Serving as a disciplinary toolbox intended to solve problems with experimentation in Pscychology, MATLAB Psychtoolbox (i.e. Psychophysics Toolbox) contains adequate MATLAB and GNU Octave functions that play different roles to carry out a trial in the light of the researchers’ design. GNU Octave is a high-level language, primarily intended for numerical computations. It provides a convenient command line interface for solving linear and nonlinear problems numerically, and for performing other numerical experiments using a language that is mostly compatible with MATLAB. In a MATLAB environment, OpenGL functions intended for Graphical computation can also be called conveniently.
The features of MATLAB are as follows:
• As a high-level programming language it’s available for Technique Computing.
• In this environment code, files and data are under management.
• Interactive tools can search, design and solve problems by iterative way
• Math functions are available for Linear algebra, Statistics, Fourier Analysis, Optimization and Numerical Integration, etc.
• 2d and 3d graphical functions are available for visual data.
• A variety of tools can be used to create custom GUI(Graphical User Interface)
• All kinds of functions can integrate the MATLAB-based algorithm with external application program and language (e.g., C, C++, FORTRAN, Java, etc).
• The kernel supports the lower-case input only, but not capital.
In addition to MATLAB, there are many other useful behavioral experiment software, such as E-prime, Experimental Run-Time System, SPIC Software , DMDX Display Software, Superlab, etc. The strong function of numerical computation and algorithm designing is where MATLAB performs better than others, especially confronted with massive and complex empirical data. And besides the computing ability, there are still other properties that outweigh many other software, which will be discussed later in this paper.
II. WHAT CAN MATLAB DO
First and foremost, MATLAB is a prominent mathematical software, standing with the other two major mathematical software: Mathematica, Maple. And it’s second to none in the fields of numerical computing, compared with other math-class application software. Based on the great function of mathematical computation, and combining with the special function provided by a variety of disciplinary toolbox, MATLAB can serve in different fields of study directed to specific experiment needs. Generally, MATLAB can proceed with the computation-related work followed:
• Numerical analysis.
• Numerical and symbolic computing.
• Engineering and scientific graphics.
• Designing and simulation of control systems.
• Digital image processing.
• Digital signal processing.
• Designing and simulation of communication systems.
Moreover,MATLAB not only has openness to external API (Application Programming Interface), but also to reading and modification of its internal MATLAB Main Toolbox and other toolboxes. This offers the programmers or researchers great convenience to write the trial codes in a short time. And users can add custom-programmed toolbox to MATLAB anytime. Many researchers have developed their own toolbox matching their long-standing experiment series over years, in which time it’s no necessary for them to program over and over. Once a toolbox or function is created and saved in MATLAB’s library, it can be used repeatedly. For API, either software or hardware, the situation is similar, as a result of openness and compatibility to internal and external dll (Dynamic Link Library) files.
An important component is obliged to refer to, that is the “Simulink”, one of the most important components of MATLAB. Simulink is an integrated environment in which researchers are able to do modeling, simulation and analysis of dynamic systems. This component provides the function for psychologists, especially in neuroscience or artificial intelligence, to study the pattern of human behavior, neural network modeling and even the organizational network modeling, etc. By using click-and-drag mouse operations in MATLAB Simulink environment, researchers could quickly model and simulate complicated dynamic systems [2]. For instance, to make a robot go needs a researcher making some controllers first, these controllers probably are based on artificial neural network, hence the modeling and simulation of these controllers could be done via Simulink [3]. Moreover, researchers could use Simulink to simulate neurobehavioral principles in an animal model organism [4].
The most significant convenience MATLAB can give derives from a large number of toolboxes have diverse types of function. The abundant library composed of diverse files and functions can solve a plenty of complex problems in psychology. One most wildly used toolbox to facilitate psychology experiment is Psychtoolbox, the toolbox provides various kinds of funcions, whether to display a visual stimuli or audio, or collect the reaction time and reaction key. If a researcher want to design an experiment contains eye-tracking, he can use a toolbox called “eyelink” to finish the task. This toolbox integrates many functions, including that establish a link between the computer and eye-tracking device; that send commands or messages to eye-tracking device to make it record the subject’s eye-movement tracks; that transfer data among different devices and make statics and analysis, etc. In addition, there is also toolbox that helps do EEG/fMRI experiment, aiming at the data from brain. Only using a PC with soundcard, headphone, an EEG pre-amplifier and MATLAB with the EEG-toolbox and the EEG-lab toolbox, a low-cost setup could be developed to perform electrical auditory brainstem responses (E-ABRs) of subjects with cochlear implants, which is an important diagnosis tool, or as one physiologic indicator [5].
Briefly, using MATLAB and its diverse functions and components, researchers can entirely design and process their experiments without hard work. Next the paper will proceed to introduce the detailed procedure of how to use MATLAB and Psychtoolbox carrying out an experiment.
III. AN EXAMPLE OF USING PSYCHTOOLBOX FOR MATLAB
This segment of paper presents an example of experiment using Change-blindness experimentation, which is a process that takes advantage of existing MATLAB libraries and toolboxes to present visual stimuli, collect experimental data, and communicate with other computers. Computer interface can precisely control and time the delivery of a series of visual materials, and collect the responses of subjects in a level of millisecond. To access this sampling rate and precision it’s no necessary to use sophisticated programs and costly specific hardware, by contrast, a personal computer with keyboard, monitor and Pscychtoolbox are enough to do this.
In visual perception, change blindness is the phenomenon that occurs when a person viewing a visual scene apparently fails to detect large changes in the scene. For change blindness to occur, the change in the scene typically has to coincide with some visual disruption such as a saccade (eye movement) or a brief obscuration of the observed scene or image. When looking at still images, a viewer can experience change blindness if part of the image changes. Such experimentation is conducted in this paper, consisting of the procedures that (1) presenting a picture shows instruction of the trials, and subjects press any key to enter the trials, (2) presenting a fixation picture to make the subjects gaze at the monitor, (3) then presenting a reading material for a particular period of time, (4) inserting a blank scene before the next presentation, (5) presenting another reading material with only one difference from the former presentation that a sentence in the former reading material is changed semantically or literally, this sentence is bolded in the same position of material, and (6) when all visual presentation come to end, subjects are asked to react on the keyboard to whether the sentence is changed. Via programming, the experiment is conducted by computer. The development process corresponding to the procedures listed above is as follows:
Presenting the Visual Stimuli
First of all, start the MATLAB (Figure.1); Click the button to write a new file in format of “.m” in file-editor. Then program to convert the experiment procedures into the form of codes.
Visual stimuli is constructed by drawing textures onto off-screen windows which can be copied onto the on-screen window, usually the main screen window, if needed. The Psychtoolbox contains one function “Screen” that allows the off-screen windows to be constructed in the memory, and when the off-screen window is copied to on-screen, another function “waitBlanking” can precisely time the display on the window, which function can synchronize the screen display with the refresh cycle of the monitor [6]. The method of drawing textures is that using the function “imread”, which is a origin function of MATLAB, to read a image file assigned by its filename, then MATLAB converts the image into digital matrix. And this matrix will be used as the textures. Also the matrix can be directly constructed through mathematical algorithm, which is then mapped to the pixels of the screen as textures. Even more complex stimuli such as movies can be generated in this way.
Creating a Graphical User Interface
In order to allow the experimenter to easily set various experiment parameters, as we have been used to the Microsoft’s windows operation, a window interface can give great convenience. In MATLAB, a graphical user interface designing environment is integrated, which is called GUIDE. This function allows users interactively develop a window with OCX controls such as buttons, editbox, and tables, etc [7]. In a similar way as used in Visual Basic, users can directly construct an interface by dragging the controls icons in the component palette. After one control component is chosen to use, a callback function is needed to program, which determines the program what to do simultaneously when users response to the window, as clicking a button or input text, in other words, makes the program to be driven by events. In this paper, we uses the GUIDE to create a interface allow the experimenter set the trial parameters such as the display time of reading materials, the number of trials needed to present, the path of image files needed to read, etc.(Figure.2)
Using Eyelink-1000 to Track Eye-movement
Here we demonstrate how to use “eyelink”, which is a set of functions and files in Psychtoolbox, to control an eye-movement tracking device, named Eyelink-1000. The tracker device is connected to two computers, one for subject and the other for experimenter. The connection is established by a USB data access and an Ethernet Network Interface Card. The task of subject-using computer is to display the series of visual stimulus and collect the response of subjects, and the experimenter-using computer is in charge of driving the Eyelink-1000 to record the tracks of subjects’ eye-movement, through software installed under DOS system. When the program for experiment is started, a command will be execute to establish a link between the two computers, which allows the program run on the subject-using computer to send messages or commands to the experimenter-using computer. And via these messages or commands, the experiment program can control the eye-movement device. The convenience is that “eyelink” provides many functions to help eye-movement tracking, such as that initializes the Eyelink-1000, that time tag during a trial, and that record the tracks and transmit information between computers.
Collecting the Response of Subjects
Psychtoolbox has diverse functions that make a pause and wait for users’ response, once users deliver a keyboard press or mouse click, the program can determine what to do then, judging by decision condition written beforehand. Such functions include “KbWait”, “KbCheck”, “GetMouse”, “Pause”, etc. But one weakness when using the keyboard to collect data is that, the time during which subject press a key might make an error if the precision is set to a level of millisecond or sub-millisecond. In spite of that, there are other methods to precisely trace subjects’ response. Since the keyboard has an inherent buffer time when key press down, more precise hardware should be used instead of the keyboard for high-level precision. For instance, additional IO input/output device can be used. In fact, the PCIboard: PCI-MIO-16E-4 can do this job. Additionally MATLAB has the MathWorks Data Acquisition toolbox to corporate with new installed IO Data Acquisition board [8].
A sweeping review of the designing process is demonstrated above, which shows the main function of MATLAB to a certain extent. Certainly, it’s just a demonstration of one aspect of MATLAB’s strong function. Using MATLAB and Psychtoolbox, or other toolbox, more complex experiment could even be carried out.

IV. COMPARISON OF PSYCHTOOLBOX WITH OTHER SOFTWARE
Cognitive-Psychology and Neuro-Psychology nowadays has enormously benefited from the great development of computer technology that made the control of experiment automatically and more precise. In distinct contrast to the scarcity of software solutions decades of years ago, researchers at present have much more choices of which software is appropriate to their experiments.
The behavioral experiment software often used today includes DMDX, E-prime, Inquisit, PsychToolkit, Superlab, Vision egg and Psychtoolbox for MATLAB, etc, among which Psychtoolbox for MATLAB is getting more and more support. If a comparison is made among these software, the Psychtoolbox outweighs the others mostly upon five aspects: the first is that in MATLAB environment developers possess a great extent of freedom to design experiment; secondly, MATLAB can provided a graphical user interface, which not only makes it easy to set parameters of experiment but also allows experiment observe the behavior such as eye-movement through the interface; thirdly, the function could be easily enhanced or adapted as a result of that MATLAB allows developers to install new toolboxes and call external files though various API; fourthly, With the function of MATLAB it’s easy to establish a local network with several computers combined, and information could transmitted in this network; the last, Psychtoolbox is able to control the experiment at a high-precision level.
Freedom to Design Experiment
Unlike other software, the MATLAB environment allows programmer develop the experiment program at will, while others, saying E-prime, have no such freedom and convenience, to a large extent they could only provide the integrated functions restrained. Apart from that, MATLAB could develop new interface for experiment besides the software’s own interface, while others provide one single interface or window.
Convenient to Create GUI
According to event-driven principles, MATLAB allows users interactively develop a window interface contains OCX controls such as buttons, editbox, and tables, etc. In a similar way as used in Visual Basic, users can directly construct an interface by dragging the controls icons in the component palette. Therefore, experimenters could use an interface to control the experiment graphically. Maybe it’s difficult for other software to develop a graphical user interface, although this lack is not vital, it’s not as convenient as MATLAB.
Openness to Enhance the Functions
MATLAB has the openness and compatibility to whether self-defined functions or external API. Even different scripting language can be integrated in MATLAB files when programming. The most significant point is that MATLAB users can add any toolbox into the library of MATLAB to enhance the software’s function. Researchers can even develop toolbox to implement specific function or aim at particular purpose on their own. And multifarious toolbox with diverse functions are already exist, including “MATLAB toolbox for functional connectivity” [9], “MATLAB toolbox for Granger causal connectivity analysis” [10], “MATLAB toolbox for the control and analysis of movement synchronization experiment” [11], etc. Researchers can directly use these existing toolboxes. No other software can be able to provide so abundant resource.
Easy to Create Network
MATLAB has the ability to receive and transmit messages to other computers on-line. This goal can be achieved by using the TCP/UDP/IP toolbox of MATLAB, which is an open-source library of network functions. In some conditions, the complex data, e.g. neurophysiological recordings from multiple microelectrodes, may necessitate specialized hardware and software, which is a problem that difficult to be solved by one single data acquisition board on one single computer [12]. Therefore, a second computer is needed. For the information transmitting, the task to connect the two computers with each other can be carried out by the functions of TCP/UDP/IP toolbox. It’s worth notice that few of other software can achieve this feature.
High-precision to Control
On account of the characteristic that most software could but sample the system time, and none of the systems, including Windows, Linux, OS, could achieve a high sample rate. For instance, the refresh rate of Windows clock sampling is less than 20, a precision about 50ms. So if the requirement is to set the display time less than 50ms, which is frequently used as subthreshold stimulus, most behavioral experiment software could not achieve. But Psychtoolbox provides functions that synchronize with the clock impulse of mainboard or the refresh rate of monitor, which allows experimenter easily design subthreshold experimentation. Nonetheless, MATLAB can get the response of subjects precisely through expanding hardware.
V. SUMMARY
The purpose of this paper mainly focused on introducing what MATLAB and one of its important toolbox Psychtoolbox could do for researchers who study in the fields of basic psychology. A concrete example using change-blindness experimentation is demonstrated above, in which many advantages of Psychtoolbox are introduced. Even though MATLAB can apparently satisfy most requirements of the researchers, but there are still disadvantages existing, such as the un-user friendly programming environment, which may obstructs researchers with only a little programming knowledge. By contrast, software like E-prime allows users make up a program through just clicking and moving the mouse. And the numerical computing ability of MATLAB is still not fully developed to use in the psychology experiment, as well as the ability to simulate and modeling. In the future, I hope these abilities can get more application.
REFERENCES
[1] S. K. Sen, and Gholam Ali Shaykhian, “MATLAB tutorial for scientific and engineering computations,” Nonlinear Analysis, vol. 71, 2009, e1005-e1020.
[2] Yunong Zhang, Weimu Ma, Xiao-Dong Li, Hone-Zhou Tan, and Ke Chen, “MATLAB Simulinnk modeling and simulation of LVI-based primal-dual neural network for solving linear and quadratic programs,” Nerocomputing, vol. 72, 2009, 1679-1687.
[3] K. G. Jolly, R. Sreerama Kumar, and R. Vijayakumar, “An artificial neural network based dynamic controller for a robot in a muti-agent system,” Neurocomputing, vol.73, 2009, 283-294.
[4] Randall Bish, Sanjay Joshi, Jeffrey Schank, and Jason Wexler, “Mathematical modeling and computer simulation of a robotic rat pup,” Mathematical and Computer Modelling, vol. 45, 2007, 981-1000.
[5] Andreas Bahmer, Otto Peter, and Uwe Baumann, “Recording of electrically evoked auditory brainstem responses (E-ABR) with an integrated stimulus generator in MATLAB,” Journal of Neuroscience Methods, vol. 173, Aug. 2008, p306-p314.
[6] Brainard DH, “The Psychophysics Toolbox,” Spatial Visison, vol.10, 1997, p433-436.
[7] Travis Meyer, and Christos Constantinidis, “A software solution for the control of visual behavioral experimentation,” Journal of Neuroscience Methods, vol.142, 2005, p27-p34
[8] Jonas Rose, Tobias Otto, and Lars Dittrich, “The Biopsychology-Toolbox: A free, open-source MATLAB-toolbox for the control of behavioral experiments,” Journal of Neuroscience Methods, vol. 175, 2008, p104-p107.
[9] Dongli Zhou, Wesley K. Thompson, and Greg Siegle, “MATLAB toolbox for functional connectivity,” NeuroImage, vol. 47, 2009, 1590-1607.
[10] Anil K. Seth, “A MATLAB toolbox for Granger causal connectivity analysis,” Journal of Neuroscience Methods, vol. 186, 2010, p262-p273.
[11] Mark T. Elliott, Andrew E. Welchman, and Alan M.Wing, “MatTap: A MATLAB toolbox for the control and analysis of movement synchronisation experiments,” Journal of Neuroscience Methods, vol. 177, 2009, p250-p257.
[12] Travis Meyer, and Christos Constantinidis, “A software solution for the control of visual behavioral experimentation,” Journal of Neuroscience Methods, vol.142, 2005, p27-p34