Download as pdf or txt
Download as pdf or txt
You are on page 1of 32

A Simple Framework for Behavioral Experiments using

the Psychophysics Toolbox for MATLAB

Jens Schwarzbach
Trento University

For ASF Version 0.36 (incomplete)

1 The ASF-Practitioner's guide ...................................................................................... 1


1.1 Installation of ASF .............................................................................................. 1
1.2 Demo ................................................................................................................... 1
1.3 Format of the stimulus-file.................................................................................. 1
1.4 Format of the trial-file......................................................................................... 2
1.4.1 Line 1: Factor levels.................................................................................... 2
1.4.2 Line 2-end: Trial definitions ....................................................................... 2
1.5 Options, options, options: The Cfg-structure. ..................................................... 3
1.5.1 Configuring display options ........................................................................ 3
1.5.2 Configuring options for response collection ............................................... 4
1.5.3 Triggers and markers .................................................................................. 5
1.5.4 Timing ......................................................................................................... 5
1.5.5 Feedback ..................................................................................................... 5
1.5.6 User supplied advanced options.................................................................. 5
1.5.7 Miscellaneous ............................................................................................. 6
1.6 Format of the results ........................................................................................... 6
1.7 Example Applications ......................................................................................... 8
1.7.1 A masked priming experiment .................................................................... 8
1.7.2 Describing a trial as a sequence of pages of defined durations .................. 9
1.8 Extending ASF’s capabilities with user supplied stimulus presentation routines
9
1.9 Testing the timing ............................................................................................. 10
1.10 Extracting behavioral data ................................................................................ 10
1.11 Troubleshooting ................................................................................................ 10
2 The ASF-Programmer's guide .................................................................................. 11
2.1 Introduction ....................................................................................................... 11
2.1.1 Online help ................................................................................................ 11
2.1.2 Creating Screens ....................................................................................... 11
2.2 A simple framework for experiments (ASF) .................................................... 19
2.2.1 A masked priming experiment .................................................................. 19
2.2.2 Describing a trial as a sequence of pages of defined durations ................ 20
2.2.3 A simple playback-scheme ....................................................................... 21
2.2.4 Telling the program when to start measuring reaction time ..................... 21
2.2.5 Other information you might want to store in a trial-definition ............... 21
2.2.6 Reading image-information for an entire experiment ............................... 21
2.2.7 Reading trial-information for an entire experiment .................................. 22
2.2.8 Encoding and Decoding ............................................................................ 24
3 Release Notes ............................................................................................................ 26
4 Index ......................................................................................................................... 28

2
What is ASF?
ASF stands for A Simple Framework for presenting visual and auditory stimuli in
behavioral experiments. It is based on the Psychophysics Toolbox for Matlab
www.psychtoolbox.org, which needs to be installed for ASF to run. The idea is to write a
program that reduces the experimenter’s task of programming behavioral experiments to
generating tables of stimulus- and trial descriptions while accurate timing of stimuli,
collecting responses from different devices such as voice-keys, button boxes or a
computer mouse, generating triggers for EEG/MEG equipment and synchronization with
MR-scanners and response-logging is dealt with in the background. While this little list
of tasks makes already clear that the name ASF becomes more and more of a misnomer I
hope that it makes experimenting simpler and that it is easy to use.
This document has two parts, one for users who want to run experiments with minimal
programming using ASF as a kind of accurate slide show player, and one part for users
who want to program customized experiments taking advantage of tasks already
operational in ASF. For example, if you have a set of pictures that you want to show with
high temporal accuracy and collect participant’s responses, part one shows you how to do
that. If you want to program an experiment with some complex rendering, e.g. moving
stimuli, but you do not want to reinvent the wheel in terms of how to link with an MR
scanner and different response devices, have a look at part two.
The ASF-Practitioner's guide

1 The ASF-Practitioner's guide


1.1 Installation of ASF
ASF is a collection of files that can reside anywhere on your computer’s hard drive in a
subdirectory called ASF, for example ‘C:\applications\ASimpleFramework’. Make sure
that the path to ASF’s installation directory is part of Matlab’s search path.

1.2 Demo
This section describes a simple framework (ASF) for running behavioral experiments
running using the Psychtoolbox for Matlab.
ASF needs four things from you:
1. a textfile that contains the names of all image files that will be displayed during
the experiment (stimulus-file), the file extension is .std
2. a textfile that contains trial by trial information about what image should be
shown and for how long (trial-file), the file extension is .trd
3. a name for a file that will hold the results (result-file), and
4. a structure Cfg that contains settings that you wish to apply to the program (e.g.
about your display).
An experiment using the Matlab Psychtoolbox is invoked by typing:
[expinfo] = ASF(stimulusfile, trialfile, expname, Cfg)

You can run a demo of a same-different task by typing:


[expinfo] = ASF('demo1.std', 'demo1.trd', demo1_'testsubject', [])
In each trial you will see two stimuli in brief succession. Your task is to press one of two
mouse buttons to indicate as fast and accurately as possible whether the two stimuli were
the same (left button) or different (right button).
In this example Demo1.std contains the list of images that will be shown. Demo1.trd
contains a trial by trial description about which image will be shown in a trial, when
reaction time measurement starts and what the experimenter considers to be the correct
response.
Note that running this demo requires that your current directory is ASF’s installation
directory (see Installation of ASF).

1.3 Format of the stimulus-file


This section explains how to set up the same-different task from the demo above. The
stimulus-file is a text file with the default extension .std (stimulus-definition) that
contains the names of all image files that will be displayed during the experiment. Each
line contains one filename, either a filename alone, a relative or a full path. The
experiment contains 4 images: 1) an empty screen, 2) a fixation cross, 3) a leftward-
pointing arrow plus fixation cross, 4) a rightward-pointing arrow plus a fixation cross.
If the images reside in the current working directory of Matlab it is sufficient just to put
the filenames into the stimulus-file, for example the file test.std could have the following
content:
img_1.bmp
img_2.bmp
1
The ASF-Practitioner's guide

img_3.bmp
You can also write absolute path names into the stimulus-file:
c:\experiments\experiment1\images\img_1.bmp
c:\experiments\experiment1\images\img_2.bmp
c:\experiments\experiment1\images\img_3.bmp
The recommended option is to use relative path-descriptions. If the images reside in a
subdirectory of the current working directory with the name 'images', then you can put a
relative path-description to each file into the stimulus-file, for example:
.\images\img_1.bmp
.\images\img_2.bmp
.\images\img_3.bmp

1.4 Format of the trial-file


