WhynHowPsychT

Download Report

Transcript WhynHowPsychT

Psychtoolbox: An introduction

Sheraz Khan, PhD TRANSCEND Research, TAL Kenet Group Fellow, MGH 1

OUTLINE

• Introduction to Psychtoolbox.

• Psychtoolbox by Simple Examples • Psychtoolbox in practice at Martinos center.

2

Introduction to Psychtoolbox

• PsychToolbox is a collection of matlab functions written to make presenting visual stimuli easier. Remember to cite the Toolbox. "We wrote our experiments in MATLAB, using the Psychophysics Toolbox extensions (Brainard, 1997; Pelli, 1997)." • Psychtoolbox is widely used in visual psychophysics and there is a lot of documentation and knowledge around.

http://psychtoolbox.org

• MAC and Windows version available, MAC version has better control over hardware.

3

Introduction to PsychToolbox

• Installation >> cd ~/Desktop >> DownloadPsychtoolbox('current') • To get help >>Screen OpenWindow?

>>Screen DrawText?

• If screen freezes ctrl-c % will stop execution clear Screen % garbage collector of Screen Cmd + option +escape % Ultimate 4

Why use PsychToolbox ?

• PsychToolbox is very strict about timing, so if accurate timing is important in your experiment PsychToolbox is good for that.

• Because PsychToolbox using graphics acceleration you can use very fast drawing without any pixelation and other image processing artefacts • Lots of people in the world use it so it's easy to get help, and more importantly its FREE.

5

Programming simple Stimuli

% Testing PsychToolbox

>> ScreenTest ***** ScreenTest: Testing Screen 0 ***** PTB-INFO: This is the OpenGL-Psychtoolbox version 3.0.8. Type 'PsychtoolboxVersion' for more detailed version information.

PTB-INFO: Psychtoolbox is licensed to you under terms of the GNU General Public License (GPL). See file 'License.txt' in the PTB-INFO: Psychtoolbox root folder for a copy of the GPL license.

PTB-INFO: OpenGL-Renderer is NVIDIA Corporation :: GeForce Go 7400/PCI/SSE2 :: 2.0.1

PTB-Info: VBL startline = 768 , VBL Endline = -1 TB-Info: Measured monitor refresh interval from VBLsync = 16.712593 ms [59.835118 Hz]. (50 valid samples taken, stddev=0.044112 ms.) PTB-Info: Reported monitor refresh interval from operating system = 16.666667 ms [60.000000 Hz].

PTB-Info: Small deviations between reported values are normal and no reason to worry.

PTB-INFO: Using NVidia's GL_TEXTURE_RECTANGLE_NV extension for efficient high-performance texture mapping...

***** ScreenTest: Done With Screen 0 ***** 6

Programming simple Stimuli

% Initializing the program

>>screenNum=1; % Screen 0 is Laptop, Screen 1 will be projector >>flipSpd=13; % a flip every 13 frames

% Opening Window on Screen, we want to used

>>[wPtr,rect]=Screen('OpenWindow',screenNum); % wPtr pointer to the screen.

% Getting Screen refresh rate

>>monitorFlipInterval=Screen('GetFlipInterval', wPtr); % 1/ monitorFlipInterval is the frame rate of the projector 7

Programming Simple Stimuli

% Finding Black and white

>>black=BlackIndex(wPtr); >>white=WhiteIndex(wPtr);

% Filling the screen with Black and wait

>>Screen('FillRect',wPtr,black); >>Screen(wPtr, 'Flip'); >>WaitSecs(2); 8

Programming Simple Stimuli

% make a rectangle in the middle of the screen flip colors and size

% Fill the screen with Black

>>Screen('FillRect',wPtr,black); >>vbl=Screen(wPtr, 'Flip'); % collect the time for the first flip with vbl

% Make a rectangle in the middle of the screen flip colors and size

for i=1:10 Screen('FillRect',wPtr,[0 0 255], [100 150 200 250]); vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval)); % flip 13 frames after vbl Screen('FillRect',wPtr,[255 0 0], [100 150 400 450]); vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval)); End % Color; Left, Right, Top, Bottom 9

Programming Simple Stimuli

% Fill the screen with Black

>>Screen('FillRect',wPtr,black); >>vbl=Screen(wPtr, 'Flip');

% Make circles flip colors & size

for i=1:10 Screen('FillOval',wPtr,[0 180 255], [ 500 500 600 600]); vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval)); Screen('FillOval',wPtr,[0 255 0], [ 400 400 900 700]); vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval)); end % Color; Starting Horizontal, Starting Vertical; Ending Horizontal, Ending Vertical 10

Programming Simple Stimuli

% Fill the screen with Black

>>Screen('FillRect',wPtr,black); >>vbl=Screen(wPtr, 'Flip');

% make lines that flip colors size & position

>>for i=1:10 Screen('DrawLine',wPtr,[0 255 255], 500, 200, 700 ,600, 5); vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval)); Screen('DrawLine',wPtr,[255 255 0], 100, 600, 600 ,100, 5); vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval)); >>end % Color; Starting Horizontal, Starting Vertical; Ending Horizontal, Ending Vertical 11

Programming Simple Stimuli

% Fill the screen with Black

>>Screen('FillRect',wPtr,black); >>vbl=Screen(wPtr, 'Flip');

% Texture is the great way of storing Images

>>image2D=255*rand(100, 100); >>textureIndex=Screen('MakeTexture', wPtr, image2D); >>Screen('DrawTexture', wPtr, textureIndex); >>Screen(wPtr, 'Flip'); >>WaitSecs(2); 12

Programming Simple Stimuli

% Fill the screen with Black

>>Screen('FillRect',wPtr,black); >>vbl=Screen(wPtr, 'Flip');

% Initialize the Keyboard input

>>KbName('UnifyKeyNames'); % Unify Max OS X, OS 9 >>[sec keyCode]=KbPressWait; % wait for the key press >>keyCode=find(keyCode~=0);

% Drawing Test

>>Screen('TextSize', wPtr , 150);% font size >>Screen('DrawText', wPtr, num2str(keyCode), 200, 20, [255 50 255]); >>vbl=Screen(wPtr, 'Flip'); % Starting Horizontal vertical position >>WaitSecs(2); 13

Programming Simple Stimuli

% Fill the screen with Black

>>Screen('FillRect',wPtr,black); >>vbl=Screen(wPtr, 'Flip');

% Combining the stimuli

>>for i=1:10 Screen('FillRect',wPtr,[0 0 255], [100 150 200 250]); Screen('DrawLine',wPtr,[0 255 255], 500, 200, 700 ,600, 5); Screen('FillOval',wPtr,[0 180 255], [ 500 500 600 600]); Screen('TextSize', wPtr , 150); Screen('DrawText', wPtr, 'FUNKY!!', 200, 20, [255 50 255]); vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval)); >>end 14

Programming Real Stimuli

Local Connectivity in the visual cortex: From Polat and Norcia (Polat and Norcia, 1996),

who discovered the paradigm (Polat and Sagi, 1993), and were the first to investigate it using VEPs. They showed that responses to

b

and

d

deviated from the linear sum of responses to (

a+c

) and (

e+c

) respectively, the difference being attributable to local connectivity.

15

Programming Real Stimuli

Specifications:

Size of the objects: Size of the Gabors, visual separation between them

Size of the Screen Distance from the Screen

L, 55 cm D, 120 cm H, 41 cm 16

•

Programming Real Stimuli

Normally in visual stimuli things are described in visual angle, so what it is ?

Size is 1 degree, separation is 3 degrees Width=tand(1)*D, Width in screen percent=(Size/L)*100 Separation=tand(3)*D, Separation in screen percent=(Separation)/H*100 17

Programming Real Stimuli

% Setting Parameters

>> nTrials = 40; >>soa = 1.5; % Stimulus-Onset Asynchrony (SOA) >>displayTime = 0.3; >>WidthOfGrid=4.88; >>gratingMatrix=Gabors; jitter = 0.1; Separation=20.25;

% Location of three gabors

>>L1=[50 50]; L2=[50 50-Separation]; L3=[50 50+Separation];

% Configuring triggers

>>di = DaqDeviceIndex; >>DaqDConfigPort(di,0,0); >>DaqDOut(di,0,0); 18

Programming Real Stimuli

% Setting Screen

>>whichScreen = max(Screen('Screens')); >>rect=Screen(whichScreen,'Rect'); % Gets Screen dimensions >>HideCursor; >>window = Screen('OpenWindow', whichScreen);

% Color Setup

% Retrieves color codes for black and white and gray.

>>black = BlackIndex(window); >>white = WhiteIndex(window); >>gray = (black + white) / 2; % Computes the color code for gray.

19

Programming Real Stimuli

% Giving Instruction to Subject

Screen('FillRect',window,gray); Screen(window,'TextSize',txtSz); Screen(window,'DrawText','Remember to keep your eyes',rect(3)/4,rect(4)/2-50); Screen(window,'DrawText','on the + at the center',rect(3)/3.3,rect(4)/2); Screen('Flip',window);

% Click to proceed

GetClick;

% Putting Cross in the center

Screen('FillRect',window,gray); Screen(window,'TextFont',centerFont); Screen(window,'TextSize',centerTxtSz); Screen(window,'DrawText',centerChar,rect(3)/2,rect(4)/2,centerColour); Screen('Flip',window); 20

Programming Real Stimuli

[sourceRect targetRect]=rectGeneration(location,WidthOfGrid,rect) % Decoding percent to actual screen

WidthOfGrid=round(max(rect)*WidthOfGrid/100); halfWidthOfTgt=WidthOfGrid/2;

% sourceRect:: image area

sourceRect = [1 1 widthOfGrid widthOfGrid];

% targetRect :: Actual Screen place and size

locationl = round(rect(3)*location(1)/100 - halfWidthOfTgt); locationt = round(rect(4)*location(2)/100 - halfWidthOfTgt); locationr = round(rect(3)*location(1)/100 + halfWidthOfTgt); locationb = round(rect(4)*location(2)/100 + halfWidthOfTgt); targetRect = [locationl locationt locationr locationb]; 21

Programming Real Stimuli

% Putting Three gabors on the Screen

[sourceRect targetRect]=rectGeneration(L1,WidthOfGrid,rect); tex = Screen('MakeTexture',window,ceil((gray+gratingMatrix))); Screen('DrawTextures', window, tex,sourceRect,targetRect); [sourceRect targetRect]=rectGeneration(L2,WidthOfGrid,rect); texu = Screen('MakeTexture',window,ceil((gray+gratingMatrix))); Screen('DrawTextures', window, texu,sourceRect,targetRect,90); [sourceRect targetRect]=rectGeneration(L3,WidthOfGrid,rect); texd = Screen('MakeTexture',window,ceil((gray+gratingMatrix))); Screen('DrawTextures', window, texd,sourceRect,targetRect,90); Screen('Flip', window); 22

Programming Real Stimuli

% Sending triggers

DaqDOut(di,0,4); %send trigger DaqDOut(di,0,0); %clear trig 23

Conclusion

• All the source code for this talk is available on why n how wiki.

• Best way to learn Pschytoolbox is to use it on the projector.

• Always test the timing of your protocol.

• Photo diode and oscilloscope is available in MEG.

24

Thank you.

25