DetectBlinks360.m 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. % DetectBlinks360.m
  2. %
  3. % This function detects blinks by using intervals of noise in arff as well as
  4. % saccade detection. For every noise interval searches on both direction
  5. % (forward and backwards in time) and if it finds a saccade within a given time
  6. % distance it labels the noise and saccade interval as blink.
  7. %
  8. % input:
  9. % data - data from the ARFF file
  10. % metadata - metadata from the ARFF file
  11. % attributes - attributes from the ARFF file
  12. % typeOfMotion- 1 -> eye FOV, 2 -> eye+head
  13. % params - parameters to use for saccade detection
  14. %
  15. % output:
  16. % result - logical vector with same length as data and true for every sample that is part of a blink
  17. function result = DetectBlinks360(data, metadata, attributes, typeOfMotion, params)
  18. % initialize search interval on both sides of the blink in us
  19. c_searchRange = 40000;
  20. c_minConf = 0.5;
  21. timeInd = GetAttPositionArff(attributes, 'time');
  22. confInd = GetAttPositionArff(attributes, 'confidence');
  23. noise = false(size(data,1),1);
  24. noise(data(:,confInd) < c_minConf) = 1;
  25. saccades = DetectSaccades360(data, metadata, attributes, typeOfMotion, params);
  26. % initially
  27. result = noise;
  28. % search for noise indices
  29. isNoiseActive = 0;
  30. startIndex = -1;
  31. endIndex = -1;
  32. for noiseIndex=1:size(noise,1)
  33. if (isNoiseActive == 0 && noise(noiseIndex) == 1)
  34. isNoiseActive = 1;
  35. startIndex = noiseIndex;
  36. end
  37. if (isNoiseActive == 1 && noise(noiseIndex) == 0)
  38. isNoiseActive = 0;
  39. endIndex = noiseIndex-1;
  40. UpdateResult();
  41. end
  42. end
  43. % function UpdateResult:
  44. % It searches on both sides of the noise intervals for blinks.
  45. function UpdateResult()
  46. % search backwards
  47. searchIndex = startIndex;
  48. saccadeFound = false;
  49. while (searchIndex > 0)
  50. if (data(startIndex,timeInd)-data(searchIndex,timeInd) > c_searchRange && saccadeFound==false)
  51. break;
  52. end
  53. if (saccades(searchIndex) && saccadeFound==false)
  54. saccadeFound = true;
  55. end
  56. if (~saccades(searchIndex) && saccadeFound==true)
  57. result(searchIndex+1:startIndex) = 1;
  58. break;
  59. end
  60. searchIndex = searchIndex-1;
  61. end
  62. % search forward
  63. searchIndex = endIndex;
  64. saccadeFound = false;
  65. while (searchIndex <= size(data,1))
  66. if (data(searchIndex,timeInd)-data(endIndex,timeInd) > c_searchRange && saccadeFound==false)
  67. break;
  68. end
  69. if (saccades(searchIndex) && saccadeFound==false)
  70. saccadeFound = true;
  71. end
  72. if (~saccades(searchIndex) && saccadeFound==true)
  73. result(endIndex+1:searchIndex) = 1;
  74. break;
  75. end
  76. searchIndex = searchIndex+1;
  77. end
  78. end
  79. end