Detection of the heartbeat and events in the cardiac cycle.