Skip to content

Commit db7637a

Browse files
committed
Merge branch 'master' into release
2 parents 57662ec + 551d750 commit db7637a

File tree

4 files changed

+45
-31
lines changed

4 files changed

+45
-31
lines changed

I2MC.m

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33
% The I2MC algorithm was designed to accomplish fixation detection in data
44
% across a wide range of noise levels and when periods of data loss may
55
% occur.
6-
6+
%
77
% Cite as:
88
% Hessels, R.S., Niehorster, D.C., Kemner, C., & Hooge, I.T.C., (2016).
99
% Noise-robust fixation detection in eye-movement data - Identification by
10-
% 2-means clustering (I2MC). Submitted.
11-
10+
% 2-means clustering (I2MC). Behavior Research Methods.
11+
%
1212
% For more information, questions, or to check whether we have updated to a
1313
% better version, e-mail: [email protected] / [email protected]. I2MC is
1414
% available from www.github.com/royhessels/I2MC
15-
15+
%
1616
% Most parts of the I2MC algorithm are licensed under the Creative Commons
1717
% Attribution 4.0 (CC BY 4.0) license. Some functions are under MIT
1818
% license, and some may be under other licenses.
19-
19+
%
2020
% Quick start guide for adopting this script for your own data:
2121
% 1) Build an import function specific for your data (see importTobiiTX300
2222
% for an example).
23-
23+
%
2424
% 2) Change line 106 to use your new import function. The format should be:
2525
%
2626
% data.time for the timestamp
@@ -31,15 +31,15 @@
3131
% You may provide coordinates from both eyes, only the left, only the
3232
% right, or only the average.
3333
% Gaze coordinates should be in pixels, timestamps should be in milliseconds
34-
34+
%
3535
% 3) Adjust the variables in the "necessary variables" section to match your
3636
% data
3737
% 4) Run the algorithm
38-
39-
% Requirements: Signal Processing Toolbox for downsampling. If not
40-
% available you may set opt.downsample to []. This may, however, degrade
41-
% performance of the algorithm.
42-
38+
%
39+
% Note: Signal Processing Toolbox is required for the default downsampling
40+
% procedure. If not available, set opt.downsampFilter to 0. This will use a
41+
% different downsampling procedure.
42+
%
4343
% Tested on MATLAB R2012a, R2014b & R2016a
4444

4545
%% INITIALIZE
@@ -83,10 +83,11 @@
8383
% opt.maxdisp = opt.xres*0.2*sqrt(2); % maximum displacement during missing for interpolation to be possible
8484
%
8585
% % K-MEANS CLUSTERING
86-
% opt.windowtime = 0.2; % time window (s) over which to calculate 2-means clustering (choose value so that max. 1 saccade can occur)
87-
% opt.steptime = 0.02;% time window shift (s) for each iteration. Use zero for sample by sample processing
88-
% opt.maxerrors = 100; % maximum number of errors allowed in k-means clustering procedure before proceeding to next file
86+
% opt.windowtime = 0.2; % time window (s) over which to calculate 2-means clustering (choose value so that max. 1 saccade can occur)
87+
% opt.steptime = 0.02; % time window shift (s) for each iteration. Use zero for sample by sample processing
88+
% opt.maxerrors = 100; % maximum number of errors allowed in k-means clustering procedure before proceeding to next file
8989
% opt.downsamples = [2 5 10];
90+
% opt.downsampFilter = 0; % use chebychev filter when downsampling? 1: yes, 0: no. requires signal processing toolbox. is what matlab's downsampling functions do, but could cause trouble (ringing) with the hard edges in eye-movement data
9091
%
9192
% % FIXATION DETERMINATION
9293
% opt.cutoffstd = 2; % number of standard deviations above mean k-means weights will be used as fixation cutoff

README

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
The I2MC algorithm was designed to accomplish fixation detection in data across a wide range of noise levels and when periods of data loss may occur.
22