The trial-file is a textfile with the extension .trd (trial-definition) that consists of two
sections:
• The first line contains the factorial information for your experiment. If you want
to code your experiment e.g. as a 2 by 3 by 4 design this line would read '2 3 4'.
• The remainder of the file contains one entry per trial. It starts with a trial-code
(see below for encoding and decoding), trial onset time with respect to
experiment-start (by default not used, but can be switched on with
Cfg.useTrialOnsetTimes = 1), followed by pairs of entries that describe a picture-
event or page (picture number, picture duration in frames). The second to last
entry contains the page-number at which reaction time measurement in a given
trial should start. The last entry contains a number for the correct response.
Factor_1_NumLevels … Factor_n_NumLevels
Code tOnset PicNum_1 PicDur_1 … … PicNum_n PicDur_n StartRTonPic CorrectResponse

Code tOnset PicNum_1 PicDur_1 … … PicNum_n PicDur_n StartRTonPic CorrectResponse

In our simple experiment a trial consists of showing each of the three pictures above for
one second and measure reaction time starting from the second picture. Note that picture-
duration is referred to in frames whose duration depends on the refresh rate of your
monitor. Let us assume you have a 100Hz monitor. This means that each picture in your
experiment has a duration of 100 frames. On different trials you want to show the
pictures in different order.

1.4.1 Line 1: Factor levels


You do not have much of a factorial design here, but maybe you want to code the order
as a factor having six levels. The first entry of your trial-file would simple read '6'. If you
had more experimental factors you would simply add one number per factor which
indicates the number of levels. A two-factorial design with three and two levels
respectively would lead to the entry '3 2'.

1.4.2 Line 2-end: Trial definitions


The following table contains the trial definitions as described above: code, trial onset
time with respect to experiment-start, followed by pairs of values that describe a page
(picture number, picture duration), followed by the page number at which reaction time

2
The ASF-Practitioner's guide

measurement starts. Note: Consider using the encode() function described in section 2.2.8
for assigning codes to trials.

code Time P1 PD1 P2 PD2 P3 PD3 P4 PD4 P5 PD5 P6 PD6 P7 PD7 StartRT Corr.
Resp
1 2 1 30 2 30 3 1 2 4 3 1 2 90 1 1 5 1
2 4 1 30 2 30 3 1 2 4 4 1 2 90 1 1 5 3
3 6 1 30 2 30 4 1 2 4 4 1 2 90 1 1 5 3
4 8 1 30 2 30 4 1 2 4 3 1 2 90 1 1 5 3

The entire file 'test.trd' would look like this:


4
01 2 1 30 2 30 3 1 2 4 3 1 2 90 1 1 5 1
02 4 1 30 2 30 3 1 2 4 4 1 2 90 1 1 5 3
03 6 1 30 2 30 4 1 2 4 4 1 2 90 1 1 5 1
04 8 1 30 2 30 4 1 2 4 3 1 2 90 1 1 5 3

1.5 Options, options, options: The Cfg-structure.


When calling the program you can leave the Cfg-structure empty. The program will run
with its default settings. Typing the following command at Matlab’s command line will
run a little demo of masked priming described in more detail below (section 1.7).
[ExpInfo] = ASF('test.std', 'test.trd', 'testsubject', [])
Note that this demo requires that your current working directory is the installation
directory of ASF.
You can change the behavior of the program using the Cfg-structure and then call the
program with [ExpInfo] = ASF('test.std', 'test.trd', 'testsubject', Cfg). Below find a list of
how to change ASF’s behavior. This list will eventually grow. Between square brackets
behind each Cfg-option is a list of accepted values, with the default value between curly
brackets.

1.5.1 Configuring display options


Below, each configuration option is described with different possible parameter values
listed between square brackets. The default setting is given between curly brackets.
- Cfg.Screen.rect [{[]}, [ulRowStart, ulColStart, ulRowEnd, ulColEnd] ]
Determines the screen size and position. For example 'Cfg.Screen.rect = [1, 1, 320,
240];' makes the experiment run in the upper left corner of the primary screen.
Leaving this parameter empty defaults to using the entire screen of the monitor with
the highest screen-number, i.e. the primary display in a single display computer and
the secondary display in a dual-screen setup.
- Cfg.useBackBuffer [0|{1}]
Depending on your graphics board your computer may complain that it cannot
perform the flip operation [VBLTimestamp StimulusOnsetTime FlipTimestamp
Missed Beampos] = Screen('Flip', windowPtr, [], 1); The default value is 1, setting
this parameter to 0 enables also less-sophisticated graphics boards to run page-
flipping.

3
The ASF-Practitioner's guide

- Cfg.Screen.color [{[255, 255, 255]}|[R, G, B]]


Screen background color defaults to white, can be any RGB value.
- Cfg.Screen.Resolution
You can force your experiment to run with certain video resolutions. This may be
particularly interesting on LCD displays or projectors, which produce best results
when operated in their native resolution
o Cfg.Screen.Resolution.width [{width of current video resolution}]
o Cfg.Screen.Resolution.height [{heigth of current video resolution}]
o Cfg.Screen.Resolution.pixelSize [{color depth of current video resolution}]
o Cfg.Screen.refreshRateHz [{refresh rate of current video resolution}]
- Cfg.Screen.fontSize [{24}]
Fontsize with which status messages are displayed, and with which text is rendered
should you use the drawText function in your code.
- Cfg.Screen.fontName {'Courier New'}
Fonttype with which status messages are displayed, and with which text is rendered
should you use the drawText function in your code.

1.5.2 Configuring options for response collection


- Cfg.responseTerminatesTrial [{0}|1]
This parameter determines the program's behavior when the participant gives a
response. Setting the parameter to zero means that a picture will be shown for the
requested time even if you already have given a response. If you set the parameter to
1 picture presentation will be terminated even before the required picture duration has
expired in case the participant has given a response. This is an often-used feature for
implementing a response period after stimulus presentation. You show an empty
picture for lets say up to 1500ms, which is terminated if your subject has pressed a
button. Thereby you do not unnecessarily slow down your participant.
- Cfg.waitUntilResponseAfterTrial [{0}|1]
Setting this parameter to 1 forces the program to wait for a response at the end of
each trial irrespective of the duration of the last page to be shown in this trial.
- Cfg.responseDevice [ {'MOUSE'}|'VOICEKEY'|'LUMINAPARALLEL',
‘KEYBOARD’ ]
The default response device is a computer mouse, other options are a voicekey using
the computer’s soundcard, and a Lumina response box connected to the parallel port
or the computer’s keyboard.
- Cfg.plotVOT [ {0}, 1 ]
When using a voice key this option allows plotting voice onset times in a separate
window (requires two screens).
- Cfg.Eyetracking.useEyelink [ {0}, 1 ]
Use an EyeLink eyetracker as response device.
- Cfg.Eyetracking.useEyelinkMouseMode [ {0}, 1 ]
Pretend using an EyeLink eyetracker as response device (mouse simulates EL).

