Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
%_______________________________________________________________________
%
% Run random dot motion experiment defined in createDotInfo
%_______________________________________________________________________
%
% Input
%
% dotInfo | experiment configuration (struct)
% subj | identifier of subject (string)
% condSet | conditions (cell array of strings)
%_______________________________________________________________________
%
function dotsExperiment_JQK_170327(dotInfo, subj, test, DEBUG, opacity)
%%
%% sanitize function parameters
%%
if nargin == 0
eval('help dotsExperiment')
return
end
if not(exist('dotInfo','var'))
error('Missing input: dotInfo')
elseif isempty(dotInfo) || not(isstruct(dotInfo))
error('Invalid input: dotInfo (requires non-empty struct)')
end
if not(exist('subj','var'))
error('Missing input: subj')
elseif not(isempty(subj)) && ischar(subj)
dotInfo.subj = subj;
else
error('Invalid input: subj (requires non-empty string)')
end
% if not(exist('condSet','var'))
% error('Missing input: condSet')
% elseif not(isempty(condSet)) && iscellstr(condSet) && min(cellfun(@length, condSet)) > 0
% dotInfo.condSet = condSet;
% else
% error('Invalid input: condSet (requires cell array of non-empty strings)')
% end
if not(isfield(dotInfo,'deployed'))
dotInfo.deployed = true;
end
%%
%% for saving behavioural data
%%
sessionFile = ['dotsX_behav_' subj '_' datestr(now, 'dd-mm-yyyy_HH-MM')];
sessionFile = [dotInfo.dataDir, sessionFile, '.mat'];
%%
%% prepare presentation
%%
displayList = Screen('screens');
displayIdx = displayList(1);
KbName('UnifyKeyNames'); % use portable key naming scheme
oldVerbosityLevel = Screen('Preference', 'Verbosity', 2); % show errors and warnings
arrowKeys = [dotInfo.keyLeft dotInfo.keyRight];
baseDotInfo = dotInfo; % keep for saving later
if DEBUG == 1
Screen('Preference', 'SkipSyncTests', 1);
PsychDebugWindowConfiguration(0, opacity);
else
clear Screen; %PsychDebugWindowConfiguration([], 1);
end;
try
%%
%% prepare canvas
%%
screenInfo = openExperiment(50,50,displayIdx); clc; % open drawing canvas
if numel(Screen('screens')) == 1 || dotInfo.deployed
HideCursor(screenInfo.curWindow);
end
Screen('TextFont', screenInfo.curWindow, 'Helvetica');
Screen('TextSize', screenInfo.curWindow, 20);
Screen('TextStyle', screenInfo.curWindow, 0); % regular
Screen('TextColor', screenInfo.curWindow, 255); % white
% show intro only if not in debug mode
if isfield(dotInfo, 'introNumTrial') && test == 1
exitSession = dotsIntroduction(dotInfo, screenInfo);
else
exitSession = false;
end
if exitSession
closeExperiment;
return
end
sessStartTime = GetSecs;
ResultMat = NaN(dotInfo.totalTrials,4);
ExperimentProtocol = cell(0);
ExperimentProtocol = [ExperimentProtocol; {'SessionOnset'}, {sessStartTime}, {[]}, {[]}, {[]},{NaN}];
%%
%% block start
%%
% have the subject get ready for the next condition
DrawFormattedText(screenInfo.curWindow, 'ready?', 'center', 'center');
Screen('Flip', screenInfo.curWindow);
% wait for experimenter to resume session
while true
[exitSession, resumeSession] = checkKeys(dotInfo);
if resumeSession
break
elseif exitSession
closeExperiment;
return
end
end
for indTrial = 1:dotInfo.totalTrials
%fprintf(' (%i/%i)\n\n', indCond, dotInfo.contrastBlocks)
TrialInitiation = GetSecs;
ExperimentProtocol = [ExperimentProtocol; {'TrialInitiation'}, {TrialInitiation}, {[]}, {[]}, {[]}, {indTrial}];
% create fixation
targets = makeDotTargets(screenInfo, dotInfo); % initialize targets
showTargets(screenInfo, targets, 1);
[~, dotInfo, ExperimentProtocol,ResultMat] = dotsX_JQK_MAT_170327(screenInfo, dotInfo, targets, indTrial, ExperimentProtocol,ResultMat);
% % take a break after every block except after the last block
% if ~(indCond == dotInfo.contrastBlocks)
% PauseStart = GetSecs();
% ExperimentProtocol = [ExperimentProtocol; {'PauseStart'}, {PauseStart}, {[]}, {[]}, {[]}, {[]}, {[]},{[]}];
% while (GetSecs()-PauseStart) < dotInfo.breakTime
% % have the subject get ready for the next condition
% pause(.1);
% remain = dotInfo.breakTime-round(GetSecs - PauseStart,0);
% DrawFormattedText(screenInfo.curWindow, ['Pause: continue in ',num2str(remain),' s'], 'center', 'center');
% Screen('Flip', screenInfo.curWindow);
% end
% end
save(sessionFile, 'ExperimentProtocol', 'dotInfo','ResultMat');
end % block
sessEndTime = GetSecs;
ExperimentProtocol = [ExperimentProtocol; {'SessionEnd'}, {sessEndTime}, {[]}, {[]}, {[]}, {indTrial}];
save(sessionFile, 'ExperimentProtocol', 'dotInfo', 'ResultMat');
% % wait for a short moment before showing task complete message
% outroStartTime = GetSecs;
% waitTime = 1;
% while true
% % exit wait loop when time delay is met
% if GetSecs - outroStartTime >= waitTime
% break
% end
%
% % stop experiment if exit key is pressed
% exitSession = checkKeys(dotInfo);
% if exitSession
% fprintf('\n')
% closeExperiment;
% return
% end
% end
% inform the subject that the experiment is over
DrawFormattedText(screenInfo.curWindow, 'task complete!', 'center', 'center');
Screen('Flip', screenInfo.curWindow);
% sessTime = GetSecs - sessStartTime;
% meanFixTime = mean([trialData.fixTime]);
% numCorrect = numel(find([trialData.correct]));
% numTrial = numel([trialData.correct]);
% numResponded = numel(find(~isnan([trialData.rxtime])));
%
% fprintf('\nTotal Time: %.2f\n', sessTime) % incl. block startup waits
% fprintf('Average fixation: %.2fs\n', meanFixTime)
% fprintf('Responded: %i/%i\n', numResponded, numTrial)
% fprintf('Correct: %i/%i\n', numCorrect, numTrial)
% fprintf('Accuracy: %.1f\n', 100*numCorrect/numResponded)
% wait for experimenter to close screen
while true
[exitKeyPressed, resumeKeyPressed] = checkKeys(dotInfo);
if exitKeyPressed || resumeKeyPressed
break
end
end
catch exception
getReport(exception) % show stack trace
end
closeExperiment; % close drawing canvas
Screen('Preference', 'Verbosity', oldVerbosityLevel); % restore verbosity
end