Blink detection algorithm