first implementation of beat detection