123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- % Preprocessing eye data
- clear all
- subjects_eyedata={'pil01';'pil02';'pi03';'p04';'p05';'p06';'p07';'p08';'p09';...
- 'p10';'p11';'p12';'p13';'p14';'p15';'p16';'p17';'p18';...
- 'p19';'p20';'p21';'p22';'p23';'p24';'p25';'p26';'p27';'p28';'p29';'p30'...
- ;'p31';'p32';'p34';'p35';'p36';'p37';'p38';'p39';'p40';'p41';...
- 'p42';'p43';'p44';'p45';'p46';'p47';'p48';'p49';'p50';'p51';'p52';...
- 'p53';'p54';'p55';'p56';'p57'};
- subjects_sub= [{'pil01'};{'pil02'};{'pi03'};{'p04'};{'p05'};{'p06'};{'p07'};{'p08'};{'p09'};...
- {'p10'};{'p11'};{'p12'};{'p13'};{'p14'};{'p15'};{'p16'};{'p17'};{'p18'};...
- {'p19'};{'p20'};{'p21'};{'p22'};{'p23'};{'p24'};{'p25'};{'p26'};{'p27'};{'p28'};{'p29'};{'p30'};...
- {'p31'};{'p32'};{'p34'};{'p35'};{'p36'};{'p37'};...
- {'p38'};{'p39'};{'p40'};{'p41'};{'p42'};{'p43'};{'p44'};{'p45'};{'p46'};{'p47'};...
- {'p48'};{'p49'};{'p50'};{'p51'};{'p52'};{'p53'};{'p54'};{'p55'};{'p56'};{'p57'}...
- ]
- %%
- for ppp=1:length(subjects_eyedata) %per participant
- %% Trigger info (EEG and Eye-Tracking)
- % % Changes: Gaze-off triggers removed (this info is included in the
- % output file). Triggers for "Thanks" messages included.
-
- % % -orientations (1:16): 001:1:016
- % % -sample item code (1:3): 20:20:60
- % % -1st/2nd sample position: 000/100
- % %
- % % i.e. item 2 at 45?? in first sample position would be 42; in 2nd sample position t would be 142
- % %
- % % - first retrocue: 1/2 (first or second item respectively)
- % % - second retrocue (for the uncued item): 3/4 (first or second item respectively)
- % %
- % % - thanks message after test for the CUED item: 5
- % % - thanks message after test for the UNCUED item: 6
- % %
- % % -Object onset in abstract test for the CUED item: 201:209 (object identity from 1 to 9)
- % % -Object onset in abstract test for the UNCUED item: 211:219 (object identity from 1 to 9)
- % %
- % % -Object onset in concrete test for the CUED item: 220/221 (for left/right tilted)
- % % -Object onset in concrete test for the UNCUED item: 223/224 (for left/right tilted)
- % %
- % % -230 Ping - First delay
- % % -231 Oddball Ping - First delay
- % %
- % % -232 Ping - Second delay
- % % -233 Oddball - Second delay
- % %
- % % -241 left button press
- % % -242 right button press
- % % -243 up/accept button press
- % % -244 feedback cued item
- % % -245 feedback uncued item
- % %
- % % -246 beginning/end of the task
- partID_prepro=subjects_eyedata{ppp};
- partID_outpufile=subjects_sub{ppp};
- mainfolder=''
- vinstoload=[mainfolder 'eyelink_matlab/' partID_prepro '.mat']
- load(vinstoload)
- if strcmp( partID_outpufile,'p11')
- load([mainfolder '/logfiles/resultfile_p11_table_repaired.mat'])
- subtable=sub
- else
- sub = tdfread([mainfolder 'logfiles/resultfile_' partID_outpufile '.txt'],'tab'); %Logfile for this participant
- subtable=struct2table(sub);
- end
- % Setting all possible triggers (just the first item on screen)
- counter=1
- allposi=[]
- for ori = 1:16
- for item=1:3
- for posi=1
- positri=ori+(item*20)+((posi==2)*100);
- postri(counter)=(positri);
- allposi=[allposi postri];
- end
- end
- end
- if ppp>=20
- allposi=[allposi 100];
- end
- cfg.data=mdat
- cfg.triggers=allposi
- cfg.prestim = 1000 %time prestim in ms
- cfg.poststim = 10000 %time prestim in ms
- data_epoch= maketrials_eyetracking_V1(cfg)
- %%
- %% Using logfile to add info of interest to the EEG data
- % Since we have 2 trigger per trial, let create a better table
- t_counter=0;
- stimuli_info=[];
- rotlist=unique(subtable.object_1_rot)
- for t = 1:length(subtable.trial)
-
- found = find(subtable.trial == t);
-
- t_counter=t_counter+1;
- stimuli_info.trial(t_counter,1) = subtable.trial(t); %Trial number;
- stimuli_info.object_1_id(t_counter,1) = subtable.object_1_id(t); %Object presented first;
- stimuli_info.object_1_rot(t_counter,1) = subtable.object_1_rot(t); %Object presented first;
- stimuli_info.object_1_position(t_counter,1) = 1; %Object presented first
- stimuli_info.object_1_trigger(t_counter,1) = subtable.trigger_object_1(t); %Object presented first;
- stimuli_info.object_1_rot_n(t_counter,1) = find(subtable.object_1_rot(t)==rotlist); %Object presented first;
-
- stimuli_info.object_2_id(t_counter,1) = subtable.object_2_id(t); %Object presented 2;
- stimuli_info.object_2_rot(t_counter,1) = subtable.object_2_rot(t); %Object presented 2;
- stimuli_info.object_2_position(t_counter,1) = 2; %Object presented 2
- stimuli_info.object_2_trigger(t_counter,1) = subtable.trigger_object_2(t); %Object presented first;
- stimuli_info.object_2_rot_n(t_counter,1) = find(subtable.object_2_rot(t)==rotlist); %Object presented first;
- stimuli_info.object_cued_id(t_counter,1) =subtable.object_cued_id(t);
- stimuli_info.object_cued_rot(t_counter,1) =subtable.object_cued_rot(t);
-
- stimuli_info.object_uncued_id(t_counter,1) =subtable.object_uncued_id(t);
- stimuli_info.object_uncued_rot(t_counter,1) =subtable.object_uncue_rot(t);
-
- stimuli_info.retrocue(t_counter,1) =subtable.retro_cue(t);
- stimuli_info.retrocue_uncued(t_counter,1) =subtable.retro_cue_uncued(t);
- stimuli_info.testing_uncued(t_counter,1) =subtable.testing_uncued(t);
-
- end
-
-
- stimuli_info=struct2table(stimuli_info) %double check
-
-
- %%
- if sum(stimuli_info.object_1_trigger'~=data_epoch.trigger_onset) %this should be 0
- error('Mismatch trials and triggers')
- end
-
- %% Recentered using mean
- data_epoch_recenter=data_epoch;
-
- allx=data_epoch.eyedat(:,1,:);
- mx=nanmean(allx(:))
-
- ally=data_epoch.eyedat(:,2,:);
- my=nanmean(ally(:))
- data_epoch_recenter.eyedat(:,1,:)=data_epoch.eyedat(:,1,:)-mx;
- data_epoch_recenter.eyedat(:,2,:)=data_epoch.eyedat(:,2,:)-my;
-
- %% if we need to visualise
- % figure; plot(squeeze(nanmean(data_epoch_recenter.eyedat(:,1,:),1)));hold on;
- % plot(squeeze(nanmean(data_epoch_recenter.eyedat(:,2,:),1)));
- %% Using a threshold to excluded not centered gaze
- data_epoch_thr=data_epoch_recenter;
- th=100; %pixel threshold
- cXY = [0,0]; %this should be the new center after re-centering
- Euc_dist=NaN(size(data_epoch_recenter.eyedat,1),size(data_epoch_recenter.eyedat,3));
- for tr = 1:size(data_epoch_recenter.eyedat,1) %trial
- for tt=1:size(data_epoch_recenter.eyedat,3) %time
- dataXY = [data_epoch_recenter.eyedat(tr,1,tt),data_epoch_recenter.eyedat(tr,2,tt)];
- Euc_dist(tr,tt) = norm( cXY - dataXY );
-
- if Euc_dist(tr,tt)>th
- data_epoch_thr.eyedat(tr,:,tt)=NaN;
- end
-
- end
- end
- %% if we need to visualise
- % figure; plot(squeeze(nanmean(data_epoch_thr.eyedat(:,1,:),1)));hold on;
- % plot(squeeze(nanmean(data_epoch_thr.eyedat(:,2,:),1)));
- %%
- data_epoch_thr.trialinfo = [stimuli_info]; %adding trial info
-
- %% Done. Save it.
- partID=subjects_eyedata{ppp}
- placetosave=[mainfolder 'eyelink_preprocessed/mean_recentered_th100/object_1_onset_11_seconds/' partID '.mat']
- save (placetosave,'data_epoch_thr','-v7.3')
-
- end
-
|