function [ fixations ] = labelFixationsViaIDT( EyeMove, mode, durationThreshold, dispersionThreshold ) %%% labels data by applying an IDT fixation algorithms %%% on the given EyeMove data %%% %%% EyeMove: eye movements of the participant [time|Lx|Ly|Rx|Ry|Hx|Hy] %%% mode: L,R %%% durationThreshold: minimum fixation duration (in millisecond) %%% dispersionThreshold: maximum disperion within a fixation (pixel based) %%% %%% Output: %%% fixation Nx4 [posX | posY | startTimestamp | duration] %%% Created by: Jakob Karolus %%% Last updated: 2016-06-29 switch upper(mode) case 'L' eyeData = EyeMove(:,1:3); case 'R' eyeData = [EyeMove(:,1) EyeMove(:, 4:5)]; end fixations = []; window = eyeData(1,:); counter=1; %while there is still data left while counter <= size(eyeData,1) %construct an initial fixation window while (window(end,1) - window(1,1)) < durationThreshold && counter < size(eyeData,1) counter = counter+1; window = [window; eyeData(counter, :)]; end %add data as long as the window's dispersion is under the threshold if calcDispersion(window) <= dispersionThreshold while calcDispersion(window) <= dispersionThreshold counter = counter+1; if counter > size(eyeData,1) break; end window = [window; eyeData(counter, :)]; end %remove the last point again (broke disperionThreshold) newFixationWindow = window(1:end-1,:); %if data is left -> start a new window if counter <= size(eyeData,1) window = eyeData(counter, :); end %compute centroid and duration and add to fixation array meanX = mean(newFixationWindow(:,2)); meanY = mean(newFixationWindow(:,3)); startTime = newFixationWindow(1,1); duration = newFixationWindow(end,1) - newFixationWindow(1,1); fixations = [fixations; meanX meanY startTime duration]; else %remove the first data point of the window and try again window = window(2:end,:); end end end