73 lines
2.3 KiB
Matlab
73 lines
2.3 KiB
Matlab
function[obj] = remove_blinks(obj, settings)
|
|
|
|
eyes = fieldnames(obj.data);
|
|
for e = 1:length(eyes)
|
|
eye = eyes{e};
|
|
signal = obj.data.(eye).uncorrected.raw;
|
|
|
|
%no data available for eye
|
|
if isempty(signal)
|
|
continue
|
|
end
|
|
|
|
%% Kill the missing datapoints
|
|
missing = find(obj.time == signal);
|
|
signal(missing) = NaN;
|
|
|
|
%% store original signal for reference
|
|
obj.data.(eye).uncorrected.raw = signal;
|
|
obj.blink_count.(eye) = 0;
|
|
obj.missing_data_count.(eye) = 0;
|
|
%% Kill the blinks (pupil dilation dip)
|
|
nans = find(isnan(signal));
|
|
|
|
%% Count the NaNs before extending them.
|
|
nans=find(isnan(signal));
|
|
dnans = diff(nans);
|
|
|
|
missing_data_list = find(dnans>1);
|
|
missing_data_count = 0;
|
|
if ~isempty(missing_data_list)
|
|
blink_list(:,1) = nans(missing_data_list);
|
|
blink_list(:,2) = dnans(missing_data_list);
|
|
blink_list(:,3) = dnans(missing_data_list) < settings.MaximumBlinkSize;
|
|
|
|
obj.blink_count.(eye) = length(find(blink_list(:,3)));
|
|
obj.missing_data_count.(eye) = length(missing_data_list);
|
|
|
|
obj.blinks.(eye) = blink_list;
|
|
end
|
|
|
|
%% Extend the NaNs
|
|
for n = 1:length(nans)
|
|
window = [nans(n)-settings.BlinkExtension(1):nans(n)+settings.BlinkExtension(2)];
|
|
window(find(window<1)) = []; %% kill the negative indices for early blinks
|
|
signal(window) = NaN;
|
|
end
|
|
|
|
if isempty(obj.blink_count.(eye))
|
|
obj.blink_count.(eye) = 0;
|
|
end
|
|
|
|
if isempty(obj.missing_data_count.(eye))
|
|
obj.missing_data_count.(eye) = 0;
|
|
end
|
|
|
|
%% determine quality;
|
|
obj.quality.(eye) = 100 - (length(find(isnan(signal))) / length(signal)*100);
|
|
obj.valid = 1;
|
|
|
|
if (obj.quality.(eye) < settings.QualityThreshold)
|
|
obj.display_and_log(sprintf('\t*) %2d blinks filtered (%2d missing data events); quality : %2d percent -> Trial excluded\n', obj.blink_count.(eye), obj.missing_data_count.(eye),round(obj.quality.(eye))));
|
|
obj.valid.(eye) = 0;
|
|
else
|
|
obj.display_and_log(sprintf('\t*) %2d blinks filtered (%2d missing data events); quality : %2d percent', obj.blink_count.(eye), obj.missing_data_count.(eye),round(obj.quality.(eye))));
|
|
end
|
|
|
|
%% Interpolate NaNs
|
|
signal= obj.inpaint_nans(signal);
|
|
|
|
obj.data.(eye).uncorrected.interpolated = signal;
|
|
|
|
end
|