4
The ASF-Practitioner's guide

1.5.3 Triggers and markers


- Cfg.issueTriggers [ {0} | 1 ]
Allows triggering external devices or setting markers for EEG/MEG data acquisition
using the parallel port. This feature requires the Matlab data acquisition toolbox to be
installed.
- Cfg.synchToScanner [ {0} | 1 ]
Wait for an external signal, for example a trigger from an MR-scanner to start
experiment.
- Cfg.synchToScannerPort [{'PARALLEL'} | 'SERIAL' | ’SIMULATE’]
Determine port on which to expect synchronization signals. Using the parallel port
requires the Matlab data acquisition toolbox to be installed.
- Cfg.serialPortName [ {'COM1'}, ... 'COMn' ]
Determine which serial port is used.
- Cfg.scannerSynchTimeOutMs {inf}
Timeout in milliseconds when waiting for scanner trigger on any port. In combination
with simulated scanner port gives you an idea of how your experiments behaves in an
MR setup (currently this combination is not very accurate).
- Cfg.digitalInputDevice [ {'NONE'}|'PARALLEL'|'NIDAQ2' ]
- Cfg.digitalOutputDevice [ {'NONE'}|'PARALLEL'|'NIDAQ2' ]
- Cfg.ScannerSynchShowDefaultMessage = [0|{1}]
By default synching to the scanner (invoked by call to ASF_WaitForScannerSynch)
produces a status message on the primary screen and in Matlab’s command window.
You can suppress these messages by setting this parameter to 0.

1.5.4 Timing
- Cfg.useTrialOnsetTimes [ {0} | 1 ]
By default, trials follow each other as fast as possible. Setting this parameter to 1
means that the second column of a trial definition determines the time with respect to
the start of the experiment at which a given trial is started. This feature can be used
for temporal jittering of trials in event-related fMRI studies.

1.5.5 Feedback
- Cfg.feedbackTrialCorrect [ {0} | 1 ]
Beep after a correct response.
- Cfg.feedbackTrialError [ {0} | 1 ]
Beep after an incorrect response.
- Cfg.onlineFeedback [ {0} | 1 ]
Provides trial by trial and cumulative statistics. Particularly useful when using
dualscreen displays. Requires statistics toolbox.

1.5.6 User supplied advanced options


- Cfg.userSuppliedTrialFunction [ {[]} | FUNCTIONHANDLE ]
ASF uses by default an internal function ShowTrial() to render stimuli and to control
their presentation. However, you may want to write your own function in order to
present customized stimuli. You may consider rewriting the function

5
The ASF-Practitioner's guide

ASFShowTrialSample.m for your purposes. In order to ASF calling your code and
not its internal one you need to provide a pointer to this function in the Cfg-structure,
in this case by typing ‘Cfg.userSuppliedTrialFunction = @ASFShowTrialSample.m’.
The ASF-Programmer’s Guide below gives more information about that.
- Cfg.userDefinedTRDcolumns [ {0} | nColumns ]
Users can supply additional information in a trial-definition file that they can use in
their own trial function. For example you may want to add two columns per trial
which tell your trialfunction where to show a bitmap (default is at the center of the
screen). These columns are inserted after column 2.
The following example shows a possible trial definition file in which stimuli are
shown at four different positions on the screen ([-100, 0; 0 100; 100, 0; 0, -100]).
Note that if you want to show stimuli at different positions you also have to write
your own stimulus presentation routine (see Cfg.userSuppliedTrialFunction above).
6
1 2 -100 0 1 100 2 100 3 100 2
2 4 0 100 1 100 3 100 2 100 2
3 6 100 0 2 100 1 100 3 100 2
4 8 0 -100 2 100 3 100 1 100 2
5 10 -100 0 3 100 1 100 2 100 2
6 12 0 100 3 100 2 100 1 100 2

1.5.7 Miscellaneous
- Cfg.randomizeTrials [ {0} | 1 ]
Trialwise randomization of the TRD-file. Not really a recommended feature since it
can interfere with other features such as trial-onset times (see below) or
counterbalancing of conditions. It is recommended that the order of trial presentations
is managed by the program or person which or who creates the TRD-files.

1.6 Format of the results


The program returns a structure expinfo which has the following fields:
- stimnames: a cell-array that contains the filenames of the images shown or in
other words the content of the stimulus-file
- factorinfo: the factorial structure as defined in the first line of the trial-file
- Cfg: the configuration of the experiment. This is more than you provide when
calling the program. It contains information about the hardware, software, as well
as the settings that the program used for displaying stimuli.
Fieldnames are:
o 'ASFVersion'
o 'Screen'
o 'useBackBuffer'
o 'responseTerminatesTrial'
o 'randomizeTrials'
o 'waitUntilResponseAfterTrial'
o 'responseDevice'
o 'plotVOT'
o 'issueTriggers'
o 'synchToScanner'

6
The ASF-Practitioner's guide

o 'synchToScannerPort'
o 'useTrialOnsetTimes'
o 'feedbackTrialCorrect'
o 'feedbackTrialError'
o 'Task'
o 'Fs'
o 'userSuppliedTrialFunction'
o 'userDefinedSTMcolumns'
o 'stimNames'
o 'trialFileName'
o 'pathstr'
o 'name'
o 'ext'
o 'version'
o 'frameRate'
o 'monitorFlipInterval'
o 'getFlipInterval'
o 'Environment'
o 'nTrials'
o 'experimentStart'
- trialinfo: A structure array that contains trial by trial information.
o trialinfo.trial: the description for a given trial as read in from the trial-file
o trialinfo.datestr: date and time when the trial has been shown
o trialinfo.response: which key has been pressed and respective reaction
time of the trial
o trialinfo.timing: not yet documented
o trialinfo.startRTMeasurement: not yet documented
o trialinfo.endRTMeasurement: not yet documented

Find below a piece of code that puts the results of your experiment into an easy-to-handle
matrix format.
function res = read_expinfo(expinfo)
%PACK DATA FROM EXPINFO INTO A MATRIX
%ROW -> trial
%COL 1: CODE
%COL 2: RT
%COL 3: KEY
nTrials = length(expinfo.TrialInfo);
res(nTrials, 3) = 0;
for i=1:nTrials
res(i, 1) = expinfo.trialinfo(i).trial.code;
res(i, 2) = expinfo.trialinfo(i).response.RT;
res(i, 3) = expinfo.trialinfo(i).response.key;
end

