Pulse detection code