find peaks and valleys