7
The ASF-Practitioner's guide

Use the function decode() described in section 2.2.8 to retrieve the factorial combination
of any given trial.

1.7 Example Applications


1.7.1 A masked priming experiment

Figure 1: Typical masked priming experiments show primes and masks at different SOAs and
response congruencies. Researchers investigate whether presenting a masked stimulus can
nevertheless influence reaction times to a target stimulus, which is in this case the mask itself (see e.g.
Vorberg et al., 2003). Timing is provided in milliseconds and corresponding number of frames on a
60Hz display.
Material and Procedures: Stimuli are presented on a 60 Hz display, i.e. stimulus
duration is quantized in steps of one frame duration (1/60th of a second or 16.6667 ms).
Each trial begins with showing a fixation cross at the center of the screen for 30 frames
(WarningPeriod). Primes are shown above fixation for one frame (PrimeDuration).
Primes are either neutral, pointing to the left or to the right. Stimulus onset asynchrony
(SOA) varies between zero and five frames. From that follows that for SOAs shorter than
PrimeDuration there is a period of temporal overlap of prime and mask (Overlap = SOA-
PrimeDuration). If SOA equals PrimeDuration there is a direct succession of the prime by
a mask. If SOA is longer than PrimeDurationthere is variable interstimulus interval (ISI)
between prime an mask in which only the fixation cross is shown (ISI = SOA-
PrimeDuration). The mask is shown altogether for 6 frames (MaskDuration). Masks
appear centered around the same location as the prime and they either point to the left or
to the right. After extinguishing the mask there is a fixation cross for 90 frames
(ResponsePeriod) which is terminated either by a participant's response or when
Response period has expired. Between trials there is a fixed inter trial interval (ITI) of
500ms. Reaction time measurement starts when presenting the mask.

8
The ASF-Practitioner's guide

The following figure depicts a trial with prime and mask pointing to the left (i.e.
congruent trial) with an SOA of 83 ms (i.e. 5 frames).
A B
Picture 1: Picture 2:
Empty.bmp Fix.bmp

Picture 3: Picture 4:
PrimeL.bmp MaskL.bmp

Figure 2: A) Detailed sequence of frames in a congruent trial with an SOA of 83ms between prime
and mask. B) Pictures used in this trial.
Sequence of events (pages) in this trial:
• Empty screen for 30 frames
• Fixation cross for 30 frames
• Prime (e.g. arrow left) and fixation cross for 1 frame
• fixation cross for 4 frames
• Mask (e.g. arrow left) and fixation cross for 5 frames
• Empty screen for 90frames
• Reaction time measurement starts with the onset of the mask

1.7.2 Describing a trial as a sequence of pages of defined durations


The trial above uses four different pictures (Picture 1-4) which are shown in the order:
1, 2, 3, 2, 4, 1. Their respective duration in frames is: 30, 30, 1, 4, 6, 90.

1.8 Extending ASF’s capabilities with user supplied stimulus


presentation routines
By default ASF presents stimuli by means of its built-in function “ShowTrial”. This
function takes as arguments a structure atrial (holds information about page order and
page durations), windowPtr (a handle to the window in which stimuli are presented),
Stimuli (a matrix of handles to textures) and the structure Cfg (holds user and program-
supplied configuration info).
TrialInfo = ShowTrial(atrial, windowPtr, Stimuli, Cfg)
The functionality of this function is that it plays back pages in a certain order and of
certain durations. Furthermore, the function deals with response collection. You can alter
9
The ASF-Practitioner's guide

the functionality of ASF by writing your own equivalent of ShowTrial that has the same
interface, .ie. same input and output arguments, but other functionality. The following
section describes how you can enhance stimulus presentation from pure visual
presentations to combined audiovisual presentations.

1.9 Testing the timing


1.10 Extracting behavioral data
1.11 Troubleshooting

10
The ASF-Programmer's guide

2 The ASF-Programmer's guide


ASF is based on the Psychtoolbox for Matlab. Psychophysics Toolbox Version 3 (PTB-3)
is a free set of Matlab functions for vision research. It makes it easy to synthesize and
show accurately controlled visual stimuli and interact with the observer.

2.1 Introduction
2.1.1 Online help
"help Psychtoolbox" provides a general overview. Detailed help is provided by typing
"help <function_name>" e.g. "help Screen". More focused help on how to use a specific
parameter, e.g. the OpenWindow parameter of the function Screen is provided by
"Screen('OpenWindow?')". The website www.psychtoolbox.org gives you the latest
information.

2.1.2 Creating Screens


The function Screen() is the heart of the Psychophysics Toolbox, providing fifty
subfunctions (selected by a text argument) that control the display screen(s). Experiments
typically begin with a call to Screen('OpenWindow'), which creates an onscreen window,
and end with a call to Screen('Close').
A Single-screen setup B Dual-screen setup

Figure 3: Screens in the PTB. A) Single screen setup. Screen 1 is the primary diplay. B) Dual-screen
setup. If you have multiple displays attached to your computer, screen 2 is the secondary display and
so forth. Screen 0 is all your displays next to each other. For example, in a multi-display setup you
can use Screen 1 for programming and Screen 2 for displaying your stimulus. If you only have one
screen, the stimulus will at least partially occlude your progrm window, whjich can become difficult
for debugging.

Typically you will create a window on each screen that you are using in your
experiment. An onscreen window contains a backbuffer and a frontbuffer. The
backbuffer is where all drawing operations are performed i.e. where you build/prepare
your stimulus for presentation. The frontbuffer is displayed at the display refresh interval.
After you have finished drawing and your stimulus image is ready in the backbuffer, you
issue the Screen('Flip',...) command. This command asks PTB to switch the role of the
front- and back- buffer at the next vertical retrace of your display device. This way, the
former backbuffer becomes the new frontbuffer and your new stimulus gets shown to the
subject. The former frontbuffer becomes the new backbuffer and is ready for drawing the
next stimulus on.
11
The ASF-Programmer's guide

2.1.2.1 A 'Hello world' program for the Matlab Psychophysics toolbox


This program creates a window for displaying stimuli using the psychophysics toolbox. It
fills the window with a default color (white). And it draws some text
function DemoScreen_1
%function DemoScreen_1
%
% Demo_Screen_1
%
% OS X:
%_______________________________________________________________
%
% Example of opening and closing a screen and of drawing text.
%
% _______________________________________________________________
%
% see also: Screen
% 8/1/07 jvs Wrote it.
try
%-----------------------------------------------------------------
%THIS SECTION IS FOR INITIALIZING YOUR DISLAY
%-----------------------------------------------------------------

%Find out which displays are available


