Preprocessing_pipeline_epoch_2nd_cue_onset_2022.m 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 triggers
  65. allposi=[3 4];
  66. cfg.data=mdat;
  67. cfg.triggers=allposi;
  68. cfg.prestim = 10000; %time prestim in ms
  69. cfg.poststim = 7500; %time prestim in ms
  70. data_epoch= maketrials_eyetracking_V1(cfg);
  71. %% Using logfile to add info of interest to the EEG data
  72. %Reduce the outputfile to only those trials with a second test
  73. toi=subtable.testing_uncued==1;
  74. subtable=subtable(toi,:);
  75. % Adding more trial info
  76. t_counter=0;
  77. stimuli_info=[];
  78. rotlist=unique(subtable.object_1_rot)
  79. for t = 1:length(subtable.trial)
  80. found = find(subtable.trial == t);
  81. t_counter=t_counter+1;
  82. stimuli_info.trial(t_counter,1) = subtable.trial(t); %Trial number;
  83. stimuli_info.object_1_id(t_counter,1) = subtable.object_1_id(t); %Object presented first;
  84. stimuli_info.object_1_rot(t_counter,1) = subtable.object_1_rot(t); %Object presented first;
  85. stimuli_info.object_1_position(t_counter,1) = 1; %Object presented first
  86. stimuli_info.object_1_trigger(t_counter,1) = subtable.trigger_object_1(t); %Object presented first;
  87. stimuli_info.object_1_rot_n(t_counter,1) = find(subtable.object_1_rot(t)==rotlist); %Object presented first;
  88. stimuli_info.object_2_id(t_counter,1) = subtable.object_2_id(t); %Object presented 2;
  89. stimuli_info.object_2_rot(t_counter,1) = subtable.object_2_rot(t); %Object presented 2;
  90. stimuli_info.object_2_position(t_counter,1) = 2; %Object presented 2
  91. stimuli_info.object_2_trigger(t_counter,1) = subtable.trigger_object_2(t); %Object presented first;
  92. stimuli_info.object_2_rot_n(t_counter,1) = find(subtable.object_2_rot(t)==rotlist); %Object presented first;
  93. stimuli_info.object_cued_id(t_counter,1) =subtable.object_cued_id(t);
  94. stimuli_info.object_cued_rot(t_counter,1) =subtable.object_cued_rot(t);
  95. stimuli_info.object_uncued_id(t_counter,1) =subtable.object_uncued_id(t);
  96. stimuli_info.object_uncued_rot(t_counter,1) =subtable.object_uncue_rot(t);
  97. stimuli_info.retrocue(t_counter,1) =subtable.retro_cue(t);
  98. stimuli_info.retrocue_uncued(t_counter,1) =subtable.retro_cue_uncued(t);
  99. stimuli_info.testing_uncued(t_counter,1) =subtable.testing_uncued(t);
  100. end
  101. stimuli_info=struct2table(stimuli_info) %to double check
  102. %% Recentered using mean
  103. data_epoch_recenter=data_epoch;
  104. allx=data_epoch.eyedat(:,1,:);
  105. mx=nanmean(allx(:))
  106. ally=data_epoch.eyedat(:,2,:);
  107. my=nanmean(ally(:))
  108. data_epoch_recenter.eyedat(:,1,:)=data_epoch.eyedat(:,1,:)-mx;
  109. data_epoch_recenter.eyedat(:,2,:)=data_epoch.eyedat(:,2,:)-my;
  110. %% if we need to visualise
  111. % figure; plot(squeeze(nanmean(data_epoch_recenter.eyedat(:,1,:),1)));hold on;
  112. % plot(squeeze(nanmean(data_epoch_recenter.eyedat(:,2,:),1)));
  113. %% Using a threshold to excluded not centered gaze
  114. data_epoch_thr=data_epoch_recenter;
  115. th=100; %pixel threshold
  116. cXY = [0,0]; %this should be the new center after re-centering
  117. Euc_dist=NaN(size(data_epoch_recenter.eyedat,1),size(data_epoch_recenter.eyedat,3));
  118. for tr = 1:size(data_epoch_recenter.eyedat,1) %trial
  119. for tt=1:size(data_epoch_recenter.eyedat,3) %time
  120. dataXY = [data_epoch_recenter.eyedat(tr,1,tt),data_epoch_recenter.eyedat(tr,2,tt)];
  121. Euc_dist(tr,tt) = norm( cXY - dataXY );
  122. if Euc_dist(tr,tt)>th
  123. data_epoch_thr.eyedat(tr,:,tt)=NaN;
  124. end
  125. end
  126. end
  127. %% if we need to visualise
  128. % figure; plot(squeeze(nanmean(data_epoch_thr.eyedat(:,1,:),1)));hold on;
  129. % plot(squeeze(nanmean(data_epoch_thr.eyedat(:,2,:),1)));
  130. %%
  131. data_epoch_thr.trialinfo = [stimuli_info]; %adding trial info
  132. %% Done. Save it.
  133. %CHANGE THE NAME!!
  134. partID=subjects_eyedata{ppp}
  135. placetosave=[mainfolder 'eyelink_preprocessed/mean_recentered_th100/2nd_cue_onset_17_5__seconds/' partID '.mat']
  136. save (placetosave,'data_epoch_thr','-v7.3')
  137. clearvars -except ppp subjects_eyedata subjects_sub
  138. end