33
Cite as:
4-
Hessels, R.S., Niehorster, D.C., Kemner, C., & Hooge, I.T.C., (2016). Noise-robust fixation detection in eye-movement data - Identification by 2-means clustering (I2MC). Submitted.
4+
Hessels, R.S., Niehorster, D.C., Kemner, C., & Hooge, I.T.C., (2016). Noise-robust fixation detection in eye-movement data - Identification by 2-means clustering (I2MC). Behavior Research Methods.
55

66
For more information, questions, or to check whether we have updated to a better version, e-mail: [email protected] / [email protected]. I2MC is available from www.github.com/royhessels/I2MC
77

@@ -17,11 +17,13 @@ data.left.X & data.left.Y for left gaze coordinates
1717
data.right.X & data.right.Y for right gaze coordinates
1818
data.average.X & data.average.Y for average of right and left gaze coordinates
1919

20-
You may provide coordinates from both eyes, only the left, only the right, or only the average. Gaze coordinates should be in pixels, timestamps should be in milliseconds
20+
You may provide coordinates from both eyes, only the left, only the right, or only the average.
21+
Gaze coordinates should be in pixels, timestamps should be in milliseconds
2122

22-
3) Adjust the variables in the "necessary variables" section to match your data
23+
3) Adjust the variables in the "necessary variables" section to match your
24+
data
2325
4) Run the algorithm
2426

25-
Requirements: Signal Processing Toolbox for downsampling. If not available you may set opt.downsample to []. This may, however, degrade performance of the algorithm.
27+
Note: Signal Processing Toolbox is required for the default downsampling procedure. If not available, set opt.downsampFilter to 0. This will use a different downsampling procedure.
2628

2729
Tested on MATLAB R2012a, R2014b & R2016a

