Peak detection using adaptive thresholding