Eyetracking_check.m 68 KB

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