An electrocardiogram (ECG or EKG) is a medical test that records the electrical activity of the heart over a period of time. It is a simple, non-invasive procedure that can help diagnose various heart conditions, including arrhythmias, myocardial infarction, and electrolyte imbalances.