%Screen 0 is always the full Windows desktop.
%Screens 1 to n are corresponding to
%windows display monitors 1 to n.
screenNumbers = Screen('Screens'); %returns an array of screen
% numbers

%determine highest available display number


highestScreenNumber = max(screenNumbers);

%create a window on the monitor with the highest number


%get help by typing on the command line: Screen('OpenWindow?')
%windowPtr is the reference to this newly created window
%
%VERSION 1: A SMALL WINDOW IN THE UPPRE LEFT
%windowPtr = Screen('OpenWindow', highestScreenNumber,…
% [], [1, 1, 320, 240]);
%VERSION 2: A FULLSCREEN WINDOW
windowPtr = Screen('OpenWindow', highestScreenNumber);

%Set some default properties for any text to be drawn in this


% window
Screen('TextFont', windowPtr, 'Courier New');
Screen('TextSize', windowPtr, 24);

%-----------------------------------------------------------------
%NOW YOU CAN START DRAWING ONTO THE BACK-BUFFER, WHICH WILL NOT
% BECOME VISIBLE UNTIL YOU FLIP IT TO THE FOREGROUND
%-----------------------------------------------------------------

12
The ASF-Programmer's guide

%fill the entire window with the default background color


Screen('FillRect', windowPtr);

%draw some text


Screen('DrawText', windowPtr, 'Hello World!',…
50, 100, [0, 0, 255, 255]);
Screen('DrawText', windowPtr, 'Hit any key to exit.',…
50, 150, [255, 0, 0, 255]);

%all the graphics operations only become visible once you "flip"
% the backbuffer to the foreground
%get help by typing on the command line: Screen('Flip?')
Screen('Flip', windowPtr, [], 1);

%wait until somebody presses a key on the keyboard


pause

%-----------------------------------------------------------------
%SHUTDOWN OF ALL WINDOWS CREATED BY THE PSYCHOPHYSICS TOOLBOX
%-----------------------------------------------------------------
%Close all open onscreen and offscreen windows and textures
Screen('CloseAll');

catch
% This "catch" section executes in case of an error in the "try"
% section above.
% Importantly, it closes the onscreen window if it's open.
Screen('CloseAll');
%display the last error message
psychrethrow(psychlasterror);
end

2.1.2.1.1 Tasks
Change the program that it creates its window in the upper right of the screen using one
quarter of your display.
Hint: You can determine the size of your display by typing
ScreenDim = get(0, 'ScreenSize') on the Matlab command line. You will get a vector that
contains [upperLeftRow, upperLeftColumn, width, height]

13
The ASF-Programmer's guide

2.1.2.2 Showing an image


function Demo_Screen_2_Images
% Demo_Screen_2_Images
%
% OS X:
%________________________________________________________________
%
% Example of showing an image using textures and of drawing text.
%
%_____________________________________________________________________
%
% see also: Screen
% 8/1/07 jvs Wrote it.
try
%-----------------------------------------------------------------
%THIS SECTION IS FOR INITIALIZING YOUR DISLAY
%-----------------------------------------------------------------

%Find out which displays are available


%Screen 0 is always the full Windows desktop.
%Screens 1 to n are corresponding to
%windows display monitors 1 to n.
screenNumbers = Screen('Screens'); %returns an array of screen
% numbers

%determine highest available display number


highestScreenNumber = max(screenNumbers);

%create a window on the monitor with the highest number


%get help by typing on the command line: Screen('OpenWindow?')
%windowPtr is the reference to this newly created window
%
%VERSION 1: A SMALL WINDOW IN THE UPPRE LEFT
windowPtr = Screen('OpenWindow', highestScreenNumber,…
[], [1, 1, 320, 240]);
%VERSION 2: A FULLSCREEN WINDOW
%windowPtr = Screen('OpenWindow', highestScreenNumber);

%Set some default properties for any text to be drawn in this


%window
Screen('TextFont', windowPtr, 'Courier New');
Screen('TextSize', windowPtr, 24);

%-----------------------------------------------------------------
%NOW YOU CAN START DRAWING ONTO THE BACK-BUFFER, WHICH WILL NOT
% BECOME
%VISIBLE UNTIL YOU FLIP IT TO THE FOREGROUND
%-----------------------------------------------------------------

%fill the entire window with the default background color


%Screen('FillRect', windowPtr);

14
The ASF-Programmer's guide

%read image
image_matrix = imread('.\images\pic_001.jpg');

texturePtr = Screen('MakeTexture', windowPtr, image_matrix);

Screen('DrawTexture', windowPtr, texturePtr)


%draw some text
Screen('DrawText', windowPtr, 'Hit any key to exit.',…
50, 150, [255, 0, 0, 255]);

%all the graphics operations only become visible once you "flip"
% the %backbuffer to the foreground
%get help by typing on the command line: Screen('Flip?')
Screen('Flip', windowPtr, [], 1);

%wait until somebody presses a key on the keyboard


pause

%-----------------------------------------------------------------
%SHUTDOWN OF ALL WINDOWS CREATED BY THE PSYCHOPHYSICS TOOLBOX
%-----------------------------------------------------------------
%Close all open onscreen and offscreen windows and textures
Screen('CloseAll');

catch
% This "catch" section executes in case of an error in the "try"
% section above.
%Importantly, it closes the onscreen window if it's open.
Screen('CloseAll');
%display the last error message
psychrethrow(psychlasterror);
end

15
The ASF-Programmer's guide

2.1.2.2.1 Showing all images in a directory for one second and record mouse
buttons as responses
This program is the Psychophysics Toolbox version of the homework assignment from
session 4
• Suppose you have n images on your harddisk (image_1.bmp...image_n.bmp).
• Write a program that displays each image for 1s and that collects a mouse
response

function response = Demo_Screen_3_SlideShow(imDir)


%function response = Demo_Screen_3_SlideShow(imDir)
% Demo_Screen_2_Images
%
% OS X:
___________________________________________________________________
%
% Example of slide-show, reaction time measurement, and drawing text.
%
% __________________________________________________________________
%
% see also: Screen

% 8/1/07 jvs Wrote it.


try
%-----------------------------------------------------------------
%THIS SECTION IS FOR INITIALIZING YOUR DISLAY
%-----------------------------------------------------------------

%Find out which displays are available


%Screen 0 is always the full Windows desktop.
%Screens 1 to n are corresponding to
%windows display monitors 1 to n.
screenNumbers = Screen('Screens'); %returns an array of screen
%numbers

%determine highest available display number


highestScreenNumber = max(screenNumbers);

%create a window on the monitor with the highest number


