Skip to content

Commit 9022d44

Browse files
committed
made Chebychev filter optional when downsampling
1 parent b85d0f6 commit 9022d44

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

I2MC.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

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)