A method and apparatus are disclosed for preventing heart rhythm disturbances by optimally recording cardiac electrical activity, optimally measuring beat-to-beat variability in the morphology of electrocardiographic waveforms, and using the measured beat-to-beat variability to control the delivery of therapy to the heart.