T-75.4950 Psychophysics Toolbox (PTB)

T-75.4950
Psychophysics Toolbox (PTB)
Jussi Hakala
[email protected]
27.1.2014
Demo 1: Frame animation
• Using the functions introduced later, we build a function
that illustrates the effect of Gaussian low pass filtering in
a 25fps frame animation
• The user can pause and continue the animation again
with the keys ‘p’ an ‘c’
• frameAnimationDemo.m
T-75.4950
27.1.2014
Demo 2: Staircase algorithm
• Experiment loosely based on the paper:
Risto Näsänen, Helena Ojanpää, Effect of image contrast and
sharpness on visual search for computer icons, Displays, Volume
24, Issue 3, October 2003, Pages 137-144
Available at http://www.sciencedirect.com/science/article/B6V0149M0C0P-1/2/44e38f7b3d5696ea99ff4c406e3c66e1
• staircaseDemo.m
T-75.4950
27.1.2014
Demo 2: Data
• Threshold easy to find by calculating the mean of the
intensities at reversal points
T-75.4950
27.1.2014
Demo 3: The psychometric curve
•
•
•
Data from an experiment using the method of constant stimuli and a 2alternative forced choice task
Aim
– plot the psychometric curve
– calculate the threshold
Procedure
– Fit a Weibull curve to the data
– Solve the Weibull from 1) at our chosen threshold probability
– Plot our data and the Weibull curve
• fitWeibullToTAFC.m
T-75.4950
27.1.2014
Demo 3: The psychometric curve
• For more sophisticated analyses: Palamedes
(http://www.palamedestoolbox.org/)
T-75.4950
27.1.2014
Background
• Psychophysical experiments require accurate stimulus presentation
that can usually be achieved only by lower level programming
languages such as C
• Using higher level interpreted languages (such as Matlab’s), is
attractive because of fast development time and ease of use
• Enter Psychophysics Toolbox
•
Brainard, D. H. (1997) The Psychophysics Toolbox, Spatial Vision 10:433-436
•
Pelli, D. G. (1997) The VideoToolbox software for visual psychophysics: Transforming numbers
into movies, Spatial Vision 10:437-442
•
Kleiner M, Brainard D, Pelli D, 2007, "What's new in Psychtoolbox-3?" Perception 36 ECVP
T-75.4950
27.1.2014
System requirements
•
•
•
•
•
Runs on Linux, OSX and Windows
Limited support for Matlab and Octave under Ubuntu
Matlab R2007a or later OR Octave 3.2 or later
Graphics adapter with OpenGL support
For accurate timing: a CRT display
• Do not expect 100% cross platform compatibility of your
PTB scripts!
•
http://psychtoolbox.org/SystemRequirements
T-75.4950
27.1.2014
Available in classroom TUAS 1174
• To use, run SetupPsychtoolbox in Matlab:
> cd C:\Programs\Matlab\toolbox\Psychtoolbox
> SetupPsychtoolbox
T-75.4950
27.1.2014
What can you do with it?
•
Provides the researcher with the ability to accurately draw on the display (within
the limits of the system)
–
•
•
•
•
Temporal, spatial and colour accuracy
Stimuli is produced with Matlab functions (e.g. Image Processing Toolbox)
Assists in collecting data
Alternative: PsychoPy (Psychology software in Python)
Commercial alternatives: SuperLab, Presentation, e-Prime
Pros
Cons
“Complete” freedom
No built-in experimental methods
Community support (free code)
No built-in stimuli (except Gabor patches)
Open source
No GUI
T-75.4950
27.1.2014
Basic use case
• Basic structure of visual stimulus presentation with
Psychophysics Toolbox:
1. Prepare stimulus (often Matlab matrices)
2. Open an onscreen window (OpenWindow)
3. Make a texture of your stimulus (either with DrawTexture or
primitive drawing functions like FillRect)
4. Flip your stimulus from the back buffer into the front buffer
with Flip
5. Hide the stimulus and get user response
6. Modify/choose the next stimulus and loop 1-6 until a
condition is satisfied
T-75.4950
27.1.2014
Screen
• Screen(‘OpenWindow’…
[windowPtr,rect] = Screen('OpenWindow’,windowPtrOrScreenNumber
[,color][,rect][,pixelSize][,numberOfBuffers][,stereomode][,multisamp
le][,imagingmode]);
• A simple use case where we open a full screen window in
screen 0 (primary screen) with a grey background and store
the pointer to that window in stimulus_window:
stimulus_window = Screen('OpenWindow', 0, 192);
T-75.4950
27.1.2014
Screen
• Screen(‘MakeTexture’…
textureIndex = Screen('MakeTexture', WindowIndex, imageMatrix
[,optimizeForDrawAngle=0] [,specialFlags=0] [,floatprecision=0]
[,textureOrientation=0] [,textureShader=0]);
• A simple use case where we create a texture of imagematrix
that is ready to be drawn at any time on stimulus_window and
stores the index into texture:
texture = Screen('MakeTexture', stimulus_window, imagematrix);
T-75.4950
27.1.2014
Screen
• Screen(‘Flip’…
[VBLTimestamp StimulusOnsetTime FlipTimestamp Missed Beampos] =
Screen('Flip', windowPtr
[,when] [,dontclear] [,dontsync] [,multiflip]);
• This flips our predrawn (!) texture from the back buffer into
the front buffer and stores the timestamp of the beginning of
the vertical blanking buffer swap to VBLtime:
VBLtime = Screen('Flip', stimulus_window);
T-75.4950
27.1.2014
Screen
• Screen(‘Flip’… part II
• In order to create an animation we draw our next
texture into the back buffer in each pass, and then flip it
after a 1/25 second interval from the previous VBLtime,
and store the new time stamp into VBLtime
Screen('DrawTexture', stimulus_window, texture(i));
VBLtime = Screen('Flip', stimulus_window, VBLtime + (1/25));
T-75.4950
27.1.2014
Screen
• You need to close all windows and textures that you open!
• Screen(‘Close’/’CloseAll’…
Screen('Close', [windowOrTextureIndex or list of
textureIndices/offscreenWindowIndices])
Screen('CloseAll');
• Close all textures and windows:
Screen('CloseAll');
T-75.4950
27.1.2014
KbCheck, KbName
[keyIsDown, secs, keyCode, deltaSecs] = KbCheck([deviceNumber])
[kbNameResult] = KbName(keyCode)
• We check if any key is pressed and decode the
response into a character
[keyIsDown, secs, keyCode] = KbCheck();
key_pressed = KbName(keyCode); %for example ‘y’
T-75.4950
27.1.2014
try… catch, @
• Use try…catch statements, and use the catch block to
close your windows and textures, otherwise the opened
window will stay open (in the unlikely event that your
code fails)
• If your program hangs or you want to terminate it
prematurely you can use the @ (AltGr + 2) to kill your
PTB function (at least you can try, of course you should
also try ctrl-c).
T-75.4950
27.1.2014
Advanced features
• OpenGL image processing and graphics
• Support for many kinds of hardware including special
displays, joysticks, eye trackers, Kinect …
• Quest threshold estimation (Quest toolbox is included)
• Optics calculations
• Probability functions
• Everything needed for experiments in psychophysics,
and more!
T-75.4950
27.1.2014
Documentation
•
•
•
•
•
Type ‘help PsychBasic’ in Matlab to get started
Continue with ‘help PsychDemos’
Function reference: http://docs.psychtoolbox.org/Psychtoolbox
FAQ: http://psychtoolbox.org/PsychtoolboxFaq
User forum in Yahoo Groups:
http://tech.groups.yahoo.com/group/psychtoolbox/messages/
T-75.4950
27.1.2014
Some last year’s experiments
•
•
•
•
•
Perception of unnaturalness in walking patterns
Meditation and change blindness
The effect of first reflections on perceived audio quality
Logo grouping and visual search
Effectiveness of different highlighting methods on a map
• What do you want to do?
T-75.4950
27.1.2014