File size: 12,021 Bytes
e7dce60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
 %%  Cost Confict adapted for Joystick and Brain Vision: JFC 12/13/11
% Re-adapted for Beh for PdDys: JFC 02/11/15

clear all;
close all;
command = 'echo orp | sudo -S ifconfig en0 down';
system(command);

fprintf('\n\nShutting down internet to protect timing\n\n');

% Find Gamepad and USB-FS2019
devs    = PsychHID('Devices');
DAQindx = DaqDeviceIndex();
err0    = DaqDConfigPort(DAQindx, 0, 0);     % Port A
GPindx  = find(strcmp('Logitech(R) Precision(TM) Gamepad', {devs.product}));

if isempty(GPindx)
  error('No Gamepad attached! Stick one in me so we can play. Then restart Matlab')
end

if isempty(DAQindx)
  error('No DAQ attached! Stick one in me or the EEG will be lonely. Then restart Matlab')
end

% Test fire?
DaqDOut(DAQindx, 0, 69); WaitSecs(0.2);
DaqDOut(DAQindx, 0, 0);
fprintf('\n\n\n')
TriggerYN = input('Did you see a trigger? And was it a lonely 69\n','s');  %       
if any(strcmp(TriggerYN, {'N'  'n'  'No'  'no'}))
    error('Ahhhhhhh!!!! No triggers. Please fix so people know when I am stimulated')
end

% Get directories
taskdir = pwd;

% Change directory to this script's dir
p = pwd;

subject_number = input('Enter the subject number :','s');
subject_group  = input('Patient, Control or Pilot ("SZ", "NC", anything else) :\n', 's');

if length(subject_group) == 0
    subject_group = 'Pilots';
end
if any(strcmp(subject_group, {'SZ', 'sz', 's', 'S', 'Patient', 'patient', 'pat', 'Pat', 'scz', 'schz', 'SCZ', 'SCHZ', 'Schz', 'Scz'}))
    subject_group = 'Patients';
elseif any(strcmp(subject_group, {'NC', 'c', 'C', 'HC', 'nc', 'hc', 'control', 'Control', 'healthy', 'healthy control', 'Healthy Control'}))
    subject_group = 'Normal Controls';
else
    subject_group = 'Pilots';
end

run_resting    = input('\nDo you need to run the resting state?\n(This is a part of the cost conflict experiment):','s');
contacts       = input('\nDoes the participant wear contacts?', 's');

datadir = [taskdir '/Data/' subject_group '/M' subject_number '/Cost Conflict/'];
mkdir(datadir);

% $$$$$$$$$$$$ $$$$$$$$$$$$ $$$$$$$$$$$$ $$$$$$$$$$$$
% % % % PREPRACT_RESPDEADLINE=3;
% % % % RESPDEADLINE=1.5;
% % % % TSTDEADLINE=5;
PREPRACT_RESPDEADLINE=1;
RESPDEADLINE=0.85;
TSTDEADLINE=3;
FUDGE = 10; % fraction of a second to jitter feedback and response, i.e. = 0.17 + rand/FUDGE

% This version adds error/missed trials to the END of the TRN run.
% And 'D' is 0% reward
% Remember there is some odd coding in the beh for condi - use old beh analysis scripts!
% $$$$$$$$$$$$ $$$$$$$$$$$$ $$$$$$$$$$$$ $$$$$$$$$$$$

% hide the cursor
HideCursor();
% disable user responses from being displayed
ListenChar(2);

% Stim
A=1; B=2;
C=3; D=4;
% Color
y=1; b=2;
% Congru
c=1; i=2;

% Set up the screen display
% get the screen pointer
screens       = Screen('Screens');
screen        = max(screens);     % Stimuli will be drawn on the highest screen number
% #####################
% screenRect = [0,0,1000,800]; % screen for debugging
screenRect = []; % full screen
% #####################
[wPtr,rect] = Screen('OpenWindow',screen, [], screenRect);
black=BlackIndex(wPtr);
Screen('FillRect',wPtr,black);
Screen(wPtr, 'Flip');