functions/I2MC/I2MCfunc.m

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
par.windowtime = .2; % time window (s) over which to calculate 2-means clustering (choose value so that max. 1 saccade can occur)
3030
par.steptime = .02; % time window shift (s) for each iteration. Use zero for sample by sample processing
3131
par.downsamples = [2 5 10]; % downsample levels (can be empty)
32+
par.downsampFilter = 1; % use chebychev filter when downsampling? 1: yes, 0: no. requires signal processing toolbox. is what matlab's downsampling functions do, but could cause trouble (ringing) with the hard edges in eye-movement data
3233
par.chebyOrder = 8; % order of cheby1 Chebyshev downsampling filter, default is normally ok, as long as there are 25 or more samples in the window (you may have less if your data is of low sampling rate or your window is small
3334
par.maxerrors = 100; % maximum number of errors allowed in k-means clustering procedure before proceeding to next file
3435
% FIXATION DETERMINATION
@@ -54,7 +55,7 @@
5455
checkNumeric(value,key);
5556
checkScalar(value,key);
5657
par.(key) = value;
57-
case {'chebyOrder','maxerrors','edgeSampInterp'}
58+
case {'downsampFilter','chebyOrder','maxerrors','edgeSampInterp'}
5859
checkInt(value,key);
5960
checkScalar(value,key);
6061
par.(key) = value;
@@ -158,7 +159,7 @@
158159

159160
% get kmeans-clustering for averaged signal
160161
fprintf('2-Means clustering started for averaged signal \n');
161-
[data.finalweights,stopped] = twoClusterWeighting(xpos,ypos,missingn,par.downsamples,par.chebyOrder,par.windowtime,par.steptime,par.freq,par.maxerrors);
162+
[data.finalweights,stopped] = twoClusterWeighting(xpos,ypos,missingn,par.downsamples,par.downsampFilter,par.chebyOrder,par.windowtime,par.steptime,par.freq,par.maxerrors);
162163

163164
% check whether clustering succeeded
164165
if stopped
@@ -170,7 +171,7 @@
170171
elseif q2Eyes
171172
% get kmeans-clustering for left eye signal
172173
fprintf('2-Means clustering started for left eye signal \n');
173-
[finalweights_left,stopped] = twoClusterWeighting(llx,lly,llmiss,par.downsamples,par.chebyOrder,par.windowtime,par.steptime,par.freq,par.maxerrors);
174+
[finalweights_left,stopped] = twoClusterWeighting(llx,lly,llmiss,par.downsamples,par.downsampFilter,par.chebyOrder,par.windowtime,par.steptime,par.freq,par.maxerrors);
174175

175176
% check whether clustering succeeded
176177
if stopped
@@ -180,7 +181,7 @@
180181

181182
% get kmeans-clustering for right eye signal
182183
fprintf('2-Means clustering started for right eye signal \n');
183-
[finalweights_right,stopped] = twoClusterWeighting(rrx,rry,rrmiss,par.downsamples,par.chebyOrder,par.windowtime,par.steptime,par.freq,par.maxerrors);
184+
[finalweights_right,stopped] = twoClusterWeighting(rrx,rry,rrmiss,par.downsamples,par.downsampFilter,par.chebyOrder,par.windowtime,par.steptime,par.freq,par.maxerrors);
184185

185186
% check whether clustering succeeded
186187
if stopped

functions/I2MC/twoClusterWeighting.m

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
function [finalweights,stopped] = twoClusterWeighting(xpos,ypos,missing,downsamples,chebyOrder,windowtime,steptime,freq,maxerrors)
1+
function [finalweights,stopped] = twoClusterWeighting(xpos,ypos,missing,downsamples,downsampFilter,chebyOrder,windowtime,steptime,freq,maxerrors)
22
% Calculates 2-means cluster weighting for eye-tracking data
33
%
44
% Input:
55
% xpos,ypos = horizontal and vertical coordinates from eye-tracker over which to calculate 2-means clustering
66
% missingn = boolean indicating which samples are missing
77
% downsamples = downsample levels used for data (1/no downsampling is always done, don't specify that)
8+
% downsampFilter = use chebychev filter when downsampling? 1: yes, 0: no. requires signal processing toolbox. is what matlab's downsampling functions do, but could cause trouble (ringing) with the hard edges in eye-movement data
89
% chebyOrder = order of Chebyshev downsampling filter
910
% windowtime = time window (s) over which to calculate 2-means clustering (choose value so that max. 1 saccade can occur)
1011
% steptime = time window (s) in each iteration. Use zero for sample by sample processing
@@ -35,12 +36,17 @@
3536
nd = length(downsamples);
3637
assert(~any(mod(freq,downsamples)),'Some of your downsample levels are not divisors of your sampling frequency')
3738

38-
% filter signal. Follow the lead of decimate(), which first runs a
39-
% Chebychev filter as specified below
40-
rip = .05; % passband ripple in dB
41-
[b,a,idxs] = deal(cell(1,nd));
39+
if downsampFilter
40+
% filter signal. Follow the lead of decimate(), which first runs a
41+
% Chebychev filter as specified below
42+
rip = .05; % passband ripple in dB
43+
[b,a] = deal(cell(1,nd));
44+
for p=1:nd
45+
[b{p},a{p}] = cheby1(chebyOrder, rip, .8/downsamples(p));
46+
end
47+
end
48+
idxs = cell(1,nd);
4249
for p=1:nd
43-
[b{p},a{p}] = cheby1(chebyOrder, rip, .8/downsamples(p));
4450
idxs{p} = fliplr(nrsamples:-downsamples(p):1);
4551
end
4652

@@ -94,8 +100,12 @@
94100
% number of samples is reduced. select samples such that they are till
95101
% end of window
96102
for p=1:nd
97-
ll_d{p+1} = filtfilt(b{p},a{p},ll_d{1});
98-
ll_d{p+1} = ll_d{p+1}(idxs{p},:);
103+
if downsampFilter
104+
ll_d{p+1} = filtfilt(b{p},a{p},ll_d{1});
105+
ll_d{p+1} = ll_d{p+1}(idxs{p},:);
106+
else
107+
ll_d{p+1} = ll_d{1}(idxs{p},:);
108+
end
99109
end
100110

101111
% do 2-means clustering

0 commit comments

Comments
 (0)