This calculator helps you determine your heart rate from an electrocardiogram (ECG or EKG) strip. The heart rate is typically measured in beats per minute (BPM). By understanding the relationship between the ECG grid and the timing of the heartbeats, you can accurately estimate the heart rate.
function calculateHeartRate() {
var rrIntervalSmallBoxes = document.getElementById("rrIntervalSmallBoxes").value;
var paperSpeed = document.getElementById("paperSpeed").value;
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = ""; // Clear previous results
// Validate inputs
if (rrIntervalSmallBoxes === "" || paperSpeed === "") {
resultDiv.innerHTML = "Please enter both RR Interval and Paper Speed.";
return;
}
var rrIntervalSmallBoxesNum = parseFloat(rrIntervalSmallBoxes);
var paperSpeedNum = parseFloat(paperSpeed);
if (isNaN(rrIntervalSmallBoxesNum) || isNaN(paperSpeedNum)) {
resultDiv.innerHTML = "Please enter valid numbers for all fields.";
return;
}
if (rrIntervalSmallBoxesNum <= 0 || paperSpeedNum <= 0) {
resultDiv.innerHTML = "RR Interval and Paper Speed must be positive values.";
return;
}
// Standard ECG grid: Each small box is 1 mm wide and represents 0.04 seconds at 25 mm/sec.
// Each large box (5 small boxes) is 5 mm wide and represents 0.20 seconds at 25 mm/sec.
var timePerSmallBox = 0.04; // seconds per small box at 25 mm/sec
var actualTimePerSmallBox = timePerSmallBox * (25 / paperSpeedNum); // Adjust for different paper speeds
var rrIntervalSeconds = rrIntervalSmallBoxesNum * actualTimePerSmallBox;
// Heart Rate (BPM) = 60 seconds / RR interval in seconds
var heartRate = 60 / rrIntervalSeconds;
// Display the result
resultDiv.innerHTML = "Calculated Heart Rate: " + heartRate.toFixed(0) + " BPM";
resultDiv.innerHTML += "(Assuming a standard ECG grid where small boxes are 1mm and large boxes are 5mm)";
}
.ecg-heart-rate-calculator {
font-family: sans-serif;
border: 1px solid #ccc;
padding: 20px;
border-radius: 8px;
max-width: 500px;
margin: 20px auto;
background-color: #f9f9f9;
}
.ecg-heart-rate-calculator h2 {
text-align: center;
margin-bottom: 20px;
color: #333;
}
.ecg-heart-rate-calculator p {
line-height: 1.6;
color: #555;
margin-bottom: 15px;
}
.input-section {
margin-bottom: 20px;
}
.input-section label {
display: block;
margin-bottom: 8px;
font-weight: bold;
color: #444;
}
.input-section input[type="number"] {
width: calc(100% – 22px);
padding: 10px;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box; /* Include padding and border in the element's total width and height */
}
.ecg-heart-rate-calculator button {
display: block;
width: 100%;
padding: 12px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
}
.ecg-heart-rate-calculator button:hover {
background-color: #0056b3;
}
#result {
margin-top: 25px;
padding-top: 15px;
border-top: 1px solid #eee;
text-align: center;
}
#result p {
font-size: 1.1em;
margin-bottom: 10px;
}
#result p:last-child {
font-size: 0.9em;
color: #777;
}