% get the center point for presentation purposes
X_center = rect(3)/2;
Y_center = rect(4)/2;
% define the boundries of the right and left stims  
image_width = 200;
image_height = 200;
% a pixel buffer from the center point
pixel_buffer = 325;
pixel_buffer_test = 75;
pixel_buffer_up = 100;
% define center rect
x_Right = X_center - image_width/2;
X_Left = X_center + image_width/2;
Y_Top = Y_center - image_height/2;
left_Ybottom = Y_Top + image_height;
center_rect = [x_Right, Y_Top, X_Left, left_Ybottom];
% define the left image rect
x_Right = X_center - image_width - pixel_buffer;
X_Left = x_Right + image_width;
Y_Top = Y_center - image_height/2;
left_Ybottom = Y_Top + image_height;
left_rect = [x_Right, Y_Top, X_Left, left_Ybottom];
% and the right image rect
x_Right = X_center + pixel_buffer;
X_Left = x_Right + image_width;
Y_Top = Y_center - image_height/2;
left_Ybottom = Y_Top + image_height;
right_rect = [x_Right, Y_Top, X_Left, left_Ybottom];
% TEST: left image rect
x_Right = X_center - image_width - pixel_buffer_test;
X_Left = x_Right + image_width;
Y_Top = Y_center - image_height/2;
left_Ybottom = Y_Top + image_height;
left_rect_test = [x_Right, Y_Top, X_Left, left_Ybottom];
% TEST: right image rect
x_Right = X_center + pixel_buffer_test;
X_Left = x_Right + image_width;
Y_Top = Y_center - image_height/2;
left_Ybottom = Y_Top + image_height;
right_rect_test = [x_Right, Y_Top, X_Left, left_Ybottom];


% input keys
left_key = KbName('d');
right_key = KbName('k');

left_button = 5;
right_button = 6;
up_button = 4;
down_button = 2;

%**********************************************************************
% RESTING STATE for eye blinks for dopamine
if any(strcmp(run_resting, {'yes' 'y' 'Y' 'Yes' 'YE' 'ye' 'YES' 'Ye'}))
    save([datadir 'contacts.mat'], 'contacts')
    restopentext  = 'Experimenter: Prepare for 2 minutes resting state EEG';
    reststarttext = 'Experimenter: Start EEG data saving.\nNew EEG file label = REST######\n\n###### = Participant Code\n\n\nThen press any key to continue.';
    restparttext  = 'Participant: Please relax while focussing gently on the cross hair for two minutes\n\n\n\nExperimenter: press any key to start.';
    restendtext   = 'Finished Resting State\nGet ready for Cost Conflict.\n\nHave fun!\n\n\nExperimenter: Press any key to go onto cost conflict';

    Screen('TextSize',wPtr,50);
    Screen('TextFont',wPtr,'Times');
    Screen('TextStyle',wPtr,0);
    Screen('TextColor',wPtr,[255 255 255]);
    DrawFormattedText(wPtr,restopentext,'center','center');
    Screen(wPtr, 'Flip');
    KbWait([],3); %Waits for keyboard(any) press

    DrawFormattedText(wPtr,reststarttext,'center','center');
    Screen(wPtr, 'Flip');
    KbWait([],3); %Waits for keyboard(any) press

    DrawFormattedText(wPtr,restparttext,'center','center');
    Screen(wPtr, 'Flip');
    KbWait([],3); %Waits for keyboard(any) press

    DrawFormattedText(wPtr,'+','center','center');
    Screen(wPtr, 'Flip');
    WaitSecs(2);
    for tl = 1:62
        DaqDOut(DAQindx, 0, tl); WaitSecs(1);
        DaqDOut(DAQindx, 0, 0); WaitSecs(1);
    end
    WaitSecs(1);

    DrawFormattedText(wPtr, restendtext,'center','center');
    Screen(wPtr, 'Flip');
    KbWait([],3); %Waits for keyboard(any) press
end

%********************************************************************
Instructions;    % Pract were stims 1,2
session = round(rand+1);
if session==1
    STIMS{1}=[4,8,15,17];
    STIMS{2}=[11,5,3,10];
    STIMS{3}=[7,12,13,18];
    STIMS{4}=[16,21,19,20];
elseif session==2
    STIMS{1}=[14,22,23,25];
    STIMS{2}=[24,29,27,28];
    STIMS{3}=[30,6,9,26];
    STIMS{4}=[31,32,33,34];
end

starttext = 'Experimenter: Start EEG data saving.\nNew EEG file label = CC######_B1\n\n\nThen press any key to begin experiment';
Screen('TextSize',wPtr,50);
Screen('TextFont',wPtr,'Times');
Screen('TextStyle',wPtr,0);
Screen('TextColor',wPtr,[255 255 255]);
DrawFormattedText(wPtr,starttext,'center','center');
Screen(wPtr, 'Flip');
KbWait([],3); %Waits for keyboard(any) press

