1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- % DetectBlinks360.m
- %
- % This function detects blinks by using intervals of noise in the provided ARFF
- % data together with saccade detection. For every noise interval searches on
- % both directions (forward and backwards in time) and if it finds a saccade
- % within a given time distance it labels the noise, the saccade interval, and
- % the samples in between as blink.
- %
- % input:
- % data - data from the ARFF file
- % metadata - metadata from the ARFF file
- % attributes - attributes from the ARFF file
- % typeOfMotion- 1 -> eye FOV, 2 -> eye+head
- % params - parameters to use for saccade detection
- %
- % output:
- % result - logical vector with same length as data and true for every sample that is part of a blink
- function result = DetectBlinks360(data, metadata, attributes, typeOfMotion, params)
- % initialize search interval on both sides of the blink in us
- c_searchRange = 40000;
- c_minConf = 0.5;
- timeInd = GetAttPositionArff(attributes, 'time');
- confInd = GetAttPositionArff(attributes, 'confidence');
-
- noise = false(size(data,1),1);
- noise(data(:,confInd) < c_minConf) = 1;
- saccades = DetectSaccades360(data, metadata, attributes, typeOfMotion, params);
- % initially
- result = noise;
- % search for noise indices
- isNoiseActive = 0;
- startIndex = -1;
- endIndex = -1;
- for noiseIndex=1:size(noise,1)
- if (isNoiseActive == 0 && noise(noiseIndex) == 1)
- isNoiseActive = 1;
- startIndex = noiseIndex;
- end
- if (isNoiseActive == 1 && noise(noiseIndex) == 0)
- isNoiseActive = 0;
- endIndex = noiseIndex-1;
- UpdateResult();
- end
- end
- % function UpdateResult:
- % It searches on both sides of the noise intervals for blinks.
- function UpdateResult()
- % search backwards
- searchIndex = startIndex;
- saccadeFound = false;
- while (searchIndex > 0)
- if (data(startIndex,timeInd)-data(searchIndex,timeInd) > c_searchRange && saccadeFound==false)
- break;
- end
- if (saccades(searchIndex) && saccadeFound==false)
- saccadeFound = true;
- end
- if (~saccades(searchIndex) && saccadeFound==true)
- result(searchIndex+1:startIndex) = 1;
- break;
- end
-
- searchIndex = searchIndex-1;
- end
- % search forward
- searchIndex = endIndex;
- saccadeFound = false;
- while (searchIndex <= size(data,1))
- if (data(searchIndex,timeInd)-data(endIndex,timeInd) > c_searchRange && saccadeFound==false)
- break;
- end
- if (saccades(searchIndex) && saccadeFound==false)
- saccadeFound = true;
- end
- if (~saccades(searchIndex) && saccadeFound==true)
- result(endIndex+1:searchIndex) = 1;
- break;
- end
-
- searchIndex = searchIndex+1;
- end
- end
- end
|