-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisualSearch_statLearning.m
572 lines (459 loc) · 26.2 KB
/
visualSearch_statLearning.m
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
classdef visualSearch_statLearning
% Author: Jason Arita
% Version: 1
%
properties
name = 'visualSearch_statLearning';
block; % where all trial data is stored
date; % current date (see help DATESTR)
start_time; % current time
end_time;
isPractice; % from prompt
subjectID; % from prompt
run_num; % from prompt
save_filename; % from prompt
condInfo; % from prompt
save_directory = 'data.raw';
%------------------------
% Stimulus settings
%------------------------
set_size_list = { 8 }; % num of colored objects
bgColorWd = 'white'; % (str)
search_annulus_radius = 200; % (px) dist. from center for landalt-c's
trialMultiplier = 1; % num times to repeat each trial permutation (~5 mins per set of unique trials)
target_quadrant_list = { 'top_left' , 'top_right' , 'btm_left' , 'btm_right'};
target_quadrant_distribution= { 7 , 1 , 1 , 1 };
target_presence_list = { 'present' };
target_orientation_list = { 'up' , 'down' };
distractor_orientation_list = { 'left' , 'right' };
%------------------------
% Time Settings
%------------------------
% ~ 12 seconds max per trial
ITI_range = [ 1.000 1.400 ]; % (sec) min dur for inter trial interval (ITI)
pre_trial_duration = 0.250; % (sec) dur to present fixation before search frame
responseDur = 1.000; % (sec) dur to wait for resp
post_response_duration = 0.250; % (sec) dur to wait after subj resp
%------------------------
% Font Settings
%------------------------
fontName = 'Helvetica'; % font name for all instructions
fontSize = 24; % font size for all instructions
fontColorWd = 'black'; % fonct color for all instructions
fontWrap = 45;
% Timing %
exptDuration;
% Response %
subjectHandedness;
accResp;
accRespNames;
end % properties
properties (Constant = true)
DEBUG = false ;
end % constant properties
methods
function obj = visualSearch_statLearning(varargin)
obj.date = datestr(now, 'mm/dd/yyyy'); % current date (see help DATESTR)
obj.start_time = datestr(now, 'HH:MM:SS AM'); % current time
% INPUT HANDLING:
switch nargin
case 0 % Default settings
% -------------------------- %
% Prompt Experiment Run Info %
% -------------------------- %
promptTitle = 'Experimental Setup Information';
prompt = ...
{ 'Enter subject number: ' ...
, 'Enter Run Number: ' ...
, 'Practice?' ...
, 'Handedness (1-Left 2-Right)' ...
};
promptNumAnsLines = 1;
promptDefaultAns = ...
{ 'J99' ...
, '99' ...
, 'no' ...
, '1' ...
};
options.Resize = 'on';
answer = inputdlg(prompt, promptTitle, promptNumAnsLines, promptDefaultAns, options);
if(isempty(answer))
return;
else
obj.subjectID = answer{1};
obj.run_num = answer{2};
obj.isPractice = answer{3};
obj.subjectHandedness = answer{4};
end
case 3
obj.subjectID = varargin{1};
obj.run_num = varargin{2};
obj.isPractice = varargin{3};
obj.subjectHandedness = varargin{4};
otherwise
error('Wrong number of input arguments');
end
% Practice Setup
switch lower(obj.isPractice)
case 'yes'
obj.isPractice = true;
otherwise
obj.isPractice = false;
end
if(obj.DEBUG)
obj.trialMultiplier = 1; % num times to repeat each trial permutation
end
%------------------------
% Set up trials
%------------------------
display('Generating Trial Permutations...');
obj.block = visualSearch_statLearning_block ...
( obj.subjectID ...
, obj.run_num ...
, obj.trialMultiplier ...
, obj.set_size_list ...
, obj.target_quadrant_list ...
, obj.target_quadrant_distribution ...
, obj.target_presence_list ...
, obj.target_orientation_list ...
, obj.distractor_orientation_list ...
, obj.ITI_range ...
, obj.search_annulus_radius ...
);
display('Done');
% -----------------------
% Randomize Trials
% -----------------------
if(~obj.DEBUG); obj.block.trials = obj.block.randomize(); end % Don't randomize if not debugging
% Setup Save Directory
if(~exist(obj.save_directory, 'dir')); mkdir(obj.save_directory); end % if save dir doesn't exist create one
% Save header to output file
if(obj.isPractice)
obj.save_filename = [ './' obj.save_directory '/practice_' obj.name '_' obj.subjectID '.txt'];
else
obj.save_filename = [ './' obj.save_directory '/' obj.name '_' obj.subjectID '.txt'];
end
end % constructor method
function obj = run(obj)
try
clc; HideCursor;
progEnv.gamepadIndex = Gamepad('GetGamepadIndicesFromNames', 'Logitech(R) Precision(TM) Gamepad');
[ winPtr, ~, screenCenter_pt ] = seSetupScreen(seColor2RGB(obj.bgColorWd)); % setup screen
% Response button(s) definitions
if(upper(obj.subjectHandedness) == 'R')
responseButtons = [6 8]; % Right trigger button 6: Target present, Button 8: Target absent
else
responseButtons = [5 7]; % Left trigger button 5: Target present, Button 7: Target absent
end
gamepadObject = seGamepad(responseButtons); % Create a SEGAMEPAD object to collect responses
background = stimBackground(obj.bgColorWd); % setup background stim
fixation = stimFixationPt(screenCenter_pt); % setup fixation stim
Screen('TextFont', winPtr, obj.fontName); % setup text font
Screen('TextSize', winPtr, obj.fontSize); % setup text size
if(obj.isPractice)
numTrials = 15; % use subset of all generated trials for practice
else
numTrials = length(obj.block.trials); % use all generated trials
end
breakTrialNum = ceil(numTrials / 3); % Take a break every 1/3 of each session
% --------------------
% Execute Experiment
% --------------------
startTime = GetSecs; % start timing experiment session
% --------------------------
% Present instructions
% --------------------------
% background.draw(winPtr);
% DrawFormattedText(winPtr, obj.cue_instructions, 'center', 'center',seColor2RGB(obj.fontColorWd),obj.fontWrap,0,0,2);
% Screen('Flip', winPtr); % flip/draw buffer to display monitor
% waitForButtonRelease(progEnv.gamepadIndex);
% waitForSubjPress(progEnv.gamepadIndex);
% --------------------------
% draw button instructions
% --------------------------
% for respNum = 1:length(obj.accResp)
%
% buttonInstruction_txt = sprintf('Button %d is the %s.\n\nPress the target %s to continue... ' ...
% , obj.accResp{respNum} ...
% , obj.accRespNames{respNum} ...
% , obj.accRespNames{respNum} ...
% );
%
% DrawFormattedText(winPtr,buttonInstruction_txt,'center','center',seColor2RGB(obj.fontColorWd),obj.fontWrap+10,false,false,2);
% Screen('Flip', winPtr); % flip/draw buffer to display monitor
%
% % wait for button confirmation
% % waitForButtonRelease(progEnv.gamepadIndex);
% % gamepadResponse(100,obj.accResp(respNum),{obj.accRespNames(respNum)}); % only accept correct response
% responseGamepad.waitForResponse(100);
%
% end
WaitSecs(.500); % give the subject a little time to get ready
ITI_start_time = GetSecs;
ITI_dur = 0;
for currTrialNum = 1:numTrials % Trial Start
% -------------------------
% Execute Single Trial
% -------------------------
obj.block.trials(currTrialNum).trial_order_num = currTrialNum; % save trial order number to data object
stim_search = obj.block.trials(currTrialNum).searchStimuli;
% if(daqCard.isPresent); daqCard.resetPorts(); end
ITI_processing_time = (GetSecs-ITI_start_time);
leftover_ITI_dur = ITI_dur -ITI_processing_time;
WaitSecs(leftover_ITI_dur);
fprintf('Nominal ITI Duration:\t%-8.4f\tms\n' , ITI_dur *1000);
fprintf('Actual ITI Duration:\t%-8.4f\tms\n' , (GetSecs-ITI_start_time)*1000);
fprintf('=================================================\n');
fprintf('Current trial Num:\t%3d / %3d\t trials\n' , currTrialNum, numTrials);
fprintf('\n');
% -------------------------
% Present: Pre-trial frame
% -------------------------
background.draw(winPtr);
fixation.draw(winPtr);
Screen('Flip', winPtr); % flip/draw buffer to display monitor
WaitSecs(obj.pre_trial_duration); % wait:
% fprintf('Pre-trial fixation dur: %1.4f\t\t ms\n' , (GetSecs-start)/1000);
% ----------------------------------
% Present: Search frame
% ----------------------------------
% start = GetSecs;
background.draw(winPtr);
fixation.draw(winPtr);
stim_search.draw(winPtr, screenCenter_pt);
Screen('Flip', winPtr); % flip/draw buffer to display monitor
% daqCard.sendEventCode(target_eventCode); % send event code
% targDisplaySOA = GetSecs-start;
% ----------------------------------
% Subj Response
% ----------------------------------
% start = GetSecs;
% subject_response = gamepadResponse(obj.responseDur, obj.accResp, obj.accRespNames);
responseGamepad.waitForResponse(obj.responseDur);
WaitSecs(obj.post_response_duration);
% targetDisplayDur = GetSecs-start;
% ------------------------------
% Present: Post-response frame
% ------------------------------
ITI_start_time = GetSecs;
background.draw(winPtr);
Screen('Flip', winPtr); % flip/draw buffer to display monitor
% -------------------------
% Post-Trial Processing
% -------------------------
% obj.block.trials(currTrialNum).saveResponse(subject_response); % save the response to the expt class structure
obj.save_to_file(currTrialNum, false);
curr_mean_accuracy = nanmean([ obj.block.trials.accuracy ]) * 100; % calculate current mean accuracy
curr_mean_RT = nanmean([ obj.block.trials.RT ]) * 1000; % calculate current mean response time
ITI_dur = obj.block.trials(currTrialNum).ITI; % figure out the ITI duration at the end of the trial
fprintf('Trial Accuracy: \t%-8.4f\t%%\n' , obj.block.trials(currTrialNum).accuracy * 100 );
fprintf('Trial Response Time:\t%-8.4f\tms\n' , obj.block.trials(currTrialNum).RT * 1000);
fprintf('\n');
fprintf('Mean Accuracy: \t%-8.4f\t%%\n' , curr_mean_accuracy );
fprintf('Mean Response Time: \t%-8.4f\tms\n' , curr_mean_RT );
fprintf('\n');
% fprintf('Target Display SOA:\t %1.4f\t ms\n' , targDisplaySOA * 1000);
% fprintf('Target Display Duration: %1.4f\t ms\n\n' , targetDisplayDur * 1000);
fprintf('-------------------------------------------------\n');
% -------------------------
% subject break
% -------------------------
% if((mod(currTrialNum, breakTrialNum) == 0) ... %
% && not(currTrialNum == numTrials) ... % No break on last trial
% && ~obj.isPractice) % No breaks during practice
%
% background.draw(winPtr);
%
% break_text = sprintf('Take a break\n\nAccuracy:\t %-1.2f \t%%\nResponse Time:\t %-1.2f\tmsecs\n\nPress button 10 button to continue', curr_mean_accuracy , curr_mean_RT);
% DrawFormattedText(winPtr, break_text, 'center', 'center',seColor2RGB(obj.fontColorWd),obj.fontWrap,0,0,2);
% Screen('Flip', winPtr); % flip/draw buffer to display monitor
% % waitForButtonRelease(progEnv.gamepadIndex);
% % waitForSubjPress(progEnv.gamepadIndex); % wait for button press (subj rest period)
%
%
%
% % --------------------------
% % Present cue instructions
% % --------------------------
% % background.draw(winPtr);
% % DrawFormattedText(winPtr, obj.cue_instructions, 'center', 'center',seColor2RGB(obj.fontColorWd),obj.fontWrap,0,0,2);
% % Screen('Flip', winPtr); % flip/draw buffer to display monitor
% % waitForButtonRelease(progEnv.gamepadIndex);
% % waitForSubjPress(progEnv.gamepadIndex);
% %
% WaitSecs(.500); % give the subject a little time to get ready
% end
end % Trial End
% -------------------------
% Finish Expt
% -------------------------
% -------------------------
% Present: Expt End Screen
% -------------------------
if(obj.isPractice)
end_instructions = sprintf('Practice Finished.\n\nAccuracy:\t %-1.2f \t%%\nResponse Time:\t %-1.2f\tmsecs\n\nPress button 10 to continue' ...
, curr_mean_accuracy ...
, curr_mean_RT ...
);
else
end_instructions = sprintf('Run finished.\n\nAccuracy:\t %-1.2f \t%%\nResponse Time:\t %-1.2f\tmsecs\n\nPress button 10 to continue' ...
, curr_mean_accuracy ...
, curr_mean_RT ...
);
% soundsc(exptEndSndData, exptEndSndFreq); % Play sound at expt run end
end
background.draw(winPtr);
DrawFormattedText(winPtr, end_instructions, 'center', 'center',seColor2RGB(obj.fontColorWd),obj.fontWrap);
Screen('Flip', winPtr); % flip/draw buffer to display monitor
if(obj.isPractice)
KbWait;
else
KbWait;
end
% display experiment information @ run end
obj.exptDuration = (GetSecs - startTime) / 60; % (minutes)
fprintf('Session Duration: %1.4f\t min\n\n' , obj.exptDuration);
ShowCursor;
Screen('CloseAll'); % close psychtoolbox screen
catch matlab_err
ShowCursor;
Screen('CloseAll'); % close psychtoolbox screen
display(getReport(matlab_err));
end
end % run method
function save_to_file(obj, trial_num, header, separator, excelYear, decimal)
% Writes cell array content into a *.csv file.
%
% CELL2CSV(obj.save_filename, cellArray, separator, excelYear, decimal)
%
% obj.save_filename = Name of the file to save. [ i.e. 'text.csv' ]
% cellArray = Name of the Cell Array where the data is in
% separator = sign separating the values (default = ';')
% excelYear = depending on the Excel version, the cells are put into
% quotes before they are written to the file. The separator
% is set to semicolon (;)
% decimal = defines the decimal separator (default = '.')
%
% by Sylvain Fiedler, KA, 2004
% updated by Sylvain Fiedler, Metz, 06
% fixed the logical-bug, Kaiserslautern, 06/2008, S.Fiedler
% added the choice of decimal separator, 11/2010, S.Fiedler
%% Checking for optional Variables
if ~exist('separator', 'var')
separator = ',';
end
if ~exist('excelYear', 'var')
excelYear = 1997;
end
if ~exist('decimal', 'var')
decimal = '.';
end
%% Setting separator for newer excelYears
if excelYear > 2000
separator = ';';
end
%% Write file
datei = fopen(obj.save_filename, 'a+'); % open/create file; append data
var_names = transpose(fieldnames(obj.block.trials(trial_num)));
for var_name = var_names
if header
print_value = var_name{1};
else
print_value = eval(['obj.block.trials(trial_num).' var_name{1}]);
end
% If zero, then empty cell
if size(print_value, 1) == 0
print_value = '';
end
% If numeric -> String
if isnumeric(print_value)
print_value = num2str(print_value);
% Conversion of decimal separator (4 Europe & South America)
% http://commons.wikimedia.org/wiki/File:DecimalSeparator.svg
if decimal ~= '.'
print_value = strrep(print_value, '.', decimal);
end
end
% If logical -> 'true' or 'false'
if islogical(print_value)
if print_value == 1
print_value = 'TRUE';
else
print_value = 'FALSE';
end
end
% If newer version of Excel -> Quotes 4 Strings
if excelYear > 2000
print_value = ['"' print_value '"']; %#ok<AGROW>
end
% OUTPUT value
fprintf(datei, '%s', print_value);
% OUTPUT separator
% if s ~= size(cellArray, 2)
fprintf(datei, separator);
% end
end
fprintf(datei, '\n'); % print new line at end of every line
% Closing file
fclose(datei);
end
end % methods
end % classdef
%% Sub Functions %
% function waitForSubjPress(gamepadIndex)
% % Keep looping till keyPressName is pressed
% BUTTON_10 = 10;
% done = false; % Initialize keyboard polling loop
%
% waitForButtonRelease(gamepadIndex); % Make sure to wait for key release AFTER start timing
% % . . . but why?
% while not(done); % keep polling keyboard for user response
% button10State = Gamepad('GetButton', gamepadIndex, BUTTON_10);
%
% if (button10State == true)
% done = true;
% end % button check
%
% end % response loop
%
% end
% function waitForButtonRelease(gamepadIndex)
% % Keeps looping till ONLY buttons 1-10 are all released
%
% BUTTON_1 = 1;
% BUTTON_2 = 2;
% BUTTON_3 = 3;
% BUTTON_4 = 4;
% BUTTON_5 = 5;
% BUTTON_6 = 6;
% BUTTON_7 = 7;
% BUTTON_8 = 8;
% BUTTON_9 = 9;
% BUTTON_10 = 10;
%
% keyDown = true;
% while(keyDown)
%
% buttonState = [ ...
% Gamepad('GetButton', gamepadIndex, BUTTON_1) ...
% Gamepad('GetButton', gamepadIndex, BUTTON_2) ...
% Gamepad('GetButton', gamepadIndex, BUTTON_3) ...
% Gamepad('GetButton', gamepadIndex, BUTTON_4) ...
% Gamepad('GetButton', gamepadIndex, BUTTON_5) ...
% Gamepad('GetButton', gamepadIndex, BUTTON_6) ...
% Gamepad('GetButton', gamepadIndex, BUTTON_7) ...
% Gamepad('GetButton', gamepadIndex, BUTTON_8) ...
% Gamepad('GetButton', gamepadIndex, BUTTON_9) ...
% Gamepad('GetButton', gamepadIndex, BUTTON_10) ...
% ];
%
% if(any(buttonState))
% keyDown = true;
% else
% keyDown = false;
% end
%
% end
%
% end
% END