File size: 14,741 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 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 |
%*****TRAINING STIM SETUP****
% the number of trials of each stim pairing
Btrials_perType = 5; % 5 runs each
TotalTrial = 16 * Btrials_perType; % 80 trials total;
% build the B1 trial list
Ayi_trials = repmat([ A,y,i ], Btrials_perType, 1);
Ayc_trials = repmat([ A,y,c ], Btrials_perType, 1);
Abi_trials = repmat([ A,b,i ], Btrials_perType, 1);
Abc_trials = repmat([ A,b,c ], Btrials_perType, 1);
Byi_trials = repmat([ B,y,i ], Btrials_perType, 1);
Byc_trials = repmat([ B,y,c ], Btrials_perType, 1);
Bbi_trials = repmat([ B,b,i ], Btrials_perType, 1);
Bbc_trials = repmat([ B,b,c ], Btrials_perType, 1);
Cyi_trials = repmat([ C,y,i ], Btrials_perType, 1);
Cyc_trials = repmat([ C,y,c ], Btrials_perType, 1);
Cbi_trials = repmat([ C,b,i ], Btrials_perType, 1);
Cbc_trials = repmat([ C,b,c ], Btrials_perType, 1);
Dyi_trials = repmat([ D,y,i ], Btrials_perType, 1);
Dyc_trials = repmat([ D,y,c ], Btrials_perType, 1);
Dbi_trials = repmat([ D,b,i ], Btrials_perType, 1);
Dbc_trials = repmat([ D,b,c ], Btrials_perType, 1);
% define the DETERMINISTIC B1 stim reward contingencies
% ############################################# size is based on trialspertype
Rich=[1;1;1;1;1];
Lean=[0;0;0;0;0];
Sparse=[0;0;0;0;0];
% #############################################
Ayc_trials=[Ayc_trials, Rich];
Abc_trials=[Abc_trials, Rich];
Ayi_trials=[Ayi_trials, Rich];
Abi_trials=[Abi_trials, Rich];
%
Byc_trials=[Byc_trials, Rich];
Bbc_trials=[Bbc_trials, Rich];
Byi_trials=[Byi_trials, Lean];
Bbi_trials=[Bbi_trials, Lean];
%
Cyc_trials=[Cyc_trials, Lean];
Cbc_trials=[Cbc_trials, Lean];
Cyi_trials=[Cyi_trials, Rich];
Cbi_trials=[Cbi_trials, Rich];
%
Dyc_trials=[Dyc_trials, Sparse];
Dbc_trials=[Dbc_trials, Sparse];
Dyi_trials=[Dyi_trials, Sparse];
Dbi_trials=[Dbi_trials, Sparse];
% bind all the trial types to define the block's trials
B_trialList = [Ayi_trials; Ayc_trials; Abi_trials; Abc_trials; Byi_trials; Byc_trials; Bbi_trials; Bbc_trials;...
Cyi_trials; Cyc_trials; Cbi_trials; Cbc_trials; Dyi_trials; Dyc_trials; Dbi_trials; Dbc_trials;];
% read in the images and create the required textures: {A,B}{y,b}
% Although A & B won't display punishments (m1.bmp) and C & D won't display rewards(1.bmp), this
% format keeps things nice and consistent, if a little redundant.
B_images = [];
B_images{1}{1} = imread(['./images/',S1,'_Y.bmp']);
B_images{1}{2} = imread(['./images/',S1,'_B.bmp']);
B_images{1}{3} = imread(['./images/',S1,'_1.bmp']);
B_images{1}{4} = imread(['./images/',S1,'_0.bmp']);
B_images{1}{5} = imread(['./images/',S1,'_m1.bmp']); % minus 1 for punishments
B_images{1}{6} = imread(['./images/',S1,'.bmp']);
B_images{2}{1} = imread(['./images/',S2,'_Y.bmp']);
B_images{2}{2} = imread(['./images/',S2,'_B.bmp']);
B_images{2}{3} = imread(['./images/',S2,'_1.bmp']);
B_images{2}{4} = imread(['./images/',S2,'_0.bmp']);
B_images{2}{5} = imread(['./images/',S2,'_m1.bmp']);
B_images{2}{6} = imread(['./images/',S2,'.bmp']);
B_images{3}{1} = imread(['./images/',S3,'_Y.bmp']);
B_images{3}{2} = imread(['./images/',S3,'_B.bmp']);
B_images{3}{3} = imread(['./images/',S3,'_1.bmp']);
B_images{3}{4} = imread(['./images/',S3,'_0.bmp']);
B_images{3}{5} = imread(['./images/',S3,'_m1.bmp']);
B_images{3}{6} = imread(['./images/',S3,'.bmp']);
B_images{4}{1} = imread(['./images/',S4,'_Y.bmp']);
B_images{4}{2} = imread(['./images/',S4,'_B.bmp']);
B_images{4}{3} = imread(['./images/',S4,'_1.bmp']);
B_images{4}{4} = imread(['./images/',S4,'_0.bmp']);
B_images{4}{5} = imread(['./images/',S4,'_m1.bmp']);
B_images{4}{6} = imread(['./images/',S4,'.bmp']);
% randomize the images
B_images_rand=[];
randx_i=randperm(size(B_images,2));
count=1;
for randx=1:size(B_images,2)
B_images_rand{count}{1} = B_images{randx_i(randx)}{1};
B_images_rand{count}{2} = B_images{randx_i(randx)}{2};
B_images_rand{count}{3} = B_images{randx_i(randx)}{3};
B_images_rand{count}{4} = B_images{randx_i(randx)}{4};
B_images_rand{count}{5} = B_images{randx_i(randx)}{5};
B_images_rand{count}{6} = B_images{randx_i(randx)}{6};
count=count+1;
end
% load all the textures
B_textures = [];
for BTexture_index = 1 : size(B_images_rand, 2) % Number of stims
for color_index = 1 : size(B_images_rand{BTexture_index}, 2) %1=Y, 2=B, 3=1, 4=0, 5=k
B_textures{BTexture_index}{color_index} = Screen('MakeTexture', wPtr, B_images_rand{BTexture_index}{color_index});
end
end
global B_textures
% load the textures into an array mapping onto corresponding choice ids
textures = [];
textures(A,y,i) = B_textures{1}{1}; % {A,B,C,D}{y,b}
textures(A,y,c) = B_textures{1}{1};
textures(A,b,i) = B_textures{1}{2};
textures(A,b,c) = B_textures{1}{2};
textures(B,y,i) = B_textures{2}{1};
textures(B,y,c) = B_textures{2}{1};
textures(B,b,i) = B_textures{2}{2};
textures(B,b,c) = B_textures{2}{2};
textures(C,y,i) = B_textures{3}{1};
textures(C,y,c) = B_textures{3}{1};
textures(C,b,i) = B_textures{3}{2};
textures(C,b,c) = B_textures{3}{2};
textures(D,y,i) = B_textures{4}{1};
textures(D,y,c) = B_textures{4}{1};
textures(D,b,i) = B_textures{4}{2};
textures(D,b,c) = B_textures{4}{2};
% Feedback - standard CC with green +1 and red 0 (no punishment -1 shapes)
FBtextures(A,1) = B_textures{1}{3}; % cells are: {A,B,C,D},{y,b,rew,0,pun,tst}
FBtextures(A,2) = B_textures{1}{4};
FBtextures(B,1) = B_textures{2}{3};
FBtextures(B,2) = B_textures{2}{4};
FBtextures(C,1) = B_textures{3}{3};
FBtextures(C,2) = B_textures{3}{4};
FBtextures(D,1) = B_textures{4}{3};
FBtextures(D,2) = B_textures{4}{4};
%****BEGIN B*****
BComplete = false;
numBBlocks = 1; %*******Determines # of Blocks*******
Bblock_index = 0;
no_response = false;
% loop through the TRAINING phase
while ~BComplete
% track trial ids
trial_ids = [];
% track trial type
trial_stimuli = [];
%track response
trial_response = [];
% track which stim was choosen
trial_selectedStim = [];
% track the rt
trial_RT = [];
% track the accuracy
trial_accuracy = [];
% track the feedback
trial_feedback = [];
% increment the block index
Bblock_index = Bblock_index + 1;
random_index = randperm(size(B_trialList, 1));
randomized_trialList = B_trialList(random_index,:);
trial_index = 1;
while trial_index <= TotalTrial
% Fixation
fixation_text = '+';
Screen('TextFont',wPtr,'Times');
Screen('TextStyle',wPtr,0);
Screen('TextColor',wPtr,[255 255 255]);
Screen('TextSize',wPtr,80);
DrawFormattedText(wPtr,fixation_text,'center','center');
Screen(wPtr, 'Flip');
% show the fixation for 1 sec
WaitSecs(1);
% get the current trial's info
type = randomized_trialList(trial_index, 1);
color = randomized_trialList(trial_index, 2);
congru = randomized_trialList(trial_index, 3);
TRIALCODE=strcat(num2str(color),num2str(congru),num2str(type));
TRIALTRIGGER=str2double(TRIALCODE);
% define the correct choice
if color==1
correct_choice = left_button;
elseif color==2
correct_choice = right_button;
end
% define the window side based on congruency
if color==1 && congru==1 %(yellow-congruent==left)
rect = left_rect;
elseif color==1 && congru==2 %(yellow-incongruent==right)
rect = right_rect;
elseif color==2 && congru==1 %(blue-congruent==right)
rect = right_rect;
elseif color==2 && congru==2 %(blue-incongruent==left)
rect = left_rect;
end
% now draw the stim
Screen('DrawTexture', wPtr, textures(type,color,congru), [], rect);
Screen(wPtr, 'Flip');
% io64(ioObject,LTP1address,TRIALTRIGGER); WaitSecs(.05); io64(ioObject,LTP1address,0);
err=DaqDOut(DAQindx, 0, TRIALTRIGGER); WaitSecs(0.05);
% start the trial timer;
startTime = GetSecs();
wait_stamp=GetSecs;
% display "tmp"
while 1
%[a ab] = JoyMEX(0);
[ keyIsDown, seconds, keyCode ] = KbCheck(GPindx);
if keyIsDown
if keyCode(left_button) && left_button==correct_choice
subject_choice = left_button;
no_response = false;
trlResponse = 1;
trlAccuracy = 1;
RESPTRIGGER = 101;
break;
elseif keyCode(right_button) && right_button==correct_choice
subject_choice = right_button;
no_response = false;
trlResponse = 1;
trlAccuracy = 1;
RESPTRIGGER = 102;
break;
elseif keyCode(left_button) && left_button~=correct_choice % ERROR!
subject_choice = left_button;
no_response = false;
trlResponse = 1;
trlAccuracy = 0;
RESPTRIGGER = 103;
break;
elseif keyCode(right_button) && right_button~=correct_choice % ERROR!
subject_choice = right_button;
no_response = false;
trlResponse = 1;
trlAccuracy = 0;
RESPTRIGGER = 104;
break;
end
elseif(GetSecs-wait_stamp) > RESPDEADLINE,
subject_choice = no_response;
no_response = true;
trlResponse = -1;
trlAccuracy = -1;
RESPTRIGGER = 105;
break;
else
RESPTRIGGER = 249;
end
end
%io64(ioObject,LTP1address,RESPTRIGGER); WaitSecs(.05); io64(ioObject,LTP1address,0);
% stop the trial timer
err=DaqDOut(DAQindx, 0, RESPTRIGGER); WaitSecs(0.05)
RT = GetSecs() - startTime - 0.05;
WaitSecs(0.12 + rand/FUDGE); % Immediate Feedback????? NO! has 0.17 delay
err=DaqDOut(DAQindx, 0, 0);
% determine if they selected the right or left stim
if subject_choice == correct_choice
trlselectedStim = 1;
% get the selected stim's reward contingency
reward_contingency = randomized_trialList(trial_index, 4);
else
trlselectedStim = 0;
end
WaitSecs(0.005);
% determine the reward feedback
Screen('TextSize',wPtr,60);
Screen('TextFont',wPtr,'Times');
Screen('TextStyle',wPtr,1);
if no_response == true
Screen('TextColor',wPtr,[200 0 0]);
reward_text = 'No Response. -3';
trlFeedback = -3;
FixRewardProbs = 1;
reward = 0;
FBTRIGGER=7;
elseif no_response == false
if trlAccuracy == 0
Screen('TextColor',wPtr,[255 0 0]);
reward_text = 'ERROR! -3';
trlFeedback = -3;
FixRewardProbs = 1;
reward = 0;
FBTRIGGER=6;
else
if reward_contingency ==1 % REWARD or ZERO
Screen('TextColor',wPtr,[0 255 0]);
FB=FBtextures(type,1);
trlFeedback = 1;
FixRewardProbs = 0;
reward=1;
FBTRIGGER=8;
elseif reward_contingency ==0 % ZERO or PUNISHMENT - NO REWARD FOR YOU!
Screen('TextColor',wPtr,[0 0 255]);
FB=FBtextures(type,2);
trlFeedback = 0;
FixRewardProbs = 0;
reward = 0;
FBTRIGGER=9;
end
end
end
% If trial was an error or no-response, add trial to end
if FixRewardProbs == 1
% Add the error trial to the end.
randomized_trialList(end+1, :) = randomized_trialList(trial_index, :);
TotalTrial=TotalTrial+1;
FixRewardProbs=0;
end
% now show feedback based on response and stim contingencies
if trlAccuracy ~= 1
DrawFormattedText(wPtr,reward_text,'center','center');
Screen(wPtr, 'Flip');
%lptwrite(888, FBTRIGGER); WaitSecs(0.15); lptwrite(888, 0);
%io64(ioObject,LTP1address,FBTRIGGER);
err=DaqDOut(DAQindx, 0, FBTRIGGER); WaitSecs(0.05);
elseif trlAccuracy == 1
Screen('DrawTexture', wPtr, FB, [], rect);
Screen(wPtr, 'Flip');
%io64(ioObject,LTP1address,FBTRIGGER); WaitSecs(.05); io64(ioObject,LTP1address,0);
err=DaqDOut(DAQindx, 0, FBTRIGGER); WaitSecs(0.05);
end
clear FBTRIGGER TRIALTRIGGER RESPTRIGGER FB;
% show the feedback for 1 sec
WaitSecs(0.95);
err=DaqDOut(DAQindx, 0, 0);
% Store the trial data
%
% update the trial number list
trial_ids = [trial_ids; trial_index];
% store the trial stimuli
trial_stimuli = [trial_stimuli; randomized_trialList(trial_index,:)];
%store response
trial_response = [trial_response; trlResponse];
% store the RT
trial_RT = [trial_RT; RT];
% store the subject's choice
trial_selectedStim = [trial_selectedStim; trlselectedStim];
% store accuracy independent of feedback
trial_accuracy = [trial_accuracy; trlAccuracy];
% store the feedback
trial_feedback = [trial_feedback; trlFeedback];
% increment the trial index
trial_index = trial_index + 1;
end % end trialnum < randomindex
% mark each trial with the block number
data_block = zeros(size(trial_ids, 1), 1) + Bblock_index;
% collate all the data from the block
data_block = [data_block, trial_ids, trial_stimuli, trial_response, trial_selectedStim, trial_RT, trial_accuracy, trial_feedback];
% check to see if Block is done
if Bblock_index >= numBBlocks
BComplete = true;
end
end
% Save Block data
save([datadir 'M' num2str(subject_number),'_B',num2str(Block),'_CC_train.mat'],'data_block','randx_i');
|