Preprocessing_pipeline_epoch_object_onset_2022.m 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. % Preprocessing eye data
  2. clear all
  3. subjects_eyedata={'pil01';'pil02';'pi03';'p04';'p05';'p06';'p07';'p08';'p09';...
  4. 'p10';'p11';'p12';'p13';'p14';'p15';'p16';'p17';'p18';...
  5. 'p19';'p20';'p21';'p22';'p23';'p24';'p25';'p26';'p27';'p28';'p29';'p30'...
  6. ;'p31';'p32';'p34';'p35';'p36';'p37';'p38';'p39';'p40';'p41';...
  7. 'p42';'p43';'p44';'p45';'p46';'p47';'p48';'p49';'p50';'p51';'p52';...
  8. 'p53';'p54';'p55';'p56';'p57'};
  9. subjects_sub= [{'pil01'};{'pil02'};{'pi03'};{'p04'};{'p05'};{'p06'};{'p07'};{'p08'};{'p09'};...
  10. {'p10'};{'p11'};{'p12'};{'p13'};{'p14'};{'p15'};{'p16'};{'p17'};{'p18'};...
  11. {'p19'};{'p20'};{'p21'};{'p22'};{'p23'};{'p24'};{'p25'};{'p26'};{'p27'};{'p28'};{'p29'};{'p30'};...
  12. {'p31'};{'p32'};{'p34'};{'p35'};{'p36'};{'p37'};...
  13. {'p38'};{'p39'};{'p40'};{'p41'};{'p42'};{'p43'};{'p44'};{'p45'};{'p46'};{'p47'};...
  14. {'p48'};{'p49'};{'p50'};{'p51'};{'p52'};{'p53'};{'p54'};{'p55'};{'p56'};{'p57'}...
  15. ]
  16. %%
  17. for ppp=1:length(subjects_eyedata) %per participant
  18. %% Trigger info (EEG and Eye-Tracking)
  19. % % Changes: Gaze-off triggers removed (this info is included in the
  20. % output file). Triggers for "Thanks" messages included.
  21. % % -orientations (1:16): 001:1:016
  22. % % -sample item code (1:3): 20:20:60
  23. % % -1st/2nd sample position: 000/100
  24. % %
  25. % % i.e. item 2 at 45?? in first sample position would be 42; in 2nd sample position t would be 142
  26. % %
  27. % % - first retrocue: 1/2 (first or second item respectively)
  28. % % - second retrocue (for the uncued item): 3/4 (first or second item respectively)
  29. % %
  30. % % - thanks message after test for the CUED item: 5
  31. % % - thanks message after test for the UNCUED item: 6
  32. % %
  33. % % -Object onset in abstract test for the CUED item: 201:209 (object identity from 1 to 9)
  34. % % -Object onset in abstract test for the UNCUED item: 211:219 (object identity from 1 to 9)
  35. % %
  36. % % -Object onset in concrete test for the CUED item: 220/221 (for left/right tilted)
  37. % % -Object onset in concrete test for the UNCUED item: 223/224 (for left/right tilted)
  38. % %
  39. % % -230 Ping - First delay
  40. % % -231 Oddball Ping - First delay
  41. % %
  42. % % -232 Ping - Second delay
  43. % % -233 Oddball - Second delay
  44. % %
  45. % % -241 left button press
  46. % % -242 right button press
  47. % % -243 up/accept button press
  48. % % -244 feedback cued item
  49. % % -245 feedback uncued item
  50. % %
  51. % % -246 beginning/end of the task
  52. partID_prepro=subjects_eyedata{ppp};
  53. partID_outpufile=subjects_sub{ppp};
  54. mainfolder=''
  55. vinstoload=[mainfolder 'eyelink_matlab/' partID_prepro '.mat']
  56. load(vinstoload)
  57. if strcmp( partID_outpufile,'p11')
  58. load([mainfolder '/logfiles/resultfile_p11_table_repaired.mat'])
  59. subtable=sub
  60. else
  61. sub = tdfread([mainfolder 'logfiles/resultfile_' partID_outpufile '.txt'],'tab'); %Logfile for this participant
  62. subtable=struct2table(sub);
  63. end
  64. % Setting all possible triggers (just the first item on screen)
  65. counter=1
  66. allposi=[]
  67. for ori = 1:16
  68. for item=1:3
  69. for posi=1
  70. positri=ori+(item*20)+((posi==2)*100);
  71. postri(counter)=(positri);
  72. allposi=[allposi postri];
  73. end
  74. end
  75. end
  76. if ppp>=20
  77. allposi=[allposi 100];
  78. end
  79. cfg.data=mdat
  80. cfg.triggers=allposi
  81. cfg.prestim = 1000 %time prestim in ms
  82. cfg.poststim = 10000 %time prestim in ms
  83. data_epoch= maketrials_eyetracking_V1(cfg)
  84. %%
  85. %% Using logfile to add info of interest to the EEG data
  86. % Since we have 2 trigger per trial, let create a better table
  87. t_counter=0;
  88. stimuli_info=[];
  89. rotlist=unique(subtable.object_1_rot)
  90. for t = 1:length(subtable.trial)
  91. found = find(subtable.trial == t);
  92. t_counter=t_counter+1;
  93. stimuli_info.trial(t_counter,1) = subtable.trial(t); %Trial number;
  94. stimuli_info.object_1_id(t_counter,1) = subtable.object_1_id(t); %Object presented first;
  95. stimuli_info.object_1_rot(t_counter,1) = subtable.object_1_rot(t); %Object presented first;
  96. stimuli_info.object_1_position(t_counter,1) = 1; %Object presented first
  97. stimuli_info.object_1_trigger(t_counter,1) = subtable.trigger_object_1(t); %Object presented first;
  98. stimuli_info.object_1_rot_n(t_counter,1) = find(subtable.object_1_rot(t)==rotlist); %Object presented first;
  99. stimuli_info.object_2_id(t_counter,1) = subtable.object_2_id(t); %Object presented 2;
  100. stimuli_info.object_2_rot(t_counter,1) = subtable.object_2_rot(t); %Object presented 2;
  101. stimuli_info.object_2_position(t_counter,1) = 2; %Object presented 2
  102. stimuli_info.object_2_trigger(t_counter,1) = subtable.trigger_object_2(t); %Object presented first;
  103. stimuli_info.object_2_rot_n(t_counter,1) = find(subtable.object_2_rot(t)==rotlist); %Object presented first;
  104. stimuli_info.object_cued_id(t_counter,1) =subtable.object_cued_id(t);
  105. stimuli_info.object_cued_rot(t_counter,1) =subtable.object_cued_rot(t);
  106. stimuli_info.object_uncued_id(t_counter,1) =subtable.object_uncued_id(t);
  107. stimuli_info.object_uncued_rot(t_counter,1) =subtable.object_uncue_rot(t);
  108. stimuli_info.retrocue(t_counter,1) =subtable.retro_cue(t);
  109. stimuli_info.retrocue_uncued(t_counter,1) =subtable.retro_cue_uncued(t);
  110. stimuli_info.testing_uncued(t_counter,1) =subtable.testing_uncued(t);
  111. end
  112. stimuli_info=struct2table(stimuli_info) %double check
  113. %%
  114. if sum(stimuli_info.object_1_trigger'~=data_epoch.trigger_onset) %this should be 0
  115. error('Mismatch trials and triggers')
  116. end
  117. %% Recentered using mean
  118. data_epoch_recenter=data_epoch;
  119. allx=data_epoch.eyedat(:,1,:);
  120. mx=nanmean(allx(:))
  121. ally=data_epoch.eyedat(:,2,:);
  122. my=nanmean(ally(:))
  123. data_epoch_recenter.eyedat(:,1,:)=data_epoch.eyedat(:,1,:)-mx;
  124. data_epoch_recenter.eyedat(:,2,:)=data_epoch.eyedat(:,2,:)-my;
  125. %% if we need to visualise
  126. % figure; plot(squeeze(nanmean(data_epoch_recenter.eyedat(:,1,:),1)));hold on;
  127. % plot(squeeze(nanmean(data_epoch_recenter.eyedat(:,2,:),1)));
  128. %% Using a threshold to excluded not centered gaze
  129. data_epoch_thr=data_epoch_recenter;
  130. th=100; %pixel threshold
  131. cXY = [0,0]; %this should be the new center after re-centering
  132. Euc_dist=NaN(size(data_epoch_recenter.eyedat,1),size(data_epoch_recenter.eyedat,3));
  133. for tr = 1:size(data_epoch_recenter.eyedat,1) %trial
  134. for tt=1:size(data_epoch_recenter.eyedat,3) %time
  135. dataXY = [data_epoch_recenter.eyedat(tr,1,tt),data_epoch_recenter.eyedat(tr,2,tt)];
  136. Euc_dist(tr,tt) = norm( cXY - dataXY );
  137. if Euc_dist(tr,tt)>th
  138. data_epoch_thr.eyedat(tr,:,tt)=NaN;
  139. end
  140. end
  141. end
  142. %% if we need to visualise
  143. % figure; plot(squeeze(nanmean(data_epoch_thr.eyedat(:,1,:),1)));hold on;
  144. % plot(squeeze(nanmean(data_epoch_thr.eyedat(:,2,:),1)));
  145. %%
  146. data_epoch_thr.trialinfo = [stimuli_info]; %adding trial info
  147. %% Done. Save it.
  148. partID=subjects_eyedata{ppp}
  149. placetosave=[mainfolder 'eyelink_preprocessed/mean_recentered_th100/object_1_onset_11_seconds/' partID '.mat']
  150. save (placetosave,'data_epoch_thr','-v7.3')
  151. end