%get help by typing on the command line: Screen('OpenWindow?')
%windowPtr is the reference to this newly created window
%
%VERSION 1: A SMALL WINDOW IN THE UPPRE LEFT
%windowPtr = Screen('OpenWindow', highestScreenNumber,…
% [], [1, 1, 320, 240]);
%VERSION 2: A FULLSCREEN WINDOW
windowPtr = Screen('OpenWindow', highestScreenNumber);

%Set some default properties for any text to be drawn in this


%window
Screen('TextFont', windowPtr, 'Courier New');
Screen('TextSize', windowPtr, 24);

16
The ASF-Programmer's guide

%get the name of all images in the directory


d = dir(imDir);
d(1:2) = []; %remove the first two entries, they relate to parent
% and child directories
nFiles = length(d);
%-----------------------------------------------------------------
%NOW YOU CAN START DRAWING ONTO THE BACK-BUFFER, WHICH WILL NOT
% BECOME
%VISIBLE UNTIL YOU FLIP IT TO THE FOREGROUND
%-----------------------------------------------------------------

%read images and draw them onto a texture


%(kind of offscreen buffer)
for i = 1:nFiles
imname = fullfile(imDir, d(i).name); %name of current image
image_matrix = imread(imname); %read image
%Create texture.
%get help by typing on the command line: Screen('MakeTexture?')
texturePtr(i) = Screen('MakeTexture', windowPtr, image_matrix);
end

response(nFiles).button = []; %pre-allocate response data


response(nFiles).time = []; %pre-allocate response data
for i = 1:nFiles
%Draw texture on back buffer
Screen('DrawTexture', windowPtr, texturePtr(i))

%all the graphics operations only become visible once you


% "flip" the backbuffer to the foreground
%get help by typing on the command line: Screen('Flip?')
Screen('Flip', windowPtr, [], 1);
%Wait for a mouse button press for maximally 1 second
[x, y, buttons, t0, t1] = WaitForMousePress(1);
if any(buttons)
%a button has been pressed before timeout
WaitSecs(1 - (t1-t0) -0.005) %wait out the remainder of the
% stimulus duration 5ms margin
response(i).button = find(buttons); %find which button it
% was
response(i).time = (t1-t0)*1000; %compute response time
end

end
%fill the entire window with the default background color
Screen('FillRect', windowPtr);

%draw some text


Screen('DrawText', windowPtr, 'BYE!',…
50, 100, [0, 0, 255, 255]);
Screen('DrawText', windowPtr,…
'Hit any key to exit.', 50, 150, [255, 0, 0, 255]);
Screen('Flip', windowPtr, [], 1);

17
The ASF-Programmer's guide

%wait until somebody presses a key on the keyboard


pause

%-----------------------------------------------------------------
%SHUTDOWN OF ALL WINDOWS CREATED BY THE PSYCHOPHYSICS TOOLBOX
%-----------------------------------------------------------------
%Close all open onscreen and offscreen windows and textures
Screen('CloseAll');

%-----------------------------------------------------------------
%PLOT REACTION TIMES
%-----------------------------------------------------------------
figure
plot(vertcat(response.time), 'o-')
xlabel('TRIAL')
ylabel('RT [ms]')

catch
% This "catch" section executes in case of an error in the "try"
%section above.
% Importantly, it closes the onscreen window if it's open.
Screen('CloseAll');
%display the last error message
psychrethrow(psychlasterror);
end

function [x, y, buttons, t0, t1] = WaitForMousePress(timeout)


buttons = 0;
t0 = GetSecs;
t1 = t0;
while (~any(buttons) & (t1 - t0)<timeout) % wait for press
[x,y,buttons] = GetMouse;
t1 = GetSecs;
% Wait 1 ms before checking the mouse again to prevent
% overload of the machine at elevated Priority()
WaitSecs(0.001);
end

18
The ASF-Programmer's guide

2.2 A simple framework for experiments (ASF)


2.2.1 A masked priming experiment

Figure 4: Typical masked priming experiments show primes and masks at different SOAs and
response congruencies. Researches investigate whether presenting a masked stimulus can
nevertheless influence reaction times to an target stimulus, which is in this case the mask itself (see
e.g. Vorberg et al., 2003). Timing is provided in milliseconds and corresponding number of frames on
a 60Hz display.
Material and Procedures: Stimuli are presented on a 60 Hz display, i.e. stimulus
duration is quantized in steps of one frame duration (1/60th of a second or 16.6667 ms).
Each trial begins with showing a fixation cross at the center of the screen for 30 frames
(WarningPeriod). Primes are shown above fixation for one frame (PrimeDuration).
Primes are either neutral, pointing to the left or to the right. Stimulus onset asynchrony
(SOA) varies between zero and five frames. From that follows that for SOAs shorter than
PrimeDuration there is a period of temporal overlap of prime and mask (Overlap = SOA-
PrimeDuration). If SOA equals PrimeDuration there is a direct succession of the prime by
a mask. If SOA is longer than PrimeDurationthere is variable interstimulus interval (ISI)
between prime an mask in which only the fixation cross is shown (ISI = SOA-
PrimeDuration). The mask is shown altogether for 6 frames (MaskDuration). Masks
appear centered around the same location as the prime and they either point to the left or
to the right. After enxtinguishing the mask there is a fixation cross for 90 frames
(ResponsePeriod) which is terminated either by a participant's response or when
Response period has expired. Between trials there is a fixed inter trial interval (ITI) of
500ms. Reaction time measurement starts when presenting the mask.
The following figure depicts a trial with prime and mask pointing to the left (i.e.
congruent trial) with an SOA of 83 ms (i.e. 5 frames).

19
The ASF-Programmer's guide

A B
Picture 1: Picture 2:
Empty.bmp Fix.bmp

Picture 3: Picture 4:
PrimeL.bmp MaskL.bmp

Figure 5: A) Detailed sequence of frames in a congruent trial with an SOA of 83ms between prime
and mask. B) Pictures used in this trial.
Sequence of events (pages) in this trial:
• Empty screen for 30 frames
• Fixation cross for 30 frames
• Prime (e.g. arrow left) and fixation cross for 1 frame
• fixation cross for 4 frames
• Mask (e.g. arrow left) and fixation cross for 5 frames
• Empty screen for 90frames
• Reaction time measurement starts with the onset of the mask

2.2.2 Describing a trial as a sequence of pages of defined durations


The trial above uses four different pictures (Picture 1-4) which are shown in the order:
1, 2, 3, 2, 4, 1. Their respective duration in frames is: 30, 30, 1, 4, 6, 90.

In MATLAB we can read images and store them in a matrix.


