this method came from Med. Phys. 33 (10), Oct 2006. and could be used to detect peak and valley in free-breathing respiratory waveforms.