Home > data-analysis > modules > gaze > fixation_code > merge_small_fix.m

merge_small_fix

PURPOSE ^

This function merge small fixations from second step based on spatial

SYNOPSIS ^

function newList = merge_small_fix(data, fix1, minDist, minDur)

DESCRIPTION ^

 This function merge small fixations from second step based on spatial 
 information. if distance between centers of two consecutive fixations
 is <= minDist, then these fixations will be merged into one.
 
 Inputs:   
    data:       [time cont_eye_x cont_eye_y velocity], Nx4
   fix1:       start and end indexes for fixation from second step
   minDur:     minimun duration for fixation.
   minDist:    small fixations will be merged if if they are
               close enough spatially (distance between centers of
               fixations <= minDist)
 
 Outputs:
   newList:   a list of onset and offset indexes for each fixation,
              n*2

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function newList = merge_small_fix(data, fix1, minDist, minDur)
0002 
0003 % This function merge small fixations from second step based on spatial
0004 % information. if distance between centers of two consecutive fixations
0005 % is <= minDist, then these fixations will be merged into one.
0006 %
0007 % Inputs:
0008 %    data:       [time cont_eye_x cont_eye_y velocity], Nx4
0009 %   fix1:       start and end indexes for fixation from second step
0010 %   minDur:     minimun duration for fixation.
0011 %   minDist:    small fixations will be merged if if they are
0012 %               close enough spatially (distance between centers of
0013 %               fixations <= minDist)
0014 %
0015 % Outputs:
0016 %   newList:   a list of onset and offset indexes for each fixation,
0017 %              n*2
0018 
0019 if isempty(fix1)
0020     error('No fixation found!')
0021 end
0022 
0023 fix3 = fix1;
0024 
0025 % calculate the center of each segment
0026 for i = 1 : size(fix3,1)
0027     fix3(i,3) = mean(data(fix3(i,1):fix3(i,2),2)); % mean x
0028     fix3(i,4) = mean(data(fix3(i,1):fix3(i,2),3)); % mean y
0029 end;
0030 
0031 % merge if needed
0032 nFix2 = 1;
0033 fix2(nFix2,:) = fix3(1,:);
0034 for i = 2 : size(fix3,1)
0035     distance = sqrt((fix3(i,3) - fix2(nFix2,3))^2 + (fix3(i,4) - fix2(nFix2,4))^2);
0036     if ((distance > minDist) || (fix3(i,1)-fix2(nFix2,2) > 4) || ...
0037             (sum(sum(isnan(data(fix2(nFix2,2):fix3(i,1),2:3))) > 0))) % do not merge if there is nan
0038         nFix2 = nFix2 + 1;
0039         fix2(nFix2,:) = fix3(i,:);
0040     else
0041         fix2(nFix2,2) = fix3(i,2);%this does the actual merging if they are close enough
0042     end;
0043 
0044 end;
0045 
0046 % remove the fixation that is shorter than the minimum duration
0047 newList = [];
0048 for i = 1:(size(fix2,1))
0049     if (data(fix2(i,2),1) - data(fix2(i,1),1)) > minDur
0050         newList = [newList; fix2(i,1), fix2(i,2)];
0051     end
0052 end

Generated on Wed 24-May-2017 00:00:56 by m2html © 2005