setNum = 0;
sets=randperm(4);
for Block=sets
    
    setNum = setNum + 1;
    
    % Set Stims
    S1=num2str(STIMS{Block}(1));
    S2=num2str(STIMS{Block}(2));
    S3=num2str(STIMS{Block}(3));
    S4=num2str(STIMS{Block}(4));

    data_block = [];
    TRAINING;
   
    load([datadir 'M' num2str(subject_number),'_B',num2str(Block),'_CC_train.mat']);
    points = sum(data_block(:,11));
    fprintf(['#########################################\n\n\Points for that block = '...
        num2str(points) '\n\n\n'...
         '#########################################\n\n\n']);

    % ########################
    Screen('TextSize',wPtr,50);
    Screen('TextFont',wPtr,'Times');
    Screen('TextStyle',wPtr,0);
    Screen('TextColor',wPtr,[255 255 255]);
    beginningText1 = 'Good Job. \n\n\nGet Ready For the test phase.  \n\n\n\n\n Experimenter:  Press [Space] to continue ';
    DrawFormattedText(wPtr,beginningText1,'center','center');
    Screen(wPtr, 'Flip');
    KbWait([],3); %Waits for keyboard(any) press
    beginningText1 = 'The pictures will be presented in pairs again. \n\n\nPick the picture that was MOST REWARDING during the task \n\n\n\n\n Experimenter: Press space to continue ';
    DrawFormattedText(wPtr,beginningText1,'center','center');
    Screen(wPtr, 'Flip');
    KbWait([],3); %Waits for keyboard(any) press
    % ########################
    
    data_test = []; 
    TESTING;
    
    clear global B_textures;
    clear S1 S2 S3 S4;

    if any(Block == sets(1:3))
        Screen('TextSize',wPtr,50);
        Screen('TextFont',wPtr,'Times');
        Screen('TextStyle',wPtr,0);
        Screen('TextColor',wPtr,[255 255 255]);
        beginningText1 = 'Great!  Get ready for a new training phase...\n\n\n\n\nExperimenter:  Press [Space] to continue';
        DrawFormattedText(wPtr,beginningText1,'center','center');
        Screen(wPtr, 'Flip');
        KbWait([],3); %Waits for keyboard(any) press
    end
    
    if  Block==sets(2)
        breaktext = 'Please have a short break while the experimenter \n starts a new EEG file \n\n\n\n New file label = CC######_B2';
        DrawFormattedText(wPtr, breaktext,'center','center');
        Screen(wPtr, 'Flip');
        KbWait([],3); %Waits for keyboard(any) press
    end
    
    blocknumbertext = num2str(find(Block==sets)+1);
    if any(Block == sets(1:3))
        startblocktext = ['Experimenter, press any key to start new block\n\n\n Block ' blocknumbertext ' of/4'];
        DrawFormattedText(wPtr, startblocktext,'center','center');
        Screen(wPtr, 'Flip');
        KbWait([],3); %Waits for keyboard(any) press
    end
    % ########################
    
end

%*******FORCE STOP**********
wait_text = 'Done!\n\nThank you for participating!\n\n\nPlease wait for the experimenter.';
Screen('TextFont',wPtr,'Times New Roman');
Screen('TextStyle',wPtr,0);
Screen('TextColor',wPtr,[255 255 255]);
Screen('TextSize',wPtr,80);
DrawFormattedText(wPtr,wait_text,'center','center');
Screen(wPtr, 'Flip');
KbWait([],3); %Waits for keyboard(any) press

%*******FORCE STOP**********

sca;
ShowCursor;
fprintf('\nEnd of Task.\n');
close all;

fprintf('\n\nStarting up internet to sync data\n');
command = 'echo orp | sudo -S ifconfig en0 up';
system(command);
WaitSecs(1);
fprintf('\n\nConnecting to the mothership......\n');
WaitSecs(1);
fprintf('\nConnection probably established......\n');
WaitSecs(2);
fprintf('\nI think I just touched E.T.\n\n\n\n');
WaitSecs(1);
command = 'rsync -avzhe ssh /Users/orp/Documents/MATLAB/REEG2/\!Cost\ Conflict_4/data/ malbrecht@orp-12212-MAPC\:/local/Dropbox/REEG_Data/REEG2_BehaviorBySub/';
system(command);

fprintf('\n\n\nOoooooohhhhh YEAH!!!! Synchronicity!.......\n');

ListenChar(0);

% Calculate total points
load([datadir 'M' num2str(subject_number),'_B',num2str(1),'_CC_train.mat']);
points = sum(data_block(:,11));
load([datadir 'M' num2str(subject_number),'_B',num2str(2),'_CC_train.mat']);
points = points + sum(data_block(:,11));
load([datadir 'M' num2str(subject_number),'_B',num2str(3),'_CC_train.mat']);
points = points + sum(data_block(:,11));
load([datadir 'M' num2str(subject_number),'_B',num2str(4),'_CC_train.mat']);
points = points + sum(data_block(:,11));

winnings = points*5/100;
if winnings < 2
    winnings = 2;
elseif winnings > 8
    winnings = 8;
end
fprintf(['#########################################\n\n\nTotal Points = '...
        num2str(points) '\n\n\nParticipant won $' num2str(winnings) '\n\n\n'...
         '#########################################\n\n\n']);