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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
function Stroop_170907(setup, expInfo)
% 170904 JQK | adapted from http://peterscarfe.com/stroopdemo.html
% | merged with parts of BasicSoundInputDemo for audio recording
% | removed parts related to RT encoding by button press
% 170904 JQK | added EEG triggers
%% create individual directory
StroopPath = [setup.subjectsPath, 'Stroop/']; mkdir(StroopPath);
%% set Stroop parameters
expInfo.Stroop.durITI = 1;
expInfo.Stroop.durResp = 2;
%% startup PTB
% Setup PTB with some default values
PsychDefaultSetup(2);
% Perform basic initialization of the sound driver:
InitializePsychSound;
% Open the default audio device [], with mode 2 (== Only audio capture),
% and a required latencyclass of zero 0 == no low-latency mode, as well as
% a frequency of 44100 Hz and 2 sound channels for stereo capture.
% This returns a handle to the audio device:
freq = 44100;
pahandle = PsychPortAudio('Open', [], 2, 0, freq, 2);
% Preallocate an internal audio recording buffer with a capacity of 5 seconds:
PsychPortAudio('GetAudioData', pahandle, 5);
rng('default');
rng('shuffle');
expInfo.Stroop.seed = rng;
%% for EEG: set up parallel port triggers
if setup.EEG.useEEG
if setup.EEG.DIO.parallelTrigger == 1
daqreset;
rehash toolboxcache
dio = digitalio('parallel');
addline(dio,0:7,0,'out');
end
end
% Set the screen number to the external secondary monitor if there is one
% connected
displayList = Screen('screens');
displayIdx = displayList(setup.disp);
KbName('UnifyKeyNames'); % Make sure keyboard mapping is the same on all supported operating systems
oldVerbosityLevel = Screen('Preference', 'Verbosity', 2); % show errors and warnings
if setup.DEBUG == 1
Screen('Preference', 'SkipSyncTests', 1);
PsychDebugWindowConfiguration(0, setup.opacity);
else
clear Screen; %PsychDebugWindowConfiguration([], 1);
end
% % Define black, white and grey
% white = WhiteIndex(displayIdx);
% grey = white / 2;
% black = BlackIndex(displayIdx);
screenInfo = openExperiment(50,50,displayIdx); clc; % open drawing canvas
if numel(Screen('screens')) == 1
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
ifi = Screen('GetFlipInterval', screenInfo.curWindow); % Query the frame duration
% initiate black background
Screen('FillRect', screenInfo.curWindow, [255/2 255/2 255/2])
% Flip to clear
Screen('Flip', screenInfo.curWindow);
% Query the frame duration
ifi = Screen('GetFlipInterval', screenInfo.curWindow);
% Set the text size
Screen('TextSize', screenInfo.curWindow, 60);
% Query the maximum priority level
topPriorityLevel = MaxPriority(screenInfo.curWindow);
% Get the centre coordinate of the screenInfo.curWindow
[xCenter, yCenter] = RectCenter(screenInfo.screenRect);
% Set the blend funciton for the screen
Screen('BlendFunction', screenInfo.curWindow, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
% Do dummy calls to GetSecs, WaitSecs, KbCheck(-1) to make sure
% they are loaded and ready when we need them - without delays
% in the wrong moment:
KbCheck(-1);
WaitSecs(0.1);
GetSecs;
%----------------------------------------------------------------------
% Timing Information
%----------------------------------------------------------------------
% Interstimulus interval time in seconds and frames
isiTimeSecs = expInfo.Stroop.durITI;
isiTimeFrames = round(isiTimeSecs / ifi);
% Numer of frames to wait before re-drawing
waitframes = 1;
expInfo.Stroop.Timing = [];
%----------------------------------------------------------------------
% Colors in words and RGB
%----------------------------------------------------------------------
% We are going to use three colors for this demo. Red, Green and blue.
expInfo.Stroop.wordList = {'Rot', 'Grn', 'Blau'};
rgbColors = [255 0 0; 0 255 0; 0 0 255];
% Make the matrix which will determine our condition combinations
condMatrixBase = [sort(repmat([1 2 3], 1, 3)); repmat([1 2 3], 1, 3)];
expInfo.Stroop.trialsPerCondition = 9;
% Duplicate the condition matrix to get the full number of trials
condMatrix = repmat(condMatrixBase, 1, expInfo.Stroop.trialsPerCondition);
% Get the size of the matrix
[~, numTrials] = size(condMatrix);
% Randomise the conditions
%shuffler = Shuffle(1:numTrials);
shuffler = randperm(numTrials);
condMatrixShuffled = condMatrix(:, shuffler);
expInfo.Stroop.ColorCondsByTrial = condMatrixShuffled;
expInfo.Stroop.ColorCondsName = {'Row1: word'; 'Row2: color'};
%----------------------------------------------------------------------
% Experimental loop
%----------------------------------------------------------------------
% Animation loop: we loop for the total number of trials
for trial = 1:numTrials
% Word and color number
wordNum = condMatrixShuffled(1, trial);
colorNum = condMatrixShuffled(2, trial);
% The color word and the color it is drawn in
theWord = expInfo.Stroop.wordList(wordNum);
theColor = rgbColors(colorNum, :);
% If this is the first trial we present a start screen and wait for a
% key-press
if trial == 1
DrawFormattedText(screenInfo.curWindow, 'Benennen Sie bitte die Schriftfarbe. \n\n Drcken Sie die rechte Taste, um zu beginnen.',...
'center', 'center', [0 0 0]);
vbl = Screen('Flip', screenInfo.curWindow);
expInfo.Stroop.Timing = [expInfo.Stroop.Timing; {'ExpOnset'}, {vbl}];
if setup.EEG.useEEG
%% send START parallelTrigger
if setup.EEG.DIO.parallelTrigger == 1
% first trigger (1)
putvalue(dio,0); % set to 0 (trigger off); ~20us (undocumented use demo in @dioline\putvalue.m and @digitalio\putvalue.m - args are: uddobj, vals [, lineInds])
WaitSecs(setup.EEG.waitTrigEnc);
setup.EEG.DIO.StartTrigger_1_01 = getvalue(dio); % read out values
putvalue(dio,1); % on
WaitSecs(setup.EEG.waitTrigEnc);
setup.EEG.DIO.StartTrigger_1_11 = getvalue(dio); % read out values
putvalue(dio,0); % off
WaitSecs(setup.EEG.waitTrigEnc);
setup.EEG.DIO.StartTrigger_1_02 = getvalue(dio); % read out values
% second trigger (2)
putvalue(dio,0); % set to 0 (trigger off); ~20us (undocumented use demo in @dioline\putvalue.m and @digitalio\putvalue.m - args are: uddobj, vals [, lineInds])
WaitSecs(setup.EEG.waitTrigEnc);
setup.EEG.DIO.StartTrigger_2_01 = getvalue(dio); % read out values
putvalue(dio,2); % on
WaitSecs(setup.EEG.waitTrigEnc);
setup.EEG.DIO.StartTrigger_2_11 = getvalue(dio); % read out values
putvalue(dio,0); % off
WaitSecs(setup.EEG.waitTrigEnc);
setup.EEG.DIO.StartTrigger_2_02 = getvalue(dio); % read out values
end
end
KbStrokeWait;
end
% Flip again to sync us to the vertical retrace at the same time as
% drawing our fixation point
Screen('DrawDots', screenInfo.curWindow, [xCenter; yCenter], 10, [0 0 0], [], 2);
if trial == 1
flipWhen = 0;
else
flipWhen = StimOnset+expInfo.Stroop.durResp-ifi/2;
end
ITIOnset = Screen('Flip', screenInfo.curWindow, flipWhen);
expInfo.Stroop.Timing = [expInfo.Stroop.Timing; {'FixOnset'}, {ITIOnset}];
if setup.EEG.useEEG
if setup.EEG.DIO.parallelTrigger == 1
% set to off state
putvalue(dio,0);
WaitSecs(setup.EEG.waitTrigEnc);
setup.EEG.DIO.BlockTrigger_16_01(trial,:) = getvalue(dio);
% set to on state
putvalue(dio,16);
WaitSecs(setup.EEG.waitTrigEnc);
setup.EEG.DIO.BlockTrigger_16_11(trial,:) = getvalue(dio);
% set to off state
putvalue(dio,0);
WaitSecs(setup.EEG.waitTrigEnc);
setup.EEG.DIO.BlockTrigger_16_02(trial,:) = getvalue(dio);
end
end
% set Onset for next stimulus
flipWhen = ITIOnset+expInfo.Stroop.durITI-ifi/2;
while GetSecs() < ITIOnset+expInfo.Stroop.durITI-100
pause(.001)
end
if trial ~= 1
% get audio from previous trial
StroopAudio.audio{trial-1} = PsychPortAudio('GetAudioData', pahandle);
PsychPortAudio('Stop', pahandle);
expInfo.Stroop.Timing = [expInfo.Stroop.Timing; {'GetAudio'}, {GetSecs()}];
if setup.EEG.useEEG
if setup.EEG.DIO.parallelTrigger == 1
% set to off state
putvalue(dio,0);
WaitSecs(setup.EEG.waitTrigEnc);
setup.EEG.DIO.BlockTrigger_64_01(trial-1,:) = getvalue(dio);
% set to on state
putvalue(dio,64);
WaitSecs(setup.EEG.waitTrigEnc);
setup.EEG.DIO.BlockTrigger_64_11(trial-1,:) = getvalue(dio);
% set to off state
putvalue(dio,0);
WaitSecs(setup.EEG.waitTrigEnc);
setup.EEG.DIO.BlockTrigger_64_02(trial-1,:) = getvalue(dio);
end
end
AudioEncoded = 1;
end
% start next audio recording at specified time
PsychPortAudio('Start', pahandle, [], flipWhen);
% The person should be asked to respond to either the written word or
% the color the word is written in.
% Present the word, start audio recording.
DrawFormattedText(screenInfo.curWindow, char(theWord), 'center', 'center', theColor);
AudioEncoded = 0;
StimOnset = Screen('Flip', screenInfo.curWindow, flipWhen);
expInfo.Stroop.Timing = [expInfo.Stroop.Timing; {'StroopStart'}, {StimOnset}];
if setup.EEG.useEEG
if setup.EEG.DIO.parallelTrigger == 1
% set to off state
putvalue(dio,0);
WaitSecs(setup.EEG.waitTrigEnc);
setup.EEG.DIO.BlockTrigger_32_01(trial,:) = getvalue(dio);
% set to on state
putvalue(dio,32);
WaitSecs(setup.EEG.waitTrigEnc);
setup.EEG.DIO.BlockTrigger_32_11(trial,:) = getvalue(dio);
% set to off state
putvalue(dio,0);
WaitSecs(setup.EEG.waitTrigEnc);
setup.EEG.DIO.BlockTrigger_32_02(trial,:) = getvalue(dio);
end
end
% We retrieve status once to get access to SampleRate:
if trial == 1
StroopAudio.s = PsychPortAudio('GetStatus', pahandle);
end
end
% record last audio response and exit PTB screen
DrawFormattedText(screenInfo.curWindow, 'Sie haben die Stroop-Aufgabe nun beendet. \n\n Vielen Dank!','center', 'center', [0 0 0]);
vbl = Screen('Flip', screenInfo.curWindow, StimOnset+expInfo.Stroop.durResp-ifi/2);
expInfo.Stroop.Timing = [expInfo.Stroop.Timing; {'EndScreen'}, {vbl}];
while GetSecs() < StimOnset+expInfo.Stroop.durResp+expInfo.Stroop.durITI-100
pause(.001);
end
PsychPortAudio('Stop', pahandle);
StroopAudio.audio{trial} = PsychPortAudio('GetAudioData', pahandle);
expInfo.Stroop.Timing = [expInfo.Stroop.Timing; {'GetAudio'}, {GetSecs()}];
if setup.EEG.useEEG
if setup.EEG.DIO.parallelTrigger == 1
% set to off state
putvalue(dio,0);
WaitSecs(setup.EEG.waitTrigEnc);
setup.EEG.DIO.BlockTrigger_64_01(trial,:) = getvalue(dio);
% set to on state
putvalue(dio,64);
WaitSecs(setup.EEG.waitTrigEnc);
setup.EEG.DIO.BlockTrigger_64_11(trial,:) = getvalue(dio);
% set to off state
putvalue(dio,0);
WaitSecs(setup.EEG.waitTrigEnc);
setup.EEG.DIO.BlockTrigger_64_02(trial,:) = getvalue(dio);
end
end
PsychPortAudio('Close', pahandle);
%% wait for 3 seconds before sending end EEG trigger
pause(3);
if setup.EEG.useEEG
%% send END parallelTrigger
if setup.EEG.DIO.parallelTrigger == 1
% first trigger
% set to off state
putvalue(dio,0);
WaitSecs(setup.EEG.waitTrigEnc);
setup.EEG.DIO.EndTrigger_6_01 = getvalue(dio);
% set to on state
putvalue(dio,6);
WaitSecs(setup.EEG.waitTrigEnc);
setup.EEG.DIO.EndTrigger_6_11 = getvalue(dio);
% set to off state
putvalue(dio,0);
WaitSecs(setup.EEG.waitTrigEnc);
setup.EEG.DIO.EndTrigger_6_02 = getvalue(dio);
% second trigger
% set to off state
putvalue(dio,0);
WaitSecs(setup.EEG.waitTrigEnc);
setup.EEG.DIO.EndTrigger_8_01 = getvalue(dio);
% set to on state
putvalue(dio,8);
WaitSecs(setup.EEG.waitTrigEnc);
setup.EEG.DIO.EndTrigger_8_11 = getvalue(dio);
% set to off state
putvalue(dio,0);
WaitSecs(setup.EEG.waitTrigEnc);
setup.EEG.DIO.EndTrigger_8_02 = getvalue(dio);
end
end
%% save data and close screen
save([StroopPath,setup.subj(1:4), '_StroopData_',expInfo.StroopRun,'.mat'], 'StroopAudio', 'expInfo');
%KbStrokeWait;
sca;
end