img(1, :, :) = imread(‘empty.bmp’);
img(2, :, :) = imread(‘fix.bmp’);
img(3, :, :) = imread(‘prime_left.bmp’);
img(4, :, :) = imread(‘mask_left.bmp’);
Sequences can be stored in vectors that are part of a structure 'trial' which describes a
given trial.
trial.pagenumber = [ 1, 2, 3, 2, 4, 1];
trial.pageduration = [30, 30, 1, 4, 6, 90]

20
The ASF-Programmer's guide

2.2.3 A simple playback-scheme


The code below uses the values stored in the variables img and trial to loop over the
sequence of pages with their respective durations in order to implement a timed picture
show. Note that the functions ShowImage() and WaitFrames() have yet to be defined.
nPages = length(trial.pagenumber);
for p = 1:nPages
ShowImage(img(trial.pagenumber, :, :))
WaitFrames(trial.pageduration(p))
end

2.2.4 Telling the program when to start measuring reaction time


In our example we wanted to start measuring reaction time once the mask is presented.
We add this information to the variable trial.
trial.StartRTonPage = 5;

The following code implements the playback lop from above and measures reaction time.
Note that the functions ShowImage() and WaitMs() and CheckWhenButtonWasPressed()
have yet to be defined.
nPages = length(trial.pagenumber);
for p = 1:nPages
ShowImage(img(trial.pagenumber, :, :))
if (p == trial. StartRTonPage)
t0 = GetSecs; %GetSecs is a PTB function
end
WaitFrames(trial.pageduration(p))
end
t1 = CheckWhenButtonWasPressed; %returns time of button press
Trial.RT = t1-t0;

2.2.5 Other information you might want to store in a trial-definition

The code of this trial:


trial.code = 21;

2.2.6 Reading image-information for an entire experiment


In order to enable the code to play back different tytpes of experiments we need to be
able to read in different images. Therefore we create a textfile (e.g. 'stimdef.txt') that
contains the filenames for all images in a given experiment.
.\images\empty.bmp
.\images\fix.bmp
.\images\prime_left.bmp
.\images\mask_left.bmp
.\images\mask_right.bmp

The following code reades the images and puts them onto textures (using PTB-functions):
function [stimnames, tex] = read_stimuli(windowPtr, fname_stim)
%function [stimnames, tex] = read_stimuli(windowPtr, fname_stim)

21
The ASF-Programmer's guide

%Loads bitmaps from a list specified in a textfile onto textures


%if successful returns nstimulus names and textures
%Example Call:
%[stimnames, tex] = read_stimuli(windowPtr, 'stimdef.txt')

%READ STIMULUS-NAMES
stimnames = importdata(fname_stim);
nStimuli = size(stimnames, 1);

%USE MATLAB'S PROGRESS BAR FOR FEEDBACK


h = waitbar(0,'Loading images...');

%CHECK WHETHER IMAGES EXIST


errorFlag = 0;
for i = 1:nStimuli
waitbar(i/nStimuli,h)

fprintf(1, 'STIMULUS: %s ...', stimnames{i});


if(exist(stimnames{i}))
%IF FILE EXISTS...
fprintf(1, 'OK\n');

%READ IMAGE INTO MATRIX


imdata=imread(stimnames{i});

%PUT IMAGE ON A TEXTURE


tex(i) = Screen('MakeTexture', windowPtr, imdata);
else
%IF FILE DOES NOT EXIST
fprintf(1, 'NOT FOUND\n');
errorFlag = errorFlag + 1;
stimnames = [];
tex = [];
return
end

end
close(h)

2.2.7 Reading trial-information for an entire experiment


The trial above has the following information
trial.code = 21;
trial.pagenumber = [ 1, 2, 3, 2, 4, 1];
trial.pageduration = [30, 30, 1, 4, 6, 90]
trial.StartRTonPage = 5;
We write this information to a text-file. We start with the trial-code and then we write
page by page the page number followed by page duration. At the end we write at which
page RT-measurement shall start. The single trial from above would be written as:

22
The ASF-Programmer's guide

code empty fix prime fix mask empty StartRT


code P1 PD1 P2 PD2 P3 PD3 P4 PD4 P5 PD5 P6 PD6
21 1 30 2 30 3 1 2 4 4 6 1 90 5

The description for an entire experiment can thus be stored in a textfile that contains n
lines for n trials.

code empty fix prime fix mask empty StartRT


code P1 PD1 P2 PD2 P3 PD3 P4 PD4 P5 PD5 P6 PD6
21 1 30 2 30 3 1 2 4 4 6 1 90 5
… … … … … … … … … … … … … …
… … … … … … … … … … … … … …
… … … … … … … … … … … … … …
The following code reades the trial definitions into memory:
function [trialdefs, factorinfo, errorflag] = read_trialdefs(fname)
%function [trialdefs, factorinfo, errorflag] = read_trialdefs(fname)
%each line is composed of a list of entries, one line per trial
%<code> [pagenumber_1, pageduration_1]...[pagenumber_n, pageduration_n]
<StartRTonPage>
errorflag = 0;
if exist(fname) == 2
%FILE EXISTS
fid = fopen(fname);
aline = fgetl(fid);
factorinfo = str2num(aline);

counter = 0;
while 1
counter = counter + 1;
aline = fgetl(fid);
if ~ischar(aline), break, end
fprintf(1, '%s\n', aline)
aline = str2num(aline);
trialdefs(counter).code = aline(1);
trialdefs(counter).pagenumber = aline(2:2:(end-1));
trialdefs(counter).pageduration = aline(3:2:(end-1));
trialdefs(counter).StartRTonPage = aline(end);
end
fclose(fid);
else
%FILE DOES NOT EXIST
errorflag = 1;
error(sprintf('FILE %s NOT FOUND', fname))
end

23
The ASF-Programmer's guide

2.2.8 Encoding and Decoding

2.2.8.1 How encoding works


Suppose you have a 2x3x4 design (two masks, 3 primes, 4 SOAs). You can describe a
trial using these three values or you can try to pack them into one. The latter method is
especially helpful if you ant to set a marker in a data stream, e.g. in EEG. The table below
shows you how to assign one value to each combination of factors.
CODE Factor 1 Factor 2 Factor 3
1 0 0 0
2 0 0 1
3 0 1 0
4 0 1 1
5 0 2 0
6 0 2 1
7 1 0 0
8 1 0 1
9 1 1 0
10 1 1 1
11 1 2 0
12 1 2 1
13 2 0 0
14 2 0 1
15 2 1 0
16 2 1 1
17 2 2 0
18 2 2 1
19 3 0 0
20 3 0 1
21 3 1 0
22 3 1 1
23 3 2 0
24 3 2 1

2.2.8.2 Decoding
Decode is the function that returns the factorial combinations from a code that has been
generated by encode(). It takes the code or a vector of codes and the factorial design as
arguments. The program returns the factorial combinations (in most of the cases this will
be a matrix) for each code.

2.2.8.3 Decoding function


function faccombination = decode(codes, fac)
%function faccombination = decode(codes, fac)
%decodes codes generated with encode.m
%
%Jens.Schwarzbach@unitn.it, 20060627
%
%example call:
% decode(1:24, [2, 3, 4])
%
codes = codes - 1;
for i = 1:length(codes)

24
The ASF-Programmer's guide

acode = codes(i);
for factor = size(fac, 2):-1:1
v(i, factor) = fix(acode/prod(fac(1:factor-1)));
acode = acode - v(i, factor)*prod(fac(1:factor-1));
end
end
faccombination = fliplr(v);

2.2.8.4 Encoding function


function codes = encode(faccombinations, factorsandlevels)
%function codes = encode(faccombination, factorsandlevels)
%Suppose you have a 2 by 4 by 2 design with the first factor changing
slowest
%and the last factor changing fastest.
%This yields 16 conditions (2*4*2)
%if levels start counting from 0 %then level 1 3 1 is the highest
%
%encoding gives unique codes that can be used for EEG triggers or
efficient coding
%use decode.m to retrieve factorial combinations from a code
%Jens.Schwarzbach@unitn.it, 20060627
%
%SEE ALSO: decode
%example call
%encode([1 3 1 ], [2 4 2])
%
% >> encode([0 0 0 ], [2 4 2]) -> 1
% >> encode([0 0 1 ], [2 4 2]) -> 2
% >> encode([0 1 0 ], [2 4 2]) -> 3
% >> encode([0 1 1 ], [2 4 2]) -> 4
%...
% >> encode([1 3 0 ], [2 4 2]) -> 15
% >> encode([1 3 1 ], [2 4 2]) -> 16
for f = 1:size(factorsandlevels, 2)
facvalue(size(factorsandlevels, 2) - f + 1) =
prod(factorsandlevels(size(factorsandlevels, 2) - f + 1:end));
end
for i = size(faccombinations, 1)
thisfaccombination = faccombinations(i, :);
codes(i) = thisfaccombination(end);
for factor = size(thisfaccombination, 2)-1:-1:1
codes(i) = codes(i) +
thisfaccombination(factor)*facvalue(factor+1);
end
end
codes = codes + 1; %ADD ONE TO AVOID THAT CODES START WITH 0; BETTER
FOR EEG TRIGGERS

25
Release Notes

3 Release Notes
%20070620 ADDED VERSION ENTRY TO Cfg
%20070620 REMOVED "WaitSecs(0.001);" IN WaitForMousePress FUNCTION
%20070622 ADDED VoiceKey functionality
%20070622 ADDED TRIGGER OUTPUT FOR MEG/EEG (requires data
acquisition toolbox)
%20070624 ADDED NONDESTRUCTIVE FLIPPING
%20070710 ADDED SYNCHRONIZATION TO EXTERNAL TRIGGERS
%20070906 ADDED GRACEFUL EXIT WHEN STM or STIMDEF FILES ARE NOT
FOUND
%20070906 ADDED TRIAL ONSET TIMES ARE NOW CODED IN THE SECOND
COLUMN OF STM FILES
% USER CAN DECIDE WHETHER TO USE OR IGNORE THEM BY
% SETTING Cfg.useTrialOnsetTimes FLAG
%20070906 ADDED TRIAL BY TRIAL FEEDBACK: Cfg.feedbackTrialCorrect,
Cfg.feedbackTrialError
%20070906 ADDED GRACEFUL EXIT WHEN PRESSING THE q BUTTON REPEATEDLY
%20070930 ADDED READ TEXT AND SOUND STIMULI
%20071010 FIXED REMOVED ERROR THAT OCCURRED WHEN NO DATA
ACQUISITION TOOLBOX WAS INSTALLED
%20071103 FIXED INCREASED MEMORY EFFICIENCY (ALTHOUGH STILL ROOM
FOR
% IMPROVEMENTS)
%20071128 CHANGED PTB_Init does not return rect directly any more,
the screen rect is now Cfg.Screen.rect
%20071202 CHANGED starting to adjust all variable names according to
mixedCase convention.
% This means, that variables start lower case and
each new word with upper case.
% BUT: structures start with upper case, e.g. Cfg,
Cfg.Screen etc.
% Example: cfg.UseBackBuffer became Cfg.useBackBuffer
% THIS WILL AFFECT PLUGINS WRITTEN BY USERS BASED ON
% PREVIOUS TEMPLATES
%20071203 ADDED KEYBOARD as possible response device
%20071203 ADDED FEEDBACK: COMMAND WINDOW SHOWS RT AND KEY FOR EACH
TRIAL

3.1 Adapting your code


Many changes have been applied to this first official release. An important one is that all ASF-functions
(should) follow a unified naming convention “ASF_doThisAndThat.m”. This is important to people who
either program ASF-plugins or who use some ASF-functions in their own code. For example
“ASFWaitForResponse.m” has been renamed to “ASF_waitForResponse.m”. If you have written many
plugins, they will all not work and you have to change them all. Here is a good way to do that. Install
notepad++ (http://sourceforge.net/projects/notepad-plus/) on your computer, open a file in your projects
directory, click on the looking glass (or go to Search -> Replace).

26
Release Notes

Provide the correct


path, e.g. a path that
is on top of all your
projects

Figure 6: Replacing function names in


all your programs. Maybe try “FindAll”
before applying “Replace in Files”.

27
Release Notes

Index
Cfg.feedbackTrialCorrect ..................... 5 Cfg.userDefinedTRDcolumns .............. 5
Cfg.feedbackTrialError ......................... 5 Cfg.userSuppliedTrialFunction ............. 5
Cfg.issueTriggers .................................. 4 Cfg.useTrialOnsetTimes ....................... 4
Cfg.onlineFeedback .............................. 5 Cfg.waitUntilResponseAfterTrial ......... 4
Cfg.plotVOT ......................................... 4 dual-screen ............................................ 3
Cfg.randomizeTrials ............................. 5 event-related fMRI ................................ 4
Cfg.responseTerminatesTrial ................ 4 Matlab data acquisition toolbox ............ 4
Cfg.Screen.rect ...................................... 3 primary display ..................................... 3
Cfg.synchToScanner ............................. 4 secondary display .................................. 3
Cfg.SynchToScannerPort...................... 4 ShowTrial() ........................................... 5
Cfg.useBackBuffer................................ 3 temporal jittering of trials ..................... 4
cfg.userDefinedTRDcolumns ............... 5

28

You might also like