Detection of the Heartbeat and Events in the Cardiac Cycle