Memoreye_unattended_version_01.m 87 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414
  1. %% MEMOREYE - UNATTENDED
  2. % Bernhard Spitzer and Juan Linde Domingo, MARCH 2021, CN@RC
  3. %% Main diferences re previous version (00)
  4. % Reduced size of pings and objects
  5. % Correct delay between last ping and tests
  6. % Including 6 different colorsets for Pings
  7. % Background set to 128
  8. %% Main diferences re previous version (00_1)
  9. % Practice added
  10. % Min delay between pings increased to 600ms (400ms before)
  11. %% Main diferences re previous version (00_5)
  12. % Practice and instructions done
  13. %% Only diferences re previous version (01)
  14. % Positions between cue and uncued items are uncorrelated
  15. % Gazebo images modified
  16. %% Only diferences re previous version (01_1)
  17. % Detecting whether participant are not looking to the fix cross and adding
  18. % this "null" trials to a final block. (no more than 48 trials)
  19. %% Only diferences re previous version (01_5)
  20. % Adding trials (50%) where after the test for the cued item we ask for the
  21. % uncued item
  22. % Only concrete task
  23. % Adding the possibility of not using pings
  24. % Instead of having a fixation cross, use a fixation DOT
  25. %% Differences compare to Memory_unateended_in_progress
  26. % Optimizing the off screen message
  27. %% Some changes in in progress 02
  28. % (1) Remove pings (although we can leave an option to turn them on again)
  29. % - Here pings are important since we use their onset to check the gaze
  30. % during the delay period. One solution is not showing the object although
  31. % we keep the onset
  32. % (end) Update the output file
  33. % Change the spatial fix threshold (1.5)
  34. % Change the instructions
  35. % FB message closer to the center
  36. % No repetion of null triaLS (NON-FIXED)
  37. % Add a temporal threshold for non-fix messages
  38. % Push back the auditory cue after feedback 500ms
  39. %% Clean workspace and initialize the random number generator
  40. clear all;
  41. rand('state', sum(100*clock)); % Initialize the random number generator
  42. %% Adding PTB pathq
  43. ptb_path
  44. %% Prompt window
  45. prompt = {'Do you want to run a practice with instructions or the real task? (only practice=1; only real task=2)'};
  46. defaults = {'2'};
  47. answer = inputdlg(prompt, 'Practice or real experiment?', 1, defaults);
  48. [supra] = deal(answer{:});
  49. supra = str2num(supra);
  50. % Open a Prompt Window and decoding the answer
  51. prompt = {'Task Version','Using the EEG-Lab PC? (0=no, 1=yes)','New Participant (0=no, 1=yes) ','Participant ID','Gender (M/F/Other)','Age','Righthanded? (0=no, 1=yes)','Stimuli subset (1 to 3)','Using Eye-tracking? (0=No;1=Yes)','Using EEG Triggers? (0=No;1=Yes)','Skip Sync Tests? (0=No;1=Yes)','First trial','Using pings (0=No;1=Yes)','Pings coloset (1 to 6)','Repeating non-fix trials? (0=No;1=Yes)'};
  52. defaults = {mfilename, '1','1','XXX','X','99','1','2','1','0','0','1','0','1','0' };
  53. answer = inputdlg(prompt, 'Experimental Setup Information', 1, defaults);
  54. [taskversion,lab,new_participant,subID, gender, age, righthanded, setofobjects,eyetracking,triggers_on, SkipSyncTests, firstrial, pingsareon, pingcolorset, repnonfixtrial] = deal(answer{:});
  55. age = str2num(age);
  56. righthanded = str2num(righthanded);
  57. eyetracking = str2num(eyetracking);
  58. original_eyetracking=eyetracking;
  59. triggers_on= str2num(triggers_on);
  60. original_triggers_on= triggers_on;
  61. SkipSyncTests =str2num(SkipSyncTests);
  62. setofobjects=str2num(setofobjects);
  63. pingcolorset = str2num(pingcolorset);
  64. firstrial=str2num(firstrial);
  65. new_participant=str2num(new_participant);
  66. lab=str2num(lab);
  67. repnonfixtrial=str2num(repnonfixtrial);
  68. pingsareon=str2num(pingsareon); %Ping on/off
  69. if supra==1
  70. mxsq=1:3;
  71. elseif supra==2
  72. if repnonfixtrial==1
  73. mxsq=4:5;
  74. elseif repnonfixtrial==0
  75. mxsq=4;
  76. end
  77. end
  78. if supra==1
  79. subID=[subID 'pr']
  80. end
  81. fixtrh=70.5;
  82. gazeofftimelim=0.5; %time limits for the eyeoff
  83. %
  84. if new_participant==0
  85. prompt = {'Participants could have a old EDF file. Choose the name for the new EDF file'};
  86. defaults = {'1'};
  87. answer = inputdlg(prompt, 'Experimental Setup Information', 1, defaults);
  88. [subID_neo] = deal(answer{:});
  89. end
  90. %% Screen setup
  91. % Background color: cho ose a number from 0 (black) to 255 (white)
  92. backgroundColor = 128;
  93. clear screen
  94. if SkipSyncTests
  95. Screen('Preference', 'SkipSyncTests', 1) %%% IMPORTANT!!
  96. end
  97. whichScreen = max(Screen('Screens'));
  98. if lab
  99. [window1, rect] = Screen('Openwindow',whichScreen,backgroundColor,[],[],2);
  100. else
  101. [window1, rect] = Screen('Openwindow',whichScreen,backgroundColor,[0 0 800 600],[],2);
  102. end
  103. slack = Screen('GetFlipInterval', window1)/2;
  104. W=rect(RectRight); % screen width
  105. H=rect(RectBottom); % screen height
  106. % Get the centre coordinate of the window
  107. [xCenter, yCenter] = RectCenter(rect);
  108. Screen(window1,'FillRect',backgroundColor);
  109. HideCursor(window1);
  110. Screen('Flip', window1);
  111. %% Preparing Eyelink - Eye Tracking
  112. if eyetracking==1
  113. dummymode=0;
  114. % STEP 2
  115. % Provide Eyelink with details about the graphics environment
  116. % and perform some initializations. The information is returned
  117. % in a structure that also contains useful defaults
  118. % and control codes (e.g. tracker state bit and Eyelink key values).
  119. el=EyelinkInitDefaults(window1);
  120. % STEP 3
  121. % Initialization of the connection with the Eyelink Gazetracker.
  122. % exit program if this fails.
  123. if ~EyelinkInit(dummymode)
  124. fprintf('Eyelink Init aborted.\n');
  125. end
  126. [v vs]=Eyelink('GetTrackerVersion');
  127. fprintf('Running experiment on a ''%s'' tracker.\n', vs );
  128. % open file for recording data
  129. if new_participant
  130. edfFile=[subID '.edf'];
  131. Eyelink('Openfile', edfFile);
  132. else
  133. edfFile=[subID_neo '.edf'];
  134. Eyelink('Openfile', edfFile);
  135. end
  136. % STEP 4
  137. % Do setup and calibrate the eye tracker
  138. EyelinkDoTrackerSetup(el);
  139. Eyelink('command', 'calibration_area_proportion = 0.45 0.45');
  140. Eyelink('command', 'calibration_validation_proportion = 0.45 0.45');
  141. % do a final check of calibration using driftcorrection
  142. % You have to hit esc before return.
  143. EyelinkDoDriftCorrection(el);
  144. % STEP 5
  145. % Start recording eye position
  146. Eyelink('StartRecording');
  147. % record a few samples before we actually start displaying
  148. WaitSecs(0.5);
  149. else
  150. edfFile=[];
  151. end
  152. %% Checking keyboard, screens, audio, and adding others settings (e.g. timing) for the experiment
  153. settings_memoreye_unattended_inprogress;
  154. %% Open the serial port (Triggers)
  155. if triggers_on
  156. TB = IOPort('OpenSerialPort','COM4'); % in the lab x=4
  157. else
  158. TB =[];
  159. end
  160. %% Run the task
  161. % time of start of experiment and date
  162. trigger_beginning_end=245;
  163. ExpStart = GetSecs;
  164. today = date;
  165. barColor=[100 100 100]
  166. % Counter for interblock message accuracy
  167. accuracy_con= [];
  168. accuracy_abs= [];
  169. for maxiblock=mxsq; %3 first miniblocks of practices and then the task
  170. % PLAY SOUND (here trig is a sound signal)
  171. % 1) fill the buffer
  172. PsychPortAudio('FillBuffer', pahandle,(audtest)');
  173. % 2) play it
  174. PsychPortAudio('Start', pahandle, repetitions, startCue);
  175. % 3) Stop when it's done playing
  176. PsychPortAudio('Stop', pahandle,1);
  177. if maxiblock==1 %first block of practice
  178. sequence=sequencepract1;
  179. practice=1;
  180. % eyetracking=0;
  181. triggers_on=0;
  182. imageFolder_in = 'instructions/one';
  183. imgList_in = dir(fullfile(imageFolder_in,['*.jpg']));
  184. imgList_in = {imgList_in(:).name};
  185. showingslides(imgList_in,imageFolder_in,window1,W,H,backgroundColor,responseKeys)
  186. elseif maxiblock==2
  187. sequence=sequencepract2;
  188. practice=1;
  189. % eyetracking=0;
  190. triggers_on=0;
  191. imageFolder_in = 'instructions/two';
  192. imgList_in = dir(fullfile(imageFolder_in,['*.jpg']));
  193. imgList_in = {imgList_in(:).name};
  194. showingslides(imgList_in,imageFolder_in,window1,W,H,backgroundColor,responseKeys)
  195. elseif maxiblock==3
  196. sequence=sequencepract3;
  197. practice=1;
  198. % eyetracking=0;
  199. triggers_on=0;
  200. imageFolder_in = 'instructions/three';
  201. imgList_in = dir(fullfile(imageFolder_in,['*.jpg']));
  202. imgList_in = {imgList_in(:).name};
  203. showingslides(imgList_in,imageFolder_in,window1,W,H,backgroundColor,responseKeys)
  204. elseif maxiblock==4 %real task
  205. sequencenull=[] %Sequence of null trials
  206. sequence=sequence_real;
  207. practice=0;
  208. if original_eyetracking % Restore eyetracking on/off to original (to send triggers)
  209. eyetracking=1;
  210. else
  211. eyetracking=0;
  212. end
  213. if original_triggers_on % Restore triggers on/off to original
  214. triggers_on=1;
  215. else
  216. triggers_on=0;
  217. end
  218. press_trigger(trigger_beginning_end,TB,triggers_on);
  219. press_eyelink_trigger(trigger_beginning_end,eyetracking)
  220. % First Message
  221. Screen(window1, 'FillRect', backgroundColor);
  222. Screen('TextSize',window1,18);
  223. msg=['Welcome to the experiment'];
  224. DrawFormattedText(window1, msg, 'center', (H/4.5), textColor);
  225. DrawFormattedText(window1, '[Press the space bar to start]', 'center', (H/1.5), textColor);
  226. overviewTime = Screen('Flip',window1)-ExpStart; % first screen time
  227. Screen('TextSize',window1,40);
  228. % PLAY SOUND (here trig is a sound signal)
  229. % 1) fill the buffer
  230. PsychPortAudio('FillBuffer', pahandle,(audtest)');
  231. % 2) play it
  232. PsychPortAudio('Start', pahandle, repetitions, startCue);
  233. % 3) Stop when it's done playing
  234. PsychPortAudio('Stop', pahandle,1);
  235. % Wait for subject to press spacebar
  236. while 1
  237. [keyIsDown,secs,keyCode] = KbCheck;
  238. if keyCode(KbName('space'))==1
  239. break
  240. end
  241. end
  242. elseif maxiblock==5 %repeating null trials (fix point)
  243. %randomize the sequencenull
  244. sequencenull=sequencenull(randperm(size(sequencenull,1)),:)
  245. sequencenull(:,10)=nblocks+1; %and put the same number for the blocks
  246. if size(sequencenull,1)>48 %Maximum trials to repeat
  247. sequencenull=sequencenull(1:48,:)
  248. end
  249. sequence=sequencenull;
  250. practice=0;
  251. firstrial=1;
  252. if original_eyetracking % Restore eyetracking on/off to original (to send triggers)
  253. eyetracking=1;
  254. else
  255. eyetracking=0;
  256. end
  257. if original_triggers_on % Restore triggers on/off to original
  258. triggers_on=1;
  259. else
  260. triggers_on=0;
  261. end
  262. press_trigger(trigger_beginning_end,TB,triggers_on);
  263. press_eyelink_trigger(trigger_beginning_end,eyetracking)
  264. % First Message
  265. Screen(window1, 'FillRect', backgroundColor);
  266. Screen('TextSize',window1,18);
  267. msg=['Almost done. We will repeat some trials where your gaze was not in the center'];
  268. DrawFormattedText(window1, msg, 'center', (H/4.5), textColor);
  269. DrawFormattedText(window1, '[Press the space bar to start]', 'center', (H/1.5), textColor);
  270. overviewTime = Screen('Flip',window1)-ExpStart; % first screen time
  271. Screen('TextSize',window1,40);
  272. % PLAY SOUND (here trig is a sound signal)
  273. % 1) fill the buffer
  274. PsychPortAudio('FillBuffer', pahandle,(audtest)');
  275. % 2) play it
  276. PsychPortAudio('Start', pahandle, repetitions, startCue);
  277. % 3) Stop when it's done playing
  278. PsychPortAudio('Stop', pahandle,1);
  279. % Wait for subject to press spacebar
  280. while 1
  281. [keyIsDown,secs,keyCode] = KbCheck;
  282. if keyCode(KbName('space'))==1
  283. break
  284. end
  285. end
  286. end
  287. for trial=firstrial:size(sequence,1)
  288. % Parameters for each trial (clarification)
  289. % In Sequence:
  290. % Column 1 = Object 1
  291. % Column 2 = Object 2
  292. % Column 3 = Rotation Object 1
  293. % Column 4 = Rotarion Object 2
  294. % Column 5 = Target: 1 or 2
  295. % Column 6 = Target Object (id)
  296. % Column 7 = Type of task (1= concrete/perceptual; 2=continuous/abstract)
  297. % Column 8 = Object memory test
  298. % Column 9 = Rotation Object memory test
  299. % Column 10 = Block number
  300. % Column 11 = Rotation target
  301. % Column 12 = Testing uncued (True / False)
  302. % Column 13 = Object memory test 2
  303. % Column 14 = Rotation Object memory test 2
  304. % Column 15 = Rotation UNCUED
  305. object_1_id=sequence(trial,1);
  306. object_2_id=sequence(trial,2);
  307. object_1_rot=sequence(trial,3);
  308. object_2_rot=sequence(trial,4);
  309. cue=sequence(trial,5);
  310. type_of_task=sequence(trial,7);
  311. object_test_id=sequence(trial,8);
  312. object_test_rot=sequence(trial,9);
  313. block=sequence(trial,10);
  314. all_rotation = unique(sequence_real(:,3));
  315. object_cue_id=sequence(trial,6);
  316. object_cue_rot=sequence(trial,11);
  317. object_uncued_id=sequence(trial,13);
  318. object_uncued_rot=sequence(trial,15);
  319. pingfixated=zeros(1,8);
  320. pingfixated_2=zeros(1,8);
  321. testinguncued=sequence(trial,12);
  322. object_test_id_uncued=sequence(trial,13);
  323. object_test_rot_uncued=sequence(trial,14);
  324. if trial<size(sequence,1);
  325. next_trial_block=sequence(trial+1,10);
  326. else % we are in the last trial of the experiment, no next block
  327. next_trial_block=block;
  328. end
  329. if cue==1
  330. %object_cue_rot=object_1_rot;
  331. uncue=2;
  332. elseif cue==2
  333. % object_cue_rot=object_2_rot;
  334. uncue=1
  335. end
  336. Onset_ping=NaN(1,10); % (creating a vector to include up to 10 pings onsets in the outputfile)
  337. Onset_ping_2=NaN(1,10); % (creating a vector to include up to 10 pings onsets in the outputfile)
  338. %% Trigger info (EEG and Eye-Tracking)
  339. % % Changes: Gaze-off triggers removed (this info is included in the
  340. % output file). Triggers for "Thanks" messages included.
  341. % % -orientations (1:16): 001:1:016
  342. % % -sample item code (1:3): 20:20:60
  343. % % -1st/2nd sample position: 000/100
  344. % %
  345. % % i.e. item 2 at 45?? in first sample position would be 42; in 2nd sample position t would be 142
  346. % %
  347. % % - first retrocue: 1/2 (first or second item respectively)
  348. % % - second retrocue (for the uncued item): 3/4 (first or second item respectively)
  349. % %
  350. % % - thanks message after test for the CUED item: 5
  351. % % - thanks message after test for the UNCUED item: 6
  352. % %
  353. % % -Object onset in abstract test for the CUED item: 201:209 (object identity from 1 to 9)
  354. % % -Object onset in abstract test for the UNCUED item: 211:219 (object identity from 1 to 9)
  355. % %
  356. % % -Object onset in concrete test for the CUED item: 220/221 (for left/right tilted)
  357. % % -Object onset in concrete test for the UNCUED item: 223/224 (for left/right tilted)
  358. % %
  359. % % -230 Ping - First delay
  360. % % -231 Oddball Ping - First delay
  361. % %
  362. % % -232 Ping - Second delay
  363. % % -233 Oddball - Second delay
  364. % %
  365. % % -241 left button press
  366. % % -242 right button press
  367. % % -243 up/accept button press
  368. % % -244 feedback cued item
  369. % % -245 feedback uncued item
  370. % %
  371. % % -246 beginning/end of the task
  372. %% IMPORTANT - MODIFIED BASED ON THE PREVIOUS LIST
  373. trigger_object_1 = (find(object_1_rot==all_rotation))+(object_1_id*20)
  374. trigger_object_2 = (find(object_2_rot==all_rotation))+(object_2_id*20)+100
  375. trigger_retrocue = cue;
  376. trigger_retrocue_2 = uncue+2;
  377. trigger_thanks = 5;
  378. trigger_thanks_2 = 6;
  379. trigger_taskcue = NaN; %not used here
  380. %To remove
  381. % trigger_object_1_null=100;
  382. % trigger_object_2_null=200;
  383. % trigger_ping_null=232
  384. degdiff=angdiff(deg2rad(object_cue_rot),deg2rad(object_test_rot)); % angular difference
  385. degdiff=rad2deg(degdiff);
  386. trigger_object_concrete= 220+(degdiff>0);
  387. trigger_object_abstract=object_test_id+200;
  388. trigger_object_concrete_uncued= 222+(degdiff>0);
  389. trigger_object_abstract_uncued=object_test_id+210;
  390. trigger_ping=230;
  391. trigger_odd_ping=231;
  392. trigger_ping_2=232;
  393. trigger_odd_ping_2=233;
  394. trigger_left_key=241;
  395. trigger_right_key=242;
  396. trigger_up_key=243;
  397. trigger_feedback=244;
  398. trigger_feedback_uncued=245;
  399. trigger_beginning_end=246;
  400. %% Pre-load stimuli and other settings
  401. bth=254% treshold to subtitute for background
  402. sc_o=(10000/W)*1.4;
  403. %Object 1
  404. file_object_1 = imgList{object_1_id};
  405. img_object_1 = imread(fullfile(imageFolder ,file_object_1));
  406. img_object_1((img_object_1>=bth))=backgroundColor; %REMOVING BACKGROUND FOR EACH IMAGE
  407. objectDisplay_1 = Screen('MakeTexture', window1, img_object_1);
  408. % Calculate image position (center of the screen) OBJECT 1
  409. imageSize_o1 = size(img_object_1)/sc_o;
  410. pos_o1 = [(W-imageSize_o1(2))/2 (H-imageSize_o1(1))/2 (W+imageSize_o1(2))/2 (H+imageSize_o1(1))/2];
  411. %Object 2
  412. file_object_2 = imgList{object_2_id};
  413. img_object_2 = imread(fullfile(imageFolder ,file_object_2));
  414. img_object_2((img_object_2>=bth))=backgroundColor; %REMOVING BACKGROUND FOR EACH IMAGE
  415. objectDisplay_2 = Screen('MakeTexture', window1, img_object_2);
  416. % Calculate image position (center of the screen) OBJECT 2
  417. imageSize_o2 = size(img_object_2)/sc_o;
  418. pos_o2 = [(W-imageSize_o2(2))/2 (H-imageSize_o2(1))/2 (W+imageSize_o2(2))/2 (H+imageSize_o2(1))/2];
  419. %Object Memory Test (we will use a difference object for the
  420. %abstract task)
  421. if type_of_task==2
  422. file_object_t = imgList_test{object_test_id};
  423. img_object_t = imread(fullfile(imageFolder_test ,file_object_t));
  424. img_object_t((img_object_t>=bth))=backgroundColor; %REMOVING BACKGROUND FOR EACH IMAGE
  425. objectDisplay_test = Screen('MakeTexture', window1, img_object_t);
  426. else
  427. file_object_t = imgList{object_test_id};
  428. img_object_t = imread(fullfile(imageFolder,file_object_t));
  429. img_object_t((img_object_t>=bth) )=backgroundColor ; %REMOVING BACKGROUND FOR EACH IMAGE
  430. objectDisplay_test = Screen('MakeTexture', window1, img_object_t);
  431. proof=img_object_t;proof(:,:,1)=proof(:,:,1)./1.5;proof(:,:,3)=proof(:,:,3)./1.5;
  432. proof((img_object_t==backgroundColor) )=backgroundColor ; %REMOVING BACKGROUND FOR EACH IMAGE
  433. objectDisplay_test_green = Screen('MakeTexture', window1, proof);
  434. proof=img_object_t;proof(:,:,2)=proof(:,:,2)./1.5;proof(:,:,3)=proof(:,:,3)./1.5;
  435. proof((img_object_t==backgroundColor))=backgroundColor ; %REMOVING BACKGROUND FOR EACH IMAGE
  436. objectDisplay_test_red = Screen('MakeTexture', window1, proof);
  437. file_object_t_uncued = imgList{object_test_id_uncued};
  438. img_object_t_uncued = imread(fullfile(imageFolder,file_object_t_uncued));
  439. img_object_t_uncued((img_object_t_uncued>=bth) )=backgroundColor ; %REMOVING BACKGROUND FOR EACH IMAGE
  440. objectDisplay_test_uncued = Screen('MakeTexture', window1, img_object_t_uncued);
  441. end
  442. % Calculate image position (center of the screen) OBJECT TEST
  443. imageSize_ot = size(img_object_t)/sc_o;
  444. pos_ot = [(W-imageSize_ot(2))/2 (H-imageSize_ot(1))/2 (W+imageSize_ot(2))/2 (H+imageSize_ot(1))/2];
  445. %Setting the position of the oddball ping
  446. %Calcularing the time gap between pings
  447. pausvec=pingT(npings,nodd,delth,pilth,minipi,maxsend,minstart)
  448. odvec=[zeros(1,npings-nodd) ones(1,nodd)]; % vector defining which ping is an oddball
  449. oddpingpos=odvec(randperm(npings));
  450. %Calcularing the time gap between pings for the SECOND delay
  451. pausvec_2=pingT(npings_2,nodd_2,delth_2,pilth_2,minipi_2,maxsend_2,minstart_2)
  452. odvec_2=[zeros(1,npings_2-nodd_2) ones(1,nodd_2)]; % vector defining which ping is an oddball
  453. oddpingpos_2=odvec_2(randperm(npings_2));
  454. %% Showing OBJECT 1
  455. objectodisplay=objectDisplay_1;
  456. rottodisplay=object_1_rot;
  457. positiontodisplay=pos_o1;
  458. OnsetResp=0;
  459. rt_catch = 0;
  460. resp_text = 0;
  461. resp_catch = 'No_Response'; %Just in case we don't have response
  462. % Screen priority
  463. Priority(MaxPriority(window1));
  464. Priority(2);
  465. if eyetracking==1 % Before 'Flip' check whether the eyes are well fixated to change the trigger id
  466. eyesin=0;
  467. eyesout=0;
  468. eyes_were_out=0;
  469. too=[];
  470. %if eyes are not fixated, the trial will not start
  471. while eyesin==0
  472. too(1) = gazein(W,H,fixtrh,gazeofftimelim,0);
  473. too(1)
  474. if too(1)==1
  475. eyesin=1;
  476. elseif too(1)==0
  477. eyes_were_out=1;
  478. end
  479. end
  480. end
  481. %If eyes were not fixated before the trial start (time lenght
  482. %defined by fixationDuration)
  483. if eyes_were_out
  484. drawDot(window1,W,H,barColor);
  485. tFixation = Screen('Flip', window1);
  486. Screen(window1, 'FillRect', backgroundColor);
  487. Screen('Flip', window1, tFixation + (fixationDuration - slack),0) %Adding between 0 and 0.5 second randomly to the minimum for the fixation duration
  488. Screen('TextSize',window1,40);
  489. DrawFormattedText(window1, 'FIXATE!', 'center', 'center', [200 0 0]);
  490. end
  491. % Show fixation cross
  492. drawDot(window1,W,H,barColor);
  493. tFixation = Screen('Flip', window1);
  494. Screen(window1, 'FillRect', backgroundColor);
  495. Screen('Flip', window1, tFixation + (fixationDuration + (rand(1)/2))- slack,0) %Adding between 0 and 0.5 second randomly to the minimum for the fixation duration
  496. % Show Object 1
  497. Screen('DrawTexture', window1, objectodisplay, [], positiontodisplay,rottodisplay);
  498. drawDot(window1,W,H,barColor); %Fixcross on top
  499. object_1_fixated=0; %eye centered
  500. if eyetracking==1 % Before 'Flip' check whether the eyes are well fixated to change the trigger id
  501. object_1_fixated = gazeoff(W,H,fixtrh,gazeofftimelim,0);
  502. end
  503. startTime = Screen('Flip', window1); % Start of trial
  504. Onset_object_1 = startTime-ExpStart; %Onset
  505. tdel=press_trigger(trigger_object_1,TB,triggers_on);
  506. press_eyelink_trigger(trigger_object_1,eyetracking)
  507. startout=[];
  508. while (GetSecs - startTime) < objectTimeout - tdel - slack
  509. [keyIsDown,secs,keyCode] = KbCheck;
  510. % ESC key quits the experiment
  511. if keyCode(KbName('Q')) == 1
  512. endexperiment(window1,pahandle,outputfile,triggers_on,TB,trigger_beginning_end,eyetracking,edfFile)
  513. end
  514. respTime = GetSecs;
  515. pressedKeys = find(keyCode);
  516. % Check for response keys
  517. if ~isempty(pressedKeys)
  518. for i = 1:length(responseKeys)
  519. if KbName(responseKeys{i}) == pressedKeys(1)
  520. break
  521. end
  522. end
  523. end
  524. if eyetracking==1
  525. nnf(1) = gazeoff(W,H,fixtrh,gazeofftimelim,0);
  526. if nnf(1)==0
  527. continue
  528. end
  529. startout=[startout GetSecs];
  530. if startout(end)-startout(1)>gazeofftimelim %pingfixated(1) %Eyes not fixated!
  531. object_1_fixated=1;
  532. end
  533. end
  534. end
  535. % Empty screen between object offset and next fix cross
  536. % Screen priority
  537. Priority(MaxPriority(window1));
  538. Priority(2);
  539. Screen(window1, 'FillRect', backgroundColor);
  540. Screen('Flip', window1 )
  541. while (GetSecs - startTime) < postobjectTimeout1 - slack
  542. % ESC key quits the experiment
  543. if keyCode(KbName('Q')) == 1
  544. endexperiment(window1,pahandle,outputfile,triggers_on,TB,trigger_beginning_end,eyetracking,edfFile)
  545. end
  546. [keyIsDown,secs,keyCode] = KbCheck;
  547. respTime = GetSecs;
  548. pressedKeys = find(keyCode);
  549. % Check for response keys
  550. if ~isempty(pressedKeys)
  551. for i = 1:length(responseKeys)
  552. if KbName(responseKeys{i}) == pressedKeys(1)
  553. resp_catch = responseKeys{i};
  554. rt_catch = respTime - startTime;
  555. OnsetResp = GetSecs - ExpStart;
  556. break
  557. end
  558. end
  559. end
  560. end
  561. %% Showing OBJECT 2
  562. objectodisplay=objectDisplay_2;
  563. rottodisplay=object_2_rot;
  564. positiontodisplay=pos_o2;
  565. OnsetResp=0;
  566. rt_catch = 0;
  567. resp_text = 0;
  568. resp_catch = 'No_Response'; %Just in case we don't have response
  569. % Screen priority
  570. Priority(MaxPriority(window1));
  571. Priority(2);
  572. % Show fixation cross
  573. Screen(window1, 'FillRect', backgroundColor);
  574. drawDot(window1,W,H,barColor);
  575. % %If eyes were not fixated in object 1
  576. % if object_1_fixated
  577. % Screen('TextSize',window1,40);
  578. % DrawFormattedText(window1, 'FIXATE!', 'center', 'center', [200 0 0]);
  579. % end
  580. tFixation = Screen('Flip', window1);
  581. Screen('Flip', window1, tFixation + (fixationDuration)- slack,0)
  582. % Show Object 2
  583. Screen('DrawTexture', window1, objectodisplay, [], positiontodisplay,rottodisplay);
  584. drawDot(window1,W,H,barColor); %Fixcross on top
  585. object_2_fixated=0; %eye centered
  586. if eyetracking==1 % Before 'Flip' check whether the eyes are well fixated to change the trigger id
  587. object_2_fixated = gazeoff(W,H,fixtrh,gazeofftimelim,0);
  588. end
  589. startTime = Screen('Flip', window1); % Start of trial
  590. Onset_object_2 = startTime-ExpStart; %Onset
  591. tdel=press_trigger(trigger_object_2,TB,triggers_on);
  592. press_eyelink_trigger(trigger_object_2,eyetracking)
  593. startout=[];
  594. while (GetSecs - startTime)< objectTimeout - tdel - slack
  595. [keyIsDown,secs,keyCode] = KbCheck;
  596. % ESC key quits the experiment
  597. if keyCode(KbName('Q')) == 1
  598. endexperiment(window1,pahandle,outputfile,triggers_on,TB,trigger_beginning_end,eyetracking,edfFile)
  599. end
  600. respTime = GetSecs;
  601. pressedKeys = find(keyCode);
  602. % Check for response keys
  603. if ~isempty(pressedKeys)
  604. for i = 1:length(responseKeys)
  605. if KbName(responseKeys{i}) == pressedKeys(1)
  606. break
  607. end
  608. end
  609. end
  610. if eyetracking==1
  611. nnf(1) = gazeoff(W,H,fixtrh,gazeofftimelim,0);
  612. if nnf(1)==0
  613. continue
  614. end
  615. startout=[startout GetSecs];
  616. if startout(end)-startout(1)>gazeofftimelim %pingfixated(1) %Eyes not fixated!
  617. object_2_fixated=1;
  618. end
  619. end
  620. end
  621. % Empty screen between object offset and next fix cross
  622. % Screen priority
  623. Priority(MaxPriority(window1));
  624. Priority(2);
  625. Screen(window1, 'FillRect', backgroundColor);
  626. drawDot(window1,W,H,barColor); %Fixcross on top
  627. %If eyes were not fixated in object 2
  628. if object_2_fixated
  629. Screen('TextSize',window1,40);
  630. DrawFormattedText(window1, 'FIXATE!', 'center', 'center', [200 0 0]);
  631. end
  632. startTime = Screen('Flip', window1 )
  633. while (GetSecs - startTime)< postobjectTimeout2 - slack
  634. % ESC key quits the experiment
  635. if keyCode(KbName('Q')) == 1
  636. endexperiment(window1,pahandle,outputfile,triggers_on,TB,trigger_beginning_end,eyetracking,edfFile)
  637. end
  638. [keyIsDown,secs,keyCode] = KbCheck;
  639. respTime = GetSecs;
  640. pressedKeys = find(keyCode);
  641. % Check for response keys
  642. if ~isempty(pressedKeys)
  643. for i = 1:length(responseKeys)
  644. if KbName(responseKeys{i}) == pressedKeys(1)
  645. resp_catch = responseKeys{i};
  646. rt_catch = respTime - startTime;
  647. OnsetResp = GetSecs - ExpStart;
  648. break
  649. end
  650. end
  651. end
  652. end
  653. %% Showing retro cue (sounds)
  654. % Screen priority
  655. Priority(MaxPriority(window1));
  656. Priority(2);
  657. % Show fixation cross
  658. drawDot(window1,W,H,barColor);
  659. startTime = Screen('Flip', window1);
  660. Onset_retrocue = startTime-ExpStart; %Onset
  661. press_trigger(trigger_retrocue,TB,triggers_on);
  662. press_eyelink_trigger(trigger_retrocue,eyetracking)
  663. % % % % Show retro cue (visual)
  664. % % %
  665. % % % % Screen('Flip', window1, tFixation + (fixationDuration + rand(1))- slack,0) %Adding between 0 and 1 second randomly to the minimum for the fixation duration
  666. % % % %
  667. % % % %
  668. % % % % Screen('TextSize',window1,60);
  669. % % % % DrawFormattedText(window1, num2str(cue), 'center', 'center', [255 255 255]);
  670. % % % %
  671. % % % % startTimePing = Screen('Flip',window1)-ExpStart; % first screen time
  672. % Presenting retro cue with audio
  673. % PLAY SOUND (here trig is a sound signal)
  674. % 1) fill the buffer
  675. PsychPortAudio('FillBuffer', pahandle,(audcue{cue})');
  676. % 2) play it
  677. PsychPortAudio('Start', pahandle, repetitions, startCue);
  678. % 3) Stop when it's done playing
  679. PsychPortAudio('Stop', pahandle,1);
  680. % WaitSecs(audiogap)
  681. %% Presenting task cue (sounds)
  682. % if type_of_task==1
  683. % taskmessage='photo'
  684. % audio=aud1;
  685. % else
  686. % taskmessage='rotation'
  687. % audio=aud2;
  688. %
  689. % end
  690. % % Screen priority
  691. % Priority(MaxPriority(window1));
  692. % Priority(2);
  693. %
  694. % % Show fixation cross
  695. % Screen(window1, 'FillRect', backgroundColor);
  696. % drawDot(window1,W,H,barColor);
  697. % startTime = Screen('Flip', window1);
  698. % press_trigger(trigger_taskcue,TB,triggers_on);
  699. % press_eyelink_trigger(trigger_taskcue,eyetracking)
  700. %
  701. % % % %
  702. % % % % Screen('Flip', window1, tFixation + (fixationDuration + rand(1))- slack,0) %Adding between 0 and 1 second randomly to the minimum for the fixation duration
  703. % % % % Screen(window1, 'FillRect', backgroundColor);
  704. % % %
  705. % % % % % Show task cue (visual
  706. % % %
  707. % % % % Screen('TextSize',window1,60);
  708. % % % % DrawFormattedText(window1, taskmessage, 'center', 'center', [255 255 255]);
  709. % % % %
  710. % % % % startTimePing = Screen('Flip',window1)-ExpStart; % first screen time
  711. %
  712. % % Presenting task cue with audio
  713. %
  714. % % PLAY SOUND (here trig is a sound signal)
  715. % % 1) fill the buffer
  716. % PsychPortAudio('FillBuffer', pahandle,(audtaskcue{type_of_task})');
  717. % % 2) play it
  718. % PsychPortAudio('Start', pahandle, repetitions, startCue);
  719. %
  720. % % 3) Stop when it's done playing
  721. % PsychPortAudio('Stop', pahandle,1);
  722. %
  723. % Onset_taskcue = startTime-ExpStart; %Onset
  724. %
  725. %% Showing the Pings (if the option is on)
  726. if pingsareon % Draw the pings if the variable pingsareon is 1
  727. for pings=1:size(oddpingpos,2) %How many pings
  728. %In this example the oddball will be a different color for the
  729. %text
  730. if oddpingpos(pings)==1
  731. rectColor_s=rectColor_odd;
  732. trigger_ping_selected=trigger_odd_ping
  733. else
  734. rectColor_s=rectColor;
  735. trigger_ping_selected=trigger_ping
  736. end
  737. % Screen priority
  738. Priority(MaxPriority(window1));
  739. Priority(2);
  740. % Show fixation cross
  741. Screen(window1, 'FillRect', backgroundColor);
  742. drawDot(window1,W,H,barColor);
  743. tFixation = Screen('Flip', window1);
  744. %Duration of fix cross is based on "pausvec"
  745. Screen('Flip', window1, tFixation + (pausvec(pings)/1000)- slack,0) %Adding time to the minimum for the fixation duration
  746. Screen('FillOval', window1, rectColor_s{1}, centeredRect1, maxDiameter1);
  747. Screen('FillOval', window1, rectColor_s{2}, centeredRect2, maxDiameter2);
  748. Screen('FillOval', window1, rectColor_s{3}, centeredRect3, maxDiameter3);
  749. Screen('FillOval', window1, rectColor_s{4}, centeredRect4, maxDiameter4);
  750. Screen('FillOval', window1, rectColor_s{5}, centeredRect5, maxDiameter5);
  751. drawDot(window1,W,H,barColor); %Fixcross on top
  752. pingfixated(pings)=0; %eye centered
  753. if eyetracking==1 % Before 'Flip' check whether the eyes are well fixated to change the trigger id
  754. pingfixated(pings) = gazeoff(W,H,fixtrh,gazeofftimelim,0);
  755. if pingfixated(pings)
  756. Screen('TextSize',window1,40);
  757. DrawFormattedText(window1, 'FIXATE!', 'center', 'center', [200 0 0]);
  758. end
  759. end
  760. % Flip to the screen
  761. startTime = Screen('Flip', window1);
  762. tdel=press_trigger(trigger_ping_selected,TB,triggers_on);
  763. press_eyelink_trigger(trigger_ping_selected,eyetracking)
  764. Onset_ping(pings) = startTime-ExpStart;
  765. startout=[];
  766. while GetSecs - startTime < ((pilth/1000)-tdel - slack)
  767. if eyetracking==1
  768. nnf(1) = gazeoff(W,H,fixtrh,gazeofftimelim,0);
  769. if nnf(1)==0
  770. continue
  771. end
  772. startout=[startout GetSecs];
  773. if startout(end)-startout(1)>gazeofftimelim %pingfixated(1) %Eyes not fixated!
  774. pingfixated(pings)=1;
  775. Screen('TextSize',window1,40);
  776. DrawFormattedText(window1, 'FIXATE!', 'center', 'center', [200 0 0]);
  777. startTimeFiXM =Screen('Flip', window1)
  778. end
  779. end
  780. end
  781. end
  782. else %if PINGS are off
  783. startout=[];
  784. % Screen priority
  785. Priority(MaxPriority(window1));
  786. Priority(2);
  787. % Show fixation cross
  788. Screen(window1, 'FillRect', backgroundColor);
  789. drawDot(window1,W,H,barColor);
  790. startTimeA = Screen('Flip', window1);
  791. while GetSecs - startTimeA < ((delth/1000)-(pausvec(end)/1000)- slack) % During the time of the delay period
  792. if eyetracking==1
  793. nnf(1) = gazeoff(W,H,fixtrh,gazeofftimelim,0);
  794. if nnf(1)==0
  795. continue
  796. end
  797. startout=[startout GetSecs];
  798. if startout(end)-startout(1)>gazeofftimelim %pingfixated(1) %Eyes not fixated!
  799. pingfixated(1)=1;
  800. Screen('TextSize',window1,40);
  801. DrawFormattedText(window1, 'FIXATE!', 'center', 'center', [200 0 0]);
  802. startTimeFiXM =Screen('Flip', window1)
  803. end
  804. end
  805. end
  806. end
  807. %% Showing OBJECTs for Memory test (Discrete/perceptual task)
  808. if type_of_task==1
  809. acc_trial_concrete=NaN;
  810. OnsetResp=0;
  811. rt_resp_concrete = 0;
  812. resp_text = 0;
  813. resp = 'No_Response'; %Just in case we don't have response
  814. rotationAngle_test=object_test_rot;
  815. finalrot_concrete=NaN;
  816. % Screen priority
  817. Priority(MaxPriority(window1));
  818. Priority(2);
  819. % Show fixation cross
  820. drawDot(window1,W,H,barColor);
  821. tFixation = Screen('Flip', window1);
  822. Screen(window1, 'FillRect', backgroundColor);
  823. Screen('Flip', window1, tFixation + (pausvec(end)/1000)- slack,0) %Adding between 0 and 1 second randomly to the minimum for the fixation duration
  824. % Show Object
  825. Screen('TextSize',window1,18);
  826. DrawFormattedText(window1, 'Press <- or -> to CHOOSE the right direction', 'center', (H/4.5), textColor);
  827. Screen('DrawTexture', window1, objectDisplay_test, [], pos_ot,rotationAngle_test);
  828. startTime_test = Screen('Flip', window1); % Start of trial
  829. press_trigger(trigger_object_concrete,TB,triggers_on);
  830. press_eyelink_trigger(trigger_object_concrete,eyetracking)
  831. Onset_object_pt = startTime-ExpStart; %Onset
  832. Onset_test = startTime_test-ExpStart; %Onset
  833. responsetimeout=0;
  834. stop=1;
  835. while stop % GetSecs - startTime < objectTimeout
  836. [keyIsDown,secs,keyCode] = KbCheck;
  837. % ESC key quits the experiment
  838. if keyCode(KbName('Q')) == 1
  839. endexperiment(window1,pahandle,outputfile,triggers_on,TB,trigger_beginning_end,eyetracking,edfFile)
  840. end
  841. respTime = GetSecs;
  842. pressedKeys = find(keyCode);
  843. % Check for response keys
  844. if ~isempty(pressedKeys)
  845. for i = 2:3
  846. if KbName(responseKeys{i}) == pressedKeys(1)
  847. resp = responseKeys{i};
  848. rt_resp_concrete= respTime - startTime_test;
  849. OnsetResp = GetSecs - ExpStart;
  850. if keyCode(KbName('RightArrow')) == 1
  851. press_trigger(trigger_right_key,TB,triggers_on);
  852. press_eyelink_trigger(trigger_right_key,eyetracking)
  853. elseif keyCode(KbName('LeftArrow')) == 1
  854. press_trigger(trigger_left_key,TB,triggers_on);
  855. press_eyelink_trigger(trigger_left_key,eyetracking)
  856. end
  857. break
  858. end
  859. end
  860. end
  861. if rt_resp_concrete > 0
  862. stop=0;
  863. break
  864. elseif (GetSecs - startTime_test > concreteTimeout - slack)
  865. stop=0;
  866. responsetimeout=1;
  867. end
  868. end
  869. % Showing the move
  870. if keyCode(KbName('RightArrow')) == 1
  871. Screen('TextSize',window1,18);
  872. DrawFormattedText(window1, 'Press <- or -> to CHOOSE the right direction', 'center', (H/4.5), textColor);
  873. Screen('DrawTexture', window1, objectDisplay_test, [], pos_ot,rotationAngle_test+distrot/contestdif);
  874. startTime = Screen('Flip', window1); % Start of trial
  875. Onset_object_pt = startTime-ExpStart; %Onset
  876. finalrot_concrete=rotationAngle_test+distrot/contestdif;
  877. end
  878. if keyCode(KbName('LeftArrow')) == 1
  879. Screen('TextSize',window1,18);
  880. DrawFormattedText(window1, 'Press <- or -> to CHOOSE the right direction', 'center', (H/4.5), textColor);
  881. Screen('DrawTexture', window1, objectDisplay_test, [], pos_ot,rotationAngle_test-distrot/contestdif);
  882. startTime = Screen('Flip', window1); % Start of trial
  883. Onset_object_pt = startTime-ExpStart; %Onset
  884. finalrot_concrete=rotationAngle_test-distrot/contestdif;
  885. end
  886. WaitSecs(fbrespcon)
  887. %% Feedback Concrete using images
  888. %Obtaining right answer
  889. if responsetimeout
  890. fb_message= (['Try to respond faster'])
  891. acc_trial_concrete=2;
  892. textColor_fb=[255 0 0]
  893. else
  894. degdiff=angdiff(deg2rad(object_cue_rot),deg2rad(object_test_rot)); % angular difference
  895. degdiff=rad2deg(degdiff)
  896. if degdiff<0
  897. corr_r='R'
  898. else
  899. corr_r='L'
  900. end
  901. %Preparing FB message
  902. if resp(1)==corr_r
  903. fb_message = 'correct'
  904. accuracy_con=[accuracy_con 1];
  905. acc_trial_concrete=1;
  906. objectDisplay_fb=objectDisplay_test_green;
  907. textColor_fb=[0 255 100]
  908. else
  909. fb_message = 'incorrect'
  910. accuracy_con=[accuracy_con 0];
  911. acc_trial_concrete=0;
  912. objectDisplay_fb=objectDisplay_test_red;
  913. textColor_fb=[255 0 0]
  914. end
  915. end
  916. Screen('TextSize',window1,20);
  917. DrawFormattedText(window1, fb_message, 'center', (H/4.5), textColor_fb);
  918. Screen('DrawTexture', window1, objectDisplay_test,[], pos_ot,object_cue_rot,1,0.9);
  919. startTime=Screen('Flip', window1); % Start of feedback
  920. Onset_feedback = startTime-ExpStart; %Onset
  921. press_trigger(trigger_feedback,TB,triggers_on);
  922. press_eyelink_trigger(trigger_feedback,eyetracking)
  923. WaitSecs(fbtimeoutcon- slack)
  924. end
  925. %% Showing OBJECTs for Memory test (Abstract task)
  926. if type_of_task==2
  927. OnsetResp=0;
  928. rt_resp_abstract = 0;
  929. rt_resp_abstract_ini = [];
  930. resp_text = 0;
  931. resp_catch = 'No_Response'; %Just in case we don't have response
  932. rotationAngle_test=object_test_rot;
  933. Onset_movl=0;
  934. rotFac=1;
  935. responsetimeout=0;
  936. % Screen priority
  937. Priority(MaxPriority(window1));
  938. Priority(2);
  939. % Show fixation cross
  940. drawDot(window1,W,H,barColor);
  941. tFixation = Screen('Flip', window1);
  942. Screen(window1, 'FillRect', backgroundColor);
  943. Screen('Flip', window1, tFixation + ( pausvec(end)/1000)- slack,0) %Adding between 0 and 1 second randomly to the minimum for the fixation duration
  944. % Show Object
  945. Screen('TextSize',window1,18);
  946. DrawFormattedText(window1, ['Press <- or -> to ROTATE; press ' keytoaccepabs ' to accept '], 'center', (H/4.5), textColor);
  947. Screen('DrawTexture', window1, objectDisplay_test, [], pos_ot,rotationAngle_test);
  948. startTime_test = Screen('Flip', window1); % Start of trial
  949. press_trigger(trigger_object_abstract,TB,triggers_on);
  950. press_eyelink_trigger(trigger_object_abstract,eyetracking)
  951. Onset_object_pt = startTime_test-ExpStart; %Onset
  952. Onset_test = startTime_test-ExpStart; %Onset
  953. stop=1;
  954. while stop % GetSecs - startTime < objectTimeout
  955. [keyIsDown,secs,keyCode] = KbCheck;
  956. % ESC key quits the experiment
  957. if keyCode(KbName('Q')) == 1
  958. endexperiment(window1,pahandle,outputfile,triggers_on,TB,trigger_beginning_end,eyetracking,edfFile)
  959. return;
  960. end
  961. pressedKeys = find(keyCode);
  962. if keyCode(KbName('RightArrow')) == 1
  963. Screen('TextSize',window1,18);
  964. DrawFormattedText(window1, ['Press <- or -> to ROTATE; press ' keytoaccepabs ' to accept '], 'center', (H/4.5), textColor);
  965. Screen('DrawTexture', window1, objectDisplay_test, [], pos_ot,rotationAngle_test+rotSensi*rotFac);
  966. startTime=Screen('Flip', window1); % Moving
  967. Onset_movn = startTime-ExpStart; %Onset
  968. ddd=Onset_movn-Onset_movl;
  969. if ddd<keypul
  970. rotFac= rotFac+keyacce;
  971. else
  972. rotFac=1
  973. end
  974. Onset_movl=Onset_movn;
  975. rotationAngle_test=rotationAngle_test+(rotSensi*rotFac)
  976. if isempty(rt_resp_abstract_ini) %saving time a key was pressed first time
  977. rt_resp_abstract_ini= startTime-ExpStart;
  978. press_trigger(trigger_right_key,TB,triggers_on);
  979. press_eyelink_trigger(trigger_right_key,eyetracking)
  980. end
  981. end
  982. if keyCode(KbName('LeftArrow')) == 1
  983. Screen('TextSize',window1,18);
  984. DrawFormattedText(window1, ['Press <- or -> to ROTATE; press ' keytoaccepabs ' to accept '], 'center', (H/4.5), textColor);
  985. Screen('DrawTexture', window1, objectDisplay_test, [], pos_ot,rotationAngle_test-rotSensi*rotFac);
  986. startTime=Screen('Flip', window1); % Moving
  987. Onset_movn = startTime-ExpStart; %Onset
  988. ddd=Onset_movn-Onset_movl;
  989. if ddd<keypul
  990. rotFac= rotFac+keyacce;
  991. else
  992. rotFac=1
  993. end
  994. Onset_movl=Onset_movn;
  995. rotationAngle_test=rotationAngle_test-(rotSensi*rotFac)
  996. if isempty(rt_resp_abstract_ini) %saving time a key was pressed first time
  997. rt_resp_abstract_ini= startTime-ExpStart;
  998. press_trigger(trigger_left_key,TB,triggers_on);
  999. press_eyelink_trigger(trigger_left_key,eyetracking)
  1000. end
  1001. end
  1002. if keyCode(KbName(keytoaccepabs)) == 1
  1003. press_trigger(trigger_up_key,TB,triggers_on);
  1004. press_eyelink_trigger(trigger_up_key,eyetracking)
  1005. rt_resp_abstract = GetSecs - startTime_test;
  1006. stop=0;
  1007. elseif (GetSecs - startTime_test > abstractTimeout)
  1008. rt_resp_abstract=0;
  1009. stop=0;
  1010. responsetimeout=1;
  1011. end
  1012. end
  1013. end
  1014. WaitSecs(fbrespabs- slack)
  1015. %% Giving feedback (B updated to circular) (Continuous task)
  1016. if type_of_task==2
  1017. degdiff=angdiff(deg2rad(rotationAngle_test),deg2rad(object_cue_rot)); % angular difference
  1018. degdiff=rad2deg(degdiff); % back to degrees
  1019. mes_catch=(['Difference in degrees = ' num2str(round(abs(degdiff)))])
  1020. fb=1;
  1021. if fb==1 % percentage correct
  1022. perc=abs(degdiff);
  1023. perc=1-abs(degdiff)/180;
  1024. perc=round(1000*perc)/10;
  1025. mes_catch= (['Accuracy score: ' num2str(perc) ' %' ])
  1026. textColor_fb=[255 255 255]
  1027. acc_trial_abstract=(perc)
  1028. end
  1029. if responsetimeout
  1030. mes_catch= (['Try to respond faster'])
  1031. textColor_fb=[255 0 0]
  1032. acc_trial_abstract=NaN
  1033. end
  1034. %To give averall feedback about performance in a block
  1035. accuracy_abs=[accuracy_abs perc];
  1036. % % % % Show fixation cross
  1037. % % %
  1038. % % % drawDot(window1,W,H,barColor);
  1039. % % % tFixation = Screen('Flip', window1);
  1040. % % %
  1041. % % % % Show fixation cross
  1042. % % % Screen(window1, 'FillRect', backgroundColor);
  1043. % % % Screen('Flip', window1, tFixation + (fixationDuration + rand(1))- slack,0) %Adding between 0 and 1 second randomly to the minimum for the fixation duration
  1044. % % %
  1045. % Show Feedback Screen
  1046. % % % DrawFormattedText(window1, mes_catch, 'center', 'center', textColor);
  1047. % % %
  1048. % % % startTime = Screen('Flip', window1);
  1049. % % % Onset_feedback = startTime-ExpStart; %Onset
  1050. % % %
  1051. Screen('TextSize',window1,18);
  1052. DrawFormattedText(window1, mes_catch, 'center', (H/4.5), textColor_fb);
  1053. Screen('DrawTexture', window1, objectDisplay_test, [], pos_ot,rotationAngle_test);
  1054. startTime=Screen('Flip', window1); % Start of feedback
  1055. press_trigger(trigger_feedback,TB,triggers_on);
  1056. press_eyelink_trigger(trigger_feedback,eyetracking)
  1057. Onset_feedback = startTime-ExpStart; %Onset
  1058. WaitSecs(fbtimeoutabs- slack)
  1059. end
  1060. %% At the end of the cued item test, we will either:
  1061. % (i) present an "Thank you" audio, to finish the trial
  1062. % (ii) cue the uncued item
  1063. if testinguncued
  1064. second_aud=(audcue{uncue})';
  1065. trigger_ready_2=trigger_retrocue_2; % If we test the uncued, the trigger will be retrocued_2
  1066. else
  1067. second_aud=(audthanks{1})';
  1068. trigger_ready_2= trigger_thanks; % If we DO NOT test the uncued, the trigger will be trigger_thanks (thanks messages after testing the cued item)
  1069. end
  1070. % Screen priority
  1071. Priority(MaxPriority(window1));
  1072. Priority(2);
  1073. % Show fixation cross
  1074. drawDot(window1,W,H,barColor);
  1075. startTime = Screen('Flip', window1);
  1076. Onset_retrocue_2 = startTime-ExpStart; %Onset
  1077. press_trigger(trigger_ready_2,TB,triggers_on);
  1078. press_eyelink_trigger(trigger_ready_2,eyetracking)
  1079. % WaitSecs(fbaudiogap)
  1080. % Presenting retro cue with audio
  1081. % PLAY SOUND (here trig is a sound signal)
  1082. % 1) fill the buffer
  1083. PsychPortAudio('FillBuffer', pahandle,second_aud);
  1084. % 2) play it
  1085. PsychPortAudio('Start', pahandle, repetitions, startCue);
  1086. % 3) Stop when it's done playing
  1087. PsychPortAudio('Stop', pahandle,1);
  1088. %% If there is a TEST for the UNCUED item
  1089. if testinguncued
  1090. %% Showing the Pings
  1091. if pingsareon %If PINGS are ON
  1092. for pings=1:size(oddpingpos_2,2) %How many pings
  1093. %In this example the oddball will be a different color for the
  1094. %text
  1095. if oddpingpos_2(pings)==1
  1096. rectColor_s=rectColor_odd;
  1097. trigger_ping_selected=trigger_odd_ping_2
  1098. else
  1099. rectColor_s=rectColor;
  1100. trigger_ping_selected=trigger_ping_2
  1101. end
  1102. % Screen priority
  1103. Priority(MaxPriority(window1));
  1104. Priority(2);
  1105. % Show fixation cross
  1106. Screen(window1, 'FillRect', backgroundColor);
  1107. drawDot(window1,W,H,barColor);
  1108. tFixation = Screen('Flip', window1);
  1109. %Duration of fix cross is based on "pausvec"
  1110. Screen(window1, 'FillRect', backgroundColor);
  1111. Screen('Flip', window1, tFixation + (pausvec_2(pings)/1000)- slack,0) %Adding between 0 and 1 second randomly to the minimum for the fixation duration
  1112. Screen('FillOval', window1, rectColor_s{1}, centeredRect1, maxDiameter1);
  1113. Screen('FillOval', window1, rectColor_s{2}, centeredRect2, maxDiameter2);
  1114. Screen('FillOval', window1, rectColor_s{3}, centeredRect3, maxDiameter3);
  1115. Screen('FillOval', window1, rectColor_s{4}, centeredRect4, maxDiameter4);
  1116. Screen('FillOval', window1, rectColor_s{5}, centeredRect5, maxDiameter5);
  1117. drawDot(window1,W,H,barColor); %Fixcross on top
  1118. pingfixated_2(pings)=0; %eye centered
  1119. if eyetracking==1 % Before 'Flip' check whether the eyes are well fixated to change the trigger id
  1120. pingfixated_2(pings) = gazeoff(W,H,fixtrh,gazeofftimelim,0);
  1121. if pingfixated_2(pings)
  1122. Screen('TextSize',window1,40);
  1123. DrawFormattedText(window1, 'FIXATE!', 'center', 'center', [200 0 0]);
  1124. end
  1125. end
  1126. % Flip to the screen
  1127. startTime = Screen('Flip', window1);
  1128. tdel=press_trigger(trigger_ping_selected,TB,triggers_on);
  1129. press_eyelink_trigger(trigger_ping_selected,eyetracking)
  1130. Onset_ping_2(pings) = startTime-ExpStart;
  1131. startout=[];
  1132. while GetSecs - startTime < ((pilth/1000)-tdel- slack)
  1133. if eyetracking==1
  1134. nnf(1) = gazeoff(W,H,fixtrh,gazeofftimelim,0);
  1135. if nnf(1)==0
  1136. continue
  1137. end
  1138. startout=[startout GetSecs];
  1139. if startout(end)-startout(1)>gazeofftimelim %pingfixated(1) %Eyes not fixated!
  1140. pingfixated_2(pings)=1;
  1141. Screen('TextSize',window1,40);
  1142. DrawFormattedText(window1, 'FIXATE!', 'center', 'center', [200 0 0]);
  1143. startTimeFiXM =Screen('Flip', window1)
  1144. end
  1145. end
  1146. end
  1147. end
  1148. else %If PINGS are off
  1149. startout=[];
  1150. % Screen priority
  1151. Priority(MaxPriority(window1));
  1152. Priority(2);
  1153. % Show fixation cross
  1154. Screen(window1, 'FillRect', backgroundColor);
  1155. drawDot(window1,W,H,barColor);
  1156. startTimeA = Screen('Flip', window1);
  1157. while GetSecs - startTimeA < ((delth_2/1000)-(pausvec_2(end)/1000)- slack) % During the time of the delay period
  1158. if eyetracking==1
  1159. nnf(1) = gazeoff(W,H,fixtrh,gazeofftimelim,0);
  1160. if nnf(1)==0
  1161. continue
  1162. end
  1163. startout=[startout GetSecs];
  1164. if startout(end)-startout(1)>gazeofftimelim %pingfixated(1) %Eyes not fixated!
  1165. pingfixated_2(1)=1;
  1166. Screen('TextSize',window1,40);
  1167. DrawFormattedText(window1, 'FIXATE!', 'center', 'center', [200 0 0]);
  1168. startTimeFiXM =Screen('Flip', window1)
  1169. end
  1170. end
  1171. end
  1172. end
  1173. %%
  1174. if type_of_task==1
  1175. acc_trial_concrete_uncued=NaN;
  1176. OnsetResp_uncued=0;
  1177. rt_resp_concrete_uncued = 0;
  1178. resp_text_uncued = 0;
  1179. resp_uncued = 'No_Response'; %Just in case we don't have response
  1180. rotationAngle_test=object_test_rot_uncued;
  1181. finalrot_concrete_uncued=NaN;
  1182. % Screen priority
  1183. Priority(MaxPriority(window1));
  1184. Priority(2);
  1185. % Show fixation cross
  1186. drawDot(window1,W,H,barColor);
  1187. tFixation = Screen('Flip', window1);
  1188. Screen(window1, 'FillRect', backgroundColor);
  1189. Screen('Flip', window1, tFixation + (pausvec_2(end)/1000)- slack,0) %Adding between 0 and 1 second randomly to the minimum for the fixation duration
  1190. % Show Object
  1191. Screen('TextSize',window1,18);
  1192. DrawFormattedText(window1, 'Press <- or -> to CHOOSE the right direction', 'center', (H/4.5), textColor);
  1193. Screen('DrawTexture', window1, objectDisplay_test_uncued, [], pos_ot,rotationAngle_test);
  1194. startTime_test = Screen('Flip', window1); % Start of trial
  1195. press_trigger(trigger_object_concrete_uncued,TB,triggers_on);
  1196. press_eyelink_trigger(trigger_object_concrete_uncued,eyetracking)
  1197. Onset_object_pt_uncued = startTime-ExpStart; %Onset
  1198. Onset_test_uncued = startTime_test-ExpStart; %Onset
  1199. responsetimeout=0;
  1200. stop=1;
  1201. while stop % GetSecs - startTime < objectTimeout
  1202. [keyIsDown,secs,keyCode] = KbCheck;
  1203. % ESC key quits the experiment
  1204. if keyCode(KbName('Q')) == 1
  1205. endexperiment(window1,pahandle,outputfile,triggers_on,TB,trigger_beginning_end,eyetracking,edfFile)
  1206. end
  1207. respTime = GetSecs;
  1208. pressedKeys = find(keyCode);
  1209. % Check for response keys
  1210. if ~isempty(pressedKeys)
  1211. for i = 2:3
  1212. if KbName(responseKeys{i}) == pressedKeys(1)
  1213. resp_uncued = responseKeys{i};
  1214. rt_resp_concrete_uncued= respTime - startTime_test;
  1215. OnsetResp_uncued = GetSecs - ExpStart;
  1216. if keyCode(KbName('RightArrow')) == 1
  1217. press_trigger(trigger_right_key,TB,triggers_on);
  1218. press_eyelink_trigger(trigger_right_key,eyetracking)
  1219. elseif keyCode(KbName('LeftArrow')) == 1
  1220. press_trigger(trigger_left_key,TB,triggers_on);
  1221. press_eyelink_trigger(trigger_left_key,eyetracking)
  1222. end
  1223. break
  1224. end
  1225. end
  1226. end
  1227. if rt_resp_concrete_uncued > 0
  1228. stop=0;
  1229. break
  1230. elseif (GetSecs - startTime_test > concreteTimeout- slack)
  1231. stop=0;
  1232. responsetimeout=1;
  1233. end
  1234. end
  1235. % Showing the move
  1236. if keyCode(KbName('RightArrow')) == 1
  1237. Screen('TextSize',window1,18);
  1238. DrawFormattedText(window1, 'Press <- or -> to CHOOSE the right direction', 'center', (H/4.5), textColor);
  1239. Screen('DrawTexture', window1, objectDisplay_test_uncued, [], pos_ot,rotationAngle_test+distrot/contestdif);
  1240. startTime = Screen('Flip', window1); % Start of trial
  1241. Onset_object_pt = startTime-ExpStart; %Onset
  1242. finalrot_concrete_uncued=rotationAngle_test+distrot/contestdif;
  1243. end
  1244. if keyCode(KbName('LeftArrow')) == 1
  1245. Screen('TextSize',window1,18);
  1246. DrawFormattedText(window1, 'Press <- or -> to CHOOSE the right direction', 'center', (H/4.5), textColor);
  1247. Screen('DrawTexture', window1, objectDisplay_test_uncued, [], pos_ot,rotationAngle_test-distrot/contestdif);
  1248. startTime = Screen('Flip', window1); % Start of trial
  1249. Onset_object_pt = startTime-ExpStart; %Onset
  1250. finalrot_concrete_uncued=rotationAngle_test-distrot/contestdif;
  1251. end
  1252. WaitSecs(fbrespcon- slack)
  1253. %% Feedback Concrete using images
  1254. %Obtaining right answer
  1255. if responsetimeout
  1256. fb_message= (['Try to respond faster'])
  1257. acc_trial_concrete_uncued=2;
  1258. textColor_fb=[255 0 0]
  1259. else
  1260. degdiff=angdiff(deg2rad(object_uncued_rot),deg2rad(object_test_rot_uncued)); % angular difference
  1261. degdiff=rad2deg(degdiff)
  1262. if degdiff<0
  1263. corr_r='R'
  1264. else
  1265. corr_r='L'
  1266. end
  1267. %Preparing FB message
  1268. if resp_uncued(1)==corr_r
  1269. fb_message = 'correct'
  1270. accuracy_con=[accuracy_con 1];
  1271. acc_trial_concrete_uncued=1;
  1272. objectDisplay_fb=objectDisplay_test_green;
  1273. textColor_fb=[0 255 100]
  1274. else
  1275. fb_message = 'incorrect'
  1276. accuracy_con=[accuracy_con 0];
  1277. acc_trial_concrete_uncued=0;
  1278. objectDisplay_fb=objectDisplay_test_red;
  1279. textColor_fb=[255 0 0]
  1280. end
  1281. end
  1282. Screen('TextSize',window1,20);
  1283. DrawFormattedText(window1, fb_message, 'center', (H/4.5), textColor_fb);
  1284. Screen('DrawTexture', window1, objectDisplay_test_uncued,[], pos_ot,object_uncued_rot,1,0.9);
  1285. startTime=Screen('Flip', window1); % Start of feedback
  1286. Onset_feedback_uncued = startTime-ExpStart; %Onset
  1287. press_trigger(trigger_feedback_uncued,TB,triggers_on);
  1288. press_eyelink_trigger(trigger_feedback_uncued,eyetracking)
  1289. WaitSecs(fbtimeoutcon- slack)
  1290. %% At the end of trial we present an "Thank you" audio, to finish the trial
  1291. second_aud=(audthanks{1})';
  1292. % Screen priority
  1293. Priority(MaxPriority(window1));
  1294. Priority(2);
  1295. % Show fixation cross
  1296. drawDot(window1,W,H,barColor);
  1297. startTime = Screen('Flip', window1);
  1298. Onset_thanks_uncued = startTime-ExpStart; %Onset
  1299. press_trigger(trigger_thanks_2,TB,triggers_on);
  1300. press_eyelink_trigger(trigger_thanks_2,eyetracking)
  1301. WaitSecs(fbaudiogap)
  1302. % Presenting retro cue with audio
  1303. % PLAY SOUND (here trig is a sound signal)
  1304. % 1) fill the buffer
  1305. PsychPortAudio('FillBuffer', pahandle, second_aud);
  1306. % 2) play it
  1307. PsychPortAudio('Start', pahandle, repetitions, startCue);
  1308. % 3) Stop when it's done playing
  1309. PsychPortAudio('Stop', pahandle,1);
  1310. end
  1311. end
  1312. %% Updating outputfile
  1313. %Info to include (related to trial)
  1314. pingsareon; %Ping on/off
  1315. block;
  1316. testinguncued;
  1317. object_1_id;
  1318. object_2_id;
  1319. file_object_1; %name of the file
  1320. file_object_2;
  1321. object_1_rot;
  1322. object_2_rot;
  1323. object_1_fixated;
  1324. object_2_fixated;
  1325. cue;
  1326. uncue;
  1327. object_cue_id;
  1328. object_cue_rot;
  1329. object_uncued_id;
  1330. object_uncued_rot;
  1331. type_of_task=sequence(trial,7); %1=concrete and 2=abstract
  1332. total_of_pings= length(oddpingpos); %sequence of pings (1== oddball)
  1333. position_odd_pings= find(oddpingpos==1);
  1334. pingfixated;
  1335. object_test_id;
  1336. object_test_rot;
  1337. total_of_pings_2= length(oddpingpos_2); %sequence of pings (1== oddball)
  1338. position_odd_pings_2= find(oddpingpos_2==1);
  1339. pingfixated_2;
  1340. object_test_id_uncued;
  1341. object_test_rot_uncued;
  1342. %Info to include (related to partipants' response)
  1343. if type_of_task==2
  1344. trigger_object_concrete=NaN;
  1345. rt_resp_concrete =NaN;
  1346. acc_trial_concrete =NaN; %0== Incorrect, 1== Correct; 2== No response/too slow)
  1347. finalrot_concrete =NaN;% final rotation for concrete task
  1348. elseif type_of_task==1
  1349. trigger_object_abstract=NaN;
  1350. rt_resp_abstract_ini=NaN
  1351. rt_resp_abstract =NaN;
  1352. acc_trial_abstract =NaN; % Percentage; NaN == No response/too slow)
  1353. rotationAngle_test =NaN; % final rotation for abstract task
  1354. end
  1355. if testinguncued ==0
  1356. resp_uncued = NaN;
  1357. trigger_object_concrete_uncued = NaN;
  1358. rt_resp_concrete_uncued = NaN;
  1359. acc_trial_concrete_uncued = NaN; %0== Incorrect, 1== Correct; 2== No response/too slow)
  1360. finalrot_concrete_uncued = NaN;% final rotation for concrete task
  1361. Onset_test_uncued= NaN;
  1362. OnsetResp_uncued = NaN;
  1363. Onset_feedback_uncued=NaN;
  1364. Onset_thanks_uncued = NaN;
  1365. end
  1366. % Time Onsets - A temporal list
  1367. Onset_object_1; %Object 1
  1368. Onset_object_2;%Object 2
  1369. Onset_retrocue;%Retro cue
  1370. Onset_taskcue=NaN;%Task cue. Nothing here in this task.
  1371. Onset_ping; %List the ping onset
  1372. Onset_test;%Test on screen
  1373. OnsetResp; %Response onset for the cued test
  1374. Onset_feedback;%Feedback
  1375. Onset_retrocue_2; % Important: this can be retrocue for uncued or a thank message
  1376. Onset_ping_2; %List the ping onset (second delay)
  1377. Onset_test_uncued; %Test for the uncued on screen (only if tested)
  1378. OnsetResp_uncued; %Response onset for the uncued test (only if tested)
  1379. Onset_feedback_uncued; %FB for the uncued on screen (only if tested)
  1380. Onset_thanks_uncued;
  1381. % For the bonus system
  1382. if maxiblock==4
  1383. bon_acc_concrete(trial)=acc_trial_concrete;
  1384. bon_acc_abstract(trial)=acc_trial_abstract;
  1385. end
  1386. % Save the null trials for a
  1387. if nansum([pingfixated(:); pingfixated_2(:); object_1_fixated; object_2_fixated])>0&&repnonfixtrial
  1388. if practice==0
  1389. sequencenull=[sequencenull; sequence(trial,:)]
  1390. if size(sequencenull,1)>48
  1391. % fixtrh=35;
  1392. end
  1393. end
  1394. end
  1395. if maxiblock==5
  1396. blocknulrep=1;
  1397. else
  1398. blocknulrep=0;
  1399. end
  1400. %% Saving data to outputfile
  1401. % Set up the output file (this output is for info related with the
  1402. % presention of room-object association and word tasks)
  1403. % resultsFolder = 'outputfiles';
  1404. % outputfile = fopen([resultsFolder '/resultfile_' num2str(subID) '.txt'],'a');
  1405. % fprintf(outputfile, 'task_version\t date\t subID\t sub_gender\t sub_age\t block_number\t trial\t object_1_name\t object_1_id\t object_1_rot\t object_2_name\t object_2_ID\t object_2_rot\t retro_cue\t object_cue_id\t object_cue_rot\t type_of_task\t type_of_ings\t position_odd_pings\t object_test_name\t object_test_id\t object_test_rot\t rt_resp_concrete\t acc_trial_concrete\t final_rot_concrete\t rt_resp_abstract_first_key\t rt_resp_abstract\t acc_trial_abstract\t final_rot_abstract\t onset_object_1\t onset_object_2\t onset_retrocue\t onset_taskcue\t onset_test\t onset_feedback\t onset_ping_1\t onset_ping_2\t onset_ping_3\t onset_ping_4\t onset_ping_5\t onset_ping_6\t onset_ping_7\t onset_ping_8\t onset_ping_9\t onset_ping_10\t trigger_object_1\t trigger_object_2\t trigger_retrocue_1\t trigger_taskcue\t trigger_object_concrete\t trigger_object_abstract\t colorset_pins\n');
  1406. if pingsareon %if we are using pings the outputfile will be more detailed
  1407. % Save results to file
  1408. fprintf(outputfile, '%s\t %s\t %s\t %s\t %d\t %d\t %d\t %s\t %d\t %d\t %s\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %s\t %d\t %d\t %s\t %d\t %d\t %f\t %d\t %f\t %f\t %d\t %f\t %d\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\n',...
  1409. taskversion, today, subID, gender, age, block, trial, file_object_1, object_1_id, object_1_rot, file_object_2, object_2_id , object_2_rot, cue, object_cue_id, object_cue_rot, uncue, object_uncued_id, object_uncued_rot, type_of_task, total_of_pings, position_odd_pings, total_of_pings_2, position_odd_pings_2, pingsareon, file_object_t, object_test_id, object_test_rot, file_object_t_uncued, object_test_id_uncued, object_test_rot_uncued, rt_resp_concrete, acc_trial_concrete, finalrot_concrete, rt_resp_concrete_uncued, acc_trial_concrete_uncued, finalrot_concrete_uncued, testinguncued, Onset_object_1, Onset_object_2, Onset_retrocue, Onset_taskcue, Onset_test, OnsetResp, Onset_feedback, Onset_retrocue_2, Onset_test_uncued,OnsetResp_uncued, Onset_feedback_uncued,Onset_thanks_uncued, Onset_ping(1), Onset_ping(2), Onset_ping(3), Onset_ping(4), Onset_ping(5), Onset_ping_2(1), Onset_ping_2(2), Onset_ping_2(3), Onset_ping_2(4),Onset_ping_2(5), trigger_object_1, trigger_object_2, trigger_retrocue, trigger_taskcue, trigger_object_concrete, trigger_object_abstract, pingcolorset, practice, righthanded, pingfixated(1),pingfixated(2),pingfixated(3), pingfixated(4), pingfixated_2(1), pingfixated_2(2), pingfixated_2(3),pingfixated_2(4), object_1_fixated, object_2_fixated,blocknulrep, fixtrh);
  1410. else
  1411. % Save results to file
  1412. fprintf(outputfile, '%s\t %s\t %s\t %s\t %d\t %d\t %d\t %s\t %d\t %d\t %s\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %s\t %d\t %d\t %s\t %d\t %d\t %f\t %d\t %f\t %f\t %d\t %f\t %d\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %f\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\n',...
  1413. taskversion, today, subID, gender, age, block, trial, file_object_1, object_1_id, object_1_rot, file_object_2, object_2_id , object_2_rot, cue, object_cue_id, object_cue_rot, uncue, object_uncued_id, object_uncued_rot, type_of_task, pingsareon, file_object_t, object_test_id, object_test_rot, file_object_t_uncued, object_test_id_uncued, object_test_rot_uncued, rt_resp_concrete, acc_trial_concrete, finalrot_concrete, rt_resp_concrete_uncued, acc_trial_concrete_uncued, finalrot_concrete_uncued, testinguncued, Onset_object_1, Onset_object_2, Onset_retrocue, Onset_taskcue, Onset_test, OnsetResp, Onset_feedback, Onset_retrocue_2, Onset_test_uncued,OnsetResp_uncued, Onset_feedback_uncued,Onset_thanks_uncued, trigger_object_1, trigger_object_2, trigger_retrocue, trigger_taskcue, trigger_object_concrete, trigger_object_abstract, practice, righthanded, pingfixated(1), pingfixated_2(1), object_1_fixated, object_2_fixated,blocknulrep, fixtrh);
  1414. end
  1415. %%
  1416. %
  1417. % p1_name = stimuli_info.Item_Name(sequence_of_n_back(t,1),:);
  1418. %
  1419. % % Save results to file
  1420. % fprintf(outputfile,'%s\t %s\t %d\t %f\t %f\n' ,...
  1421. % today, p1_name, rt_catch, Onset_object_p1,OnsetResp);
  1422. %
  1423. % fprintf(outputfile, 'date\t object_name\t rt_resp_concreteonse\t Onset_object\t Onset_response\n');
  1424. %% Interblock MESSAGE
  1425. if block~=next_trial_block
  1426. ddo=block/nblocks
  1427. baseRect = [0 0 W/4 W/32];
  1428. baseRect_done = [0 0 (W/4)*ddo W/32];
  1429. rectColorBase = [100 100 100];
  1430. rectColor_done = [0 200 10];
  1431. centeredRect = CenterRectOnPointd(baseRect, xCenter, yCenter);
  1432. centeredRect_done = centeredRect;
  1433. trd=centeredRect(1)+((centeredRect(3)-centeredRect(1))*ddo);
  1434. centeredRect_done(3)=trd;
  1435. % Draw the square to the screen. For information on the command used in
  1436. % this line see Screen FillRect?
  1437. Screen('FillRect', window1, rectColorBase, centeredRect);
  1438. Screen('FillRect', window1, rectColor_done, centeredRect_done);
  1439. Screen('TextSize',window1,18);
  1440. msg=['Great! You finished the ',num2str(ddo*100),' % of the task'];
  1441. DrawFormattedText(window1, msg, 'center', (H/2.5), textColor);
  1442. DrawFormattedText(window1, ['Accuracy: ' num2str(mean(accuracy_con)*100)], 'center', (H/4.5), textColor);
  1443. DrawFormattedText(window1, '[Press the space bar to continue]', 'center', (H/1.5), textColor);
  1444. overviewTime = Screen('Flip',window1)-ExpStart; % first screen time
  1445. Screen('TextSize',window1,40);
  1446. % Wait for subject to press spacebar
  1447. while 1
  1448. [keyIsDown,secs,keyCode] = KbCheck;
  1449. if keyCode(KbName('space'))==1
  1450. break
  1451. elseif keyCode(KbName('Q'))==1
  1452. endexperiment(window1,pahandle,outputfile,triggers_on,TB,trigger_beginning_end,eyetracking,edfFile)
  1453. end
  1454. end
  1455. % Counter for interblock message accuracy
  1456. accuracy_con= [];
  1457. accuracy_abs= [];
  1458. end
  1459. end
  1460. end
  1461. %%
  1462. %% FINAL MESSAGE
  1463. if practice
  1464. msg=['Great! You finished the practice blocks'];
  1465. else
  1466. msg=['Great! You finished ',num2str(block),' of ', num2str(nblocks), ' blocks'];
  1467. end
  1468. Screen('TextSize',window1,18);
  1469. DrawFormattedText(window1, msg, 'center', (H/4.5), textColor);
  1470. DrawFormattedText(window1, '[Press the space bar to continue]', 'center', (H/1.5), textColor);
  1471. overviewTime = Screen('Flip',window1)-ExpStart; % first screen time
  1472. Screen('TextSize',window1,40);
  1473. % Wait for subject to press spacebar
  1474. while 1
  1475. [keyIsDown,secs,keyCode] = KbCheck;
  1476. if keyCode(KbName('space'))==1
  1477. break
  1478. end
  1479. end
  1480. %% BONUS
  1481. if practice==0
  1482. msg= ['We will take 5 random trials of each task (new/same object).'];
  1483. msg2= ['If your accuracy is >= 60% you will get a bonus payment.']
  1484. Screen('TextSize',window1,18);
  1485. DrawFormattedText(window1, msg, 'center', (H/4.5), textColor);
  1486. DrawFormattedText(window1, msg2, 'center', 'center', textColor);
  1487. DrawFormattedText(window1, '[Press the space bar to continue]', 'center', (H/1.5), textColor);
  1488. overviewTime = Screen('Flip',window1)-ExpStart; % first screen time
  1489. Screen('TextSize',window1,40);
  1490. WaitSecs(1);
  1491. % Wait for subject to press spacebar
  1492. while 1
  1493. [keyIsDown,secs,keyCode] = KbCheck;
  1494. if keyCode(KbName('space'))==1
  1495. break
  1496. end
  1497. end
  1498. WaitSecs(2);
  1499. toi=~isnan(bon_acc_concrete);
  1500. bonnac=bon_acc_concrete(toi);
  1501. gg=randperm(length(bonnac));
  1502. bonusfinconcrete=mean(bonnac(gg(1:5))==1);
  1503. % toi=~isnan(bon_acc_abstract);
  1504. % bonnac=bon_acc_abstract(toi);
  1505. % gg=randperm(length(bonnac));
  1506. % bonusfinabstract=mean(bonnac(gg(1:5)));
  1507. msg= ['Accuracy: ' num2str(bonusfinconcrete*100) ' %'];
  1508. if bonusfinconcrete>=.60%&bonusfinabstract>=80
  1509. msg2=['Congrats! You got the bonus payment'];
  1510. else
  1511. msg2=['Unfortunately you did not get the bonus payment"'];
  1512. end
  1513. Screen('TextSize',window1,18);
  1514. DrawFormattedText(window1, msg, 'center', (H/4.5), textColor);
  1515. DrawFormattedText(window1, msg2, 'center', 'center', textColor);
  1516. DrawFormattedText(window1, '[Press the space bar to finish]', 'center', (H/1.5), textColor);
  1517. overviewTime = Screen('Flip',window1)-ExpStart; % first screen time
  1518. Screen('TextSize',window1,40);
  1519. % Wait for subject to press spacebar
  1520. while 1
  1521. [keyIsDown,secs,keyCode] = KbCheck;
  1522. if keyCode(KbName('space'))==1
  1523. break
  1524. end
  1525. end
  1526. end
  1527. WaitSecs(1);
  1528. %% END
  1529. endexperiment(window1,pahandle,outputfile,triggers_on,TB,trigger_beginning_end,eyetracking,edfFile)
  1530. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1531. %% Subfunctions
  1532. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1533. %% End the experiment
  1534. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1535. function endexperiment(window1,pahandle,outputfile, triggers_on,TB,ti,eyetracking,edfFile)
  1536. if triggers_on
  1537. % ti is the trigger id
  1538. % Set the port to zero state 0
  1539. IOPort('Write', TB, uint8(0),0);
  1540. WaitSecs(0.005)
  1541. % Set Bit 0 (Pin 2 of the Output(to Amp)
  1542. IOPort('Write', TB, uint8(ti),0);
  1543. % Wait 2ms and reset the port to zero state
  1544. WaitSecs(0.005)
  1545. IOPort('Write', TB, uint8(0),0);
  1546. WaitSecs(0.005)
  1547. % Then disconnect/close the serial port object from the serial port
  1548. IOPort('Close', TB);
  1549. end
  1550. if eyetracking==1
  1551. % mark zero-plot time in data file
  1552. mel=num2str(ti)
  1553. Eyelink('Message', mel);
  1554. % STEP 8
  1555. % finish up: stop recording eye-movements,
  1556. % close graphics window, close data file and shut down tracker
  1557. Eyelink('StopRecording');
  1558. Eyelink('CloseFile');
  1559. Eyelink('ReceiveFile',edfFile, ['data_eyelink/' edfFile])
  1560. Eyelink('Shutdown');
  1561. end
  1562. % Close audio settings (pahandle)
  1563. PsychPortAudio('Close', pahandle);
  1564. RestrictKeysForKbCheck([]);
  1565. fclose(outputfile);
  1566. Screen(window1,'Close');
  1567. close all
  1568. sca;
  1569. return
  1570. end
  1571. %% Detecting a that gaze is non-centered
  1572. function [isoff]= gazeoff(W,H,fixtrh,gazeofftimelim,wentout)
  1573. isoff=0;
  1574. if Eyelink( 'NewFloatSampleAvailable') > 0
  1575. evt = Eyelink( 'NewestFloatSample');
  1576. if abs(round(evt.gx(1))-(W/2))>fixtrh|abs(round(evt.gy(1))-(H/2))>fixtrh %Eyes NOT fixated!
  1577. startout=GetSecs;
  1578. wentout=1;
  1579. isoff=1; %eye not centered
  1580. return
  1581. end
  1582. end
  1583. end
  1584. %% Detecting a that gaze is centered
  1585. function [isin]= gazein(W,H,fixtrh,gazeofftimelim,wentout)
  1586. isin=0;
  1587. if Eyelink( 'NewFloatSampleAvailable') > 0
  1588. evt = Eyelink( 'NewestFloatSample');
  1589. if abs(round(evt.gx(1))-(W/2))<= fixtrh|abs(round(evt.gy(1))-(H/2))<= fixtrh %Eyes NOT fixated!
  1590. isin=1; %eye centered
  1591. return
  1592. end
  1593. end
  1594. end
  1595. %% Draw a fixation cross (overlapping horizontal and vertical bar)
  1596. function drawCross(window,W,H,barColor)
  1597. if nargin==3
  1598. barColor = [0 0 0];
  1599. end
  1600. barLength = 16; % in pixels
  1601. barWidth = 2; % in pixels
  1602. %0.5; % number from 0 (black) to 1 (white)
  1603. Screen('FillRect', window, barColor,[ (W-barLength)/2 (H-barWidth)/2 (W+barLength)/2 (H+barWidth)/2]);
  1604. Screen('FillRect', window, barColor,[ (W-barWidth)/2 (H-barLength)/2 (W+barWidth)/2 (H+barLength)/2]);
  1605. end
  1606. %% Draw a fixation DOT (overlapping horizontal and vertical bar)
  1607. function drawDot(window,W,H,barColor)
  1608. if nargin==3
  1609. barColor = [0 0 0];
  1610. end
  1611. barLength = 8; % in pixels
  1612. barWidth = 8; % in pixels
  1613. %0.5; % number from 0 (black) to 1 (white)
  1614. Screen('FillOval', window, barColor, [(W-barLength)/2 (H-barWidth)/2 (W+barLength)/2 (H+barWidth)/2]);
  1615. end
  1616. % Screen(???DrawDots???, windowPtr, xy [,size] [,color] [,center] [,dot_type][, lenient]);
  1617. %% Doing the timing job for delay between encoding (last item) and test
  1618. function pausvec=pingT(npings,nodd,delth,pilth,minipi,maxsend,minstart)
  1619. pausvec=NaN(1,npings+1);
  1620. pausvec(1)=randsample(minstart:maxsend,1); % pause before first ping (<minipi) % JLD edited
  1621. pausvec(end)=randsample(minipi+pilth:maxsend,1); % pause after last ping (>pilth, <minipi) % JLD edited
  1622. for p=2:npings-1
  1623. tleft=delth-nansum(pausvec); % time left
  1624. pleft=npings-p; % #pings left
  1625. maxipi=tleft-pleft*minipi; % max inter-ping-interval
  1626. pausvec(p)=randsample(minipi:maxipi,1); % pseudo-random pause length
  1627. end
  1628. pausvec(end-1)=delth-nansum(pausvec);% allocate remaining time left
  1629. % shorten post-ping time by ping lenghts (already done for last one)
  1630. pausvec(2:end)=pausvec(2:end)-pilth;
  1631. % do another permute to be sure:
  1632. pausvec=pausvec([1 randperm(npings-1)+1 npings+1]);
  1633. if sum(pausvec)~=delth-pilth*npings
  1634. error('ping time assignment error')
  1635. end
  1636. end
  1637. %% Trigger functions
  1638. function tdel=press_trigger(ti,TB,triggers_on)
  1639. c=tic;
  1640. if triggers_on
  1641. % ti is the trigger id
  1642. % Set the port to zero state 0
  1643. IOPort('Write', TB, uint8(0),0);
  1644. WaitSecs(0.005)
  1645. % Set Bit 0 (Pin 2 of the Output(to Amp)
  1646. IOPort('Write', TB, uint8(ti),0);
  1647. % Wait 2ms and reset the port to zero state
  1648. WaitSecs(0.005)
  1649. IOPort('Write', TB, uint8(0),0);
  1650. WaitSecs(0.005)
  1651. end
  1652. tdel=toc(c);
  1653. end
  1654. function press_eyelink_trigger(ti,eyetracking)
  1655. if eyetracking==1
  1656. % mark zero-plot time in data file
  1657. mel=num2str(ti)
  1658. Eyelink('Message', mel);
  1659. end
  1660. end
  1661. %% Showing slides
  1662. function showingslides(imgList_in,imageFolder_in,window1,W,H,backgroundColor,responseKeys)
  1663. imtotal = 1:size(imgList_in,2)
  1664. t=1
  1665. ttrue=1;
  1666. while ttrue==1
  1667. % Load image
  1668. file_in = imgList_in{t};
  1669. img_in = imread(fullfile(imageFolder_in,file_in));
  1670. imageDisplay_in = Screen('MakeTexture', window1, img_in);
  1671. % Calculate image position (center of the screen)
  1672. rat=(W/size(img_in,2))*.7;
  1673. imageSize = size(img_in)*rat;
  1674. pos = [(W-imageSize(2))/2 (H-imageSize(1))/2 (W+imageSize(2))/2 (H+imageSize(1))/2];
  1675. % Screen priority
  1676. Priority(MaxPriority(window1));
  1677. Priority(2);
  1678. % Show the images
  1679. Screen(window1, 'FillRect', backgroundColor);
  1680. Screen('DrawTexture', window1, imageDisplay_in, [], pos);
  1681. startTime = Screen('Flip', window1); % Start of trial
  1682. % Get keypress response
  1683. rt = 0;
  1684. resp = 0;
  1685. while 1
  1686. [keyIsDown,~,keyCode] = KbCheck;
  1687. respTime = GetSecs;
  1688. pressedKeys = find(keyCode);
  1689. % ESC key quits the experiment
  1690. if keyCode(KbName('Q')) == 1
  1691. clear all
  1692. close all
  1693. sca
  1694. return;
  1695. end
  1696. % Check for response keys
  1697. if ~isempty(pressedKeys)
  1698. for i = 1:length(responseKeys)
  1699. if KbName(responseKeys{i}) == pressedKeys(1)
  1700. resp = responseKeys{i};
  1701. rt = respTime - startTime;
  1702. end
  1703. end
  1704. end
  1705. % Exit loop once a response is recorded. Delete that to keep the
  1706. % image after the response
  1707. if keyCode(KbName('RightArrow'))==1
  1708. t=t+1;
  1709. break;
  1710. elseif keyCode(KbName('LeftArrow'))==1&t>1;
  1711. t=t-1;
  1712. break
  1713. end
  1714. end
  1715. WaitSecs(1);
  1716. % Clear textures
  1717. Screen(imageDisplay_in,'Close');
  1718. if t>imtotal;
  1719. ttrue=0;
  1720. end
  1721. end
  1722. end