Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
667 views4 pages

Psychtoolbox Drawing & Experiment

A document containing some examples around Matlab/psychtoolbox and do common stuff like opening a Screen or creating an experimental data collection loop.

Uploaded by

eniinegag54423
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
667 views4 pages

Psychtoolbox Drawing & Experiment

A document containing some examples around Matlab/psychtoolbox and do common stuff like opening a Screen or creating an experimental data collection loop.

Uploaded by

eniinegag54423
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 4

% ScreenExamples.

m
%
% opens a window using psychtoolbox,
% shows simple examples of usage of a number of drawing commans
%
% Of note comments are intentially left out so that students can see
an
% example of a command that works but will still have to go through a
% process of discovery to master them.
%
% written for Psychtoolbox 3 by Aaron Seitz 1/2012
[window, rect]=Screen('OpenWindow',0);
dur=1;
Screen('FrameOval',window,[127],[200 200 400 400])
Screen('Flip',window)
WaitSecs(dur)
Screen('FillOval',window,[127],[200 200 400 400])
Screen('Flip',window)
WaitSecs(dur)
Screen('FrameRect',window,[127],[200 200 400 400])
Screen('Flip',window)
WaitSecs(dur)
Screen('FillRect',window,[127],[200 200 400 400])
Screen('Flip',window)
WaitSecs(dur)
Screen('DrawLine',window,[127],200,200, 400, 400)
Screen('Flip',window)
WaitSecs(dur)
Screen('DrawLines',window,[200 300 300 400 400 500; 300 300 400 400
500 600],2, [255 8 89])
Screen('Flip',window)
WaitSecs(dur)
Screen('DrawArc',window,[127],[200 200 400 400],23,200)
Screen('Flip',window)
WaitSecs(dur)
Screen('FillArc',window,[127],[200 200 400 400],23,56)
Screen('Flip',window)
WaitSecs(dur)
Screen('FillPoly',window,rand(3,1)*255,[200 300 300 400 400 500; 300
300 400 400 500 600]')
Screen('Flip',window)
WaitSecs(dur)
Screen('FramePoly',window,rand(3,1)*255,[200 300 300 400 400 500; 300
300 400 400 500 600]')

Screen('Flip',window)
WaitSecs(dur)
% Note with text there are a lot of formatting options!
Screen('TextFont',window, 'Courier');
Screen('TextSize',window, 30);
Screen('TextStyle', window, 0);
Screen('DrawText', window, 'Here is one way to draw text', 100, 300,
rand(3,1)*255);
DrawFormattedText(window,'Here is another','center','center',[255 0
255]);
Screen('Flip',window)
WaitSecs(dur)
%Note with Textures you need to first make them and then draw them.
IM1=rand(100,100,3)*255;
IM2= imread('T.png', 'png');
tex(1) = Screen('MakeTexture', window, IM1);
tex(2) = Screen('MakeTexture', window, IM2);
Screen('DrawTextures', window, tex([1 2 1 2]), [], [100 100
400 400; 400 350 550 500; 600 600 800 800; 100 500 200 550]',
rand(4,1)*360);
Screen('DrawTexture', window, tex(2), []);
Screen('Flip',window)
WaitSecs(dur)
Screen('CloseAll');

%
%
%
%
%
%
%
%
%

SampleExperiment.m
,
shows a simple experiment, press a key whenever you see or hear a
cow...instructions to the subject are an excercise to the user ;-).
runs a staircase
written for Psychtoolbox 3

by Aaron Seitz 1/2012

%% Example Experiment
% Gets subject Info sets up experiment
prompt = {'Enter subject number:'}; %description of fields
defaults = {''};%you can put in default responses
answer = inputdlg(prompt, 'Subject Number',1.2,defaults); %opens
dialog
SUBJECT = answer{1,:}; %Gets Subject Name

c = clock; %Current date and time as date vector. [year month day hour
minute seconds]
baseName=[SUBJECT '_DemoExp_' num2str(c(2)) '_' num2str(c(3)) '_'
num2str(c(4)) '_' num2str(c(5))]; %makes unique filename
rand('seed',GetSecs); %sets randseed
% Opens Sets up Psychtoolbox
[window, rect]=Screen('OpenWindow',0); % open screen
FlipInt=Screen('GetFlipInterval',window); %Gets Flip Interval
ListenChar(2); %makes it so characters typed don?t show up in the
command window
HideCursor(); %hides the cursor
KbName('UnifyKeyNames'); %used for cross-platform compatibility of
keynaming
KbQueueCreate; %creates cue using defaults
KbQueueStart; %starts the cue
[wavedata freq ] = wavread('./cow.wav'); % load sound file
TheSnd=[wavedata wavedata] ;
InitializePsychSound(1); %inidializes sound driver...the 1 pushes for
low latency
pahandle = PsychPortAudio('Open', [], [], 2, freq, 2, 0); % opens
sound buffer...requests high-precision timing and stereo
vbl=Screen('Flip',window); %gets a good basetime
%staircase parameters
numdown=3; %number of corrent items in a row to go down.
stepsize=-.01; %step size
thresh=.3; %starting point of staircase
CorCounter=0;
for trial=1:40 %runs through trials
starttime=vbl +round((3*rand + 1)/FlipInt)*FlipInt %jitters
prestim interval between 1 and 3.5 and rounds to flip intervals
PsychPortAudio('FillBuffer', pahandle, thresh*TheSnd'); % loads
data into buffer
PsychPortAudio('Start', pahandle,1,inf); %starts sound at infinity
PsychPortAudio('RescheduleStart', pahandle, starttime, 0)
%reschedules startime to
vbl=Screen('Flip',window,starttime-FlipInt/2); %swaps backbuffer
to frontbuffer
KbQueueFlush; %Flushes Buffer so only response after stimonset are
recorded
Waitsecs(.5); %gives .5 secs for a response
if KbQueueCheck
CorCounter=
CorCounter+1;
else
CorCounter=0
end
threshhist(trial)=thresh;
if CorCounter>=numdown
thresh=thresh+stepsize;

else
thresh=thresh-stepsize;
end
thresh=max(thresh,0); %makes sure values don't go negative
thresh=min(thresh,1);
%makes sure values don't go above 1
save(baseName) % saves everything in the workspace
end
ListenChar(0); %makes it so characters typed do show up in the command
window
ShowCursor(); %shows the cursor
Screen('CloseAll'); %Closes Screen
Priority(0); %resets priority
KbQueueRelease; %releases keyboard cue
ListenChar(0); %makes it so characters typed do show up in the command
window
PsychPortAudio('Close'); %close audiobuffer

You might also like