DetectBlinks360.m 3.0 KB

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