Calculate RMSSD and SDNN from RR Intervals or Beat-to-Beat Data
Paste a comma-separated list of values (e.g., from a CSV export or heart rate monitor).
RMSSD
0 ms
Primary vagal tone metric
SDNN
0 ms
Overall variability
Mean Heart Rate
0 bpm
Samples Analyzed
0 beats
How to Calculate Heart Rate Variability (HRV) from Heart Rate
Heart Rate Variability (HRV) is the physiological phenomenon of variation in the time interval between consecutive heartbeats. Unlike a standard "Average Heart Rate" which smooths out data over a minute, HRV requires the specific timing of every single beat, known as the RR Interval (the time between R-waves on an ECG).
1. Understanding the Data Input
To calculate HRV manually or via a tool, you cannot use a single number like "60 BPM". You need a time series.
RR Intervals (ms): This is the raw time in milliseconds between beats (e.g., 800ms, 850ms, 780ms). This is the preferred scientific input.
Instantaneous BPM: If your device gives you the heart rate for every specific beat (e.g., 60, 62, 58), this can be converted to milliseconds using the formula: ms = 60,000 / BPM.
2. The RMSSD Calculation (The Gold Standard)
RMSSD (Root Mean Square of Successive Differences) is the most reliable metric for estimating vagal tone (parasympathetic nervous system activity). It is less influenced by breathing patterns than other metrics. The formula is:
RMSSD = √ [ (Sum of squared differences between adjacent RR intervals) / (Number of intervals – 1) ]
Step-by-Step Calculation:
Calculate the difference between consecutive beats (Beat 2 – Beat 1, Beat 3 – Beat 2, etc.).
Square each of these differences.
Calculate the average (mean) of these squared differences.
Take the square root of that average.
3. The SDNN Calculation
SDNN (Standard Deviation of NN intervals) measures the overall variability in the recording. It reflects both sympathetic and parasympathetic activity.
SDNN = √ [ (Sum of (Each RR interval – Mean RR)^2) / (Total number of beats – 1) ]
Essentially, this is the standard deviation of your list of RR intervals. Higher SDNN values generally correlate with better overall health and resilience to stress.
4. Interpreting Your Results
High HRV: Generally indicates a state of recovery, low stress, and a healthy autonomic nervous system. Athletes often see high HRV when well-rested.
Low HRV: Can indicate stress, fatigue, illness, or overtraining. It suggests the sympathetic (fight-or-flight) system is dominant.
Note: HRV is highly individual. It is best used by comparing your own daily values against your personal baseline rather than comparing yourself to others.
function updatePlaceholder() {
var isBPM = document.getElementById('typeBPM').checked;
var textarea = document.getElementById('rrData');
if (isBPM) {
textarea.placeholder = "Example BPM series: 60, 62, 58, 65, 61…";
} else {
textarea.placeholder = "Example ms series: 1000, 950, 1020, 980, 1010…";
}
}
function calculateHRV() {
// Reset UI
document.getElementById('errorMsg').style.display = 'none';
document.getElementById('resultsArea').style.display = 'none';
// 1. Get Input
var rawText = document.getElementById('rrData').value;
var isBPM = document.getElementById('typeBPM').checked;
// 2. Parse Data
// Split by commas, spaces, newlines, tabs
var textValues = rawText.split(/[ , \n\t]+/);
var rrIntervals = [];
for (var i = 0; i 0) {
// Conversion logic
if (isBPM) {
// Convert BPM to ms: 60000 / bpm
// Validate BPM to avoid divide by zero or unrealistic numbers
if (val > 20 && val 200 && val < 3000) {
rrIntervals.push(val);
}
}
}
}
// 3. Validation
if (rrIntervals.length < 2) {
var err = document.getElementById('errorMsg');
err.innerHTML = "Please enter at least 2 valid data points to calculate variability.";
err.style.display = 'block';
return;
}
// 4. Calculations
var n = rrIntervals.length;
// — Calculate Mean RR —
var sumRR = 0;
for (var k = 0; k < n; k++) {
sumRR += rrIntervals[k];
}
var meanRR = sumRR / n;
// — Calculate Mean Heart Rate —
var meanHR = 60000 / meanRR;
// — Calculate SDNN (Standard Deviation) —
// Sum of squared differences from Mean
var sumSquaredDiffMean = 0;
for (var j = 0; j < n; j++) {
var diff = rrIntervals[j] – meanRR;
sumSquaredDiffMean += (diff * diff);
}
// SDNN formula uses N-1 (sample standard deviation)
var sdnn = Math.sqrt(sumSquaredDiffMean / (n – 1));
// — Calculate RMSSD —
// Root Mean Square of Successive Differences
var sumSquaredSuccessiveDiff = 0;
for (var m = 0; m < n – 1; m++) {
var diffSuccessive = rrIntervals[m+1] – rrIntervals[m];
sumSquaredSuccessiveDiff += (diffSuccessive * diffSuccessive);
}
var rmssd = Math.sqrt(sumSquaredSuccessiveDiff / (n – 1));
// 5. Output Results
document.getElementById('resRMSSD').innerHTML = rmssd.toFixed(1) + ' ms';
document.getElementById('resSDNN').innerHTML = sdnn.toFixed(1) + ' ms';
document.getElementById('resMeanHR').innerHTML = Math.round(meanHR) + ' bpm';
document.getElementById('resCount').innerHTML = n + ' beats';
document.getElementById('resultsArea').style.display = 'grid';
}