Calculating heart rate (HR) from an Electrocardiogram (ECG or EKG) is a fundamental task in cardiology and medical monitoring. The ECG records the electrical activity of the heart, and specific points on the ECG waveform, particularly the R-waves of the QRS complex, represent ventricular depolarization. The time between consecutive R-waves (the R-R interval) is a direct indicator of the heart's rhythm and rate.
Method 1: Using R-R Interval (Seconds)
This is the most straightforward method if you can accurately measure the time between two consecutive R-waves.
Explanation: Since there are 60 seconds in a minute, dividing 60 by the R-R interval in seconds gives you the number of heartbeats (and thus, R-waves) that would occur in one minute. This is the heart rate in beats per minute (bpm).
Example: If the R-R interval measured on the ECG is 0.75 seconds, the heart rate is calculated as:
60 / 0.75 = 80 bpm
Method 2: Using ECG Sampling Rate (Hz) and Number of Small Boxes
ECG paper is typically gridded, with small boxes representing 0.04 seconds and large boxes (5 small boxes) representing 0.20 seconds. Many ECG machines also provide a sampling rate in Hertz (Hz), which indicates the number of data points recorded per second.
Formula: Heart Rate (bpm) = (Sampling Rate (Hz) / Number of data points between two R-waves) * 60
Alternatively, if the number of small boxes between R-waves is known: Heart Rate (bpm) = (Number of large boxes between R-waves * 5 + Number of small boxes between R-waves) * 0.04 seconds/small box = R-R Interval (seconds)
Then use Method 1: Heart Rate (bpm) = 60 / R-R Interval (seconds)
Explanation: This method is useful when dealing with digital ECG data or when the paper speed isn't standard. The sampling rate tells you how many data points exist per second. By counting the number of data points between two R-waves, you can determine the R-R interval. Multiplying by 60 converts this to beats per minute.
Example: An ECG has a sampling rate of 500 Hz. If there are 400 data points between two consecutive R-waves:
R-R Interval (seconds) = 400 data points / 500 Hz = 0.8 seconds Heart Rate (bpm) = 60 / 0.8 = 75 bpm
Note: For a regular rhythm, you can average the R-R intervals over a longer period (e.g., 6 seconds) and multiply by 10 for a more accurate estimate of the average heart rate. This is particularly useful in cases of irregular rhythms.
function calculateHeartRate() {
var rrIntervalInput = document.getElementById("rrInterval");
var samplingRateInput = document.getElementById("samplingRate");
var resultDiv = document.getElementById("result");
var rrInterval = parseFloat(rrIntervalInput.value);
var samplingRate = parseFloat(samplingRateInput.value);
resultDiv.innerHTML = ""; // Clear previous result
if (isNaN(rrInterval) || rrInterval <= 0) {
resultDiv.innerHTML = "Please enter a valid R-R interval in seconds.";
return;
}
if (isNaN(samplingRate) || samplingRate <= 0) {
resultDiv.innerHTML = "Please enter a valid ECG sampling rate in Hz.";
return;
}
// Calculate Heart Rate using R-R Interval
var heartRateFromInterval = 60 / rrInterval;
// Display the result
resultDiv.innerHTML = "Calculated Heart Rate: " + heartRateFromInterval.toFixed(1) + " bpm";
}