written by
Paul Richardson

Signal to Meaning (Part I): The Signal Processing That Makes HRV Possible

Health & Fitness Computer Science STEM 9 min read

Your heart doesn’t tick like a metronome; even at rest, it naturally speeds up and slows down as your body responds to physical or emotional stress. Those tiny beat-to-beat changes, measured in milliseconds, reflect how your nervous system reacts to your daily choices — how well you’ve slept, how hard you’ve trained, what you’ve eaten, and how you’ve managed stress. Together, they reveal how effectively your body is coping, recovering, and staying in balance. This insight comes from your Heart Rate Variability — or HRV — the measure of how much time changes from one heartbeat to the next.

Wearables from Oura, Whoop, Fitbit, and others rely on signal processing to turn those subtle variations into HRV metrics and actionable insights. These devices use HRV data to estimate how much stress your body and mind are under — and how well you’re recovering and adapting — often summarizing it in metrics like Readiness Score, Recovery Score, or Body Battery.

​Not all wearables measure HRV the same way. Devices like the Oura Ring, Fitbit, and Apple Watch use photoplethysmography (PPG) sensors that track blood flow changes using light to estimate heartbeat timing. These are generally the red and green flashing lights my youngest likes to point out anytime he sees Christmas playing out on my finger from my Oura Ring! Chest straps such as the Polar H10 or Garmin HRM-Pro tend to use electrocardiogram (ECG) signals to record the heart’s electrical activity directly. Despite the different inputs — light versus electricity — the process is the same: detect each beat, measure the intervals, and analyze the variations to calculate HRV.

In this article, we’ll explore using electrocardiogram (ECG) signals to extract HRV — converting raw heartbeat data into meaningful indicators of stress and readiness, the same foundation powering the algorithms behind today’s most advanced devices.

To see the code and a few more technical details I have created and shared a notebook on Kaggle.
Companion Notebook: Signal to Meaning (Part I): The Signal Processing That Makes HRV Possible

From Research to Wearables

Scientists first began studying HRV in the 1960s, but it wasn’t until 1996 that things became standardized. That year, an international task force published Heart Rate Variability: Standards of Measurement, Physiological Interpretation, and Clinical Use — the paper as I understand it still serves as the foundation for how researchers (and now wearables) calculate HRV. These standards created a shared foundation for how HRV is measured and interpreted today.

Today, HRV is built into nearly every major wearable. Wearables like the Oura Ring, Fitbit, Whoop Strap, Garmin watches, and Polar chest straps record your heartbeat, filter out noise, and turn those signals into a single number that reflects how your body is managing stress — and how well you’re recovering from it.

But that simple number hides a lot of complexity. Behind the scenes, your device runs a series of data and signal processing steps to detect each heart beat and interpret your body’s physiological response. Before that Readiness Score or Recovery score or etc... ever appears on your screen, it has to capture and find every heartbeat — and that’s where signal pre-processing for HRV analysis begins.

1. The ECG Signal: Where It All Beings

ECG-signal-processing-HRV
Ten Seconds of Raw ECG Data

An electrocardiogram (ECG) records the heart’s electrical activity as tiny changes in voltage over time.
Each heartbeat creates a characteristic pattern made up of several waves — the P wave, QRS complex, and T wave.

Normal ECG waveform with QRS complex for illustration.

The tall spikes within the QRS complex, known as R-peaks, are especially important because each one represents a single heartbeat. By measuring the time between consecutive R-peaks — the R-R interval — we can observe how the heart’s rhythm shifts from beat to beat.

These small timing differences form the foundation of HRV signal processing, which depends on accurate detection of each heartbeat. Before we can measure HRV accurately, the ECG signal itself needs to be clean — free from noise caused by movement, muscle tension, or electrical interference that can blur or hide individual heartbeats.

That’s why the first step in HRV analysis is signal cleaning and preprocessing — preparing the data so each beat can be detected precisely.

2. Cleaning Up the Noise in ECG for Processing HRV

ECG-signal-processing-HRV
10 secs segment - Raw ECG Data vs Cleaned ECG Data

Raw physiological signals, like the ECG, are rarely perfect. They carry traces of everything happening both around and within us — breathing, muscle tension, motion, even the faint hum of electrical interference. Each of these can blur the true rhythm of the heart — adding drift, noise, and distortion that hide the very features we’re trying to study.

To make sense of all that noise, we first need to clean the signal. This is where filtering comes in — a way to keep what matters and remove what doesn’t. A bandpass filter focuses on the range of frequencies that carry true cardiac activity, typically between 0.5 and 40 hertz. The lower cutoff removes slow baseline drift from breathing or body movement, while the upper cutoff limits high-frequency noise from muscle activity and electrical interference. What’s left is the clean, middle band that captures the heart’s rhythm — the sharp QRS complexes that mark each beat clearly and reliably.

5 secs segment - Raw ECG Data vs Cleaned ECG Data

3. Finding the Peaks​: ECG Signal Processing for HRV

Identified R-Peaks from Clean ECG Data

Once the ECG signal has been cleaned through filtering, the next step is to find each heartbeat — the tall spikes called R-peaks. Each heartbeat on an ECG appears as a distinct spike called the QRS complex — a quick burst of electrical activity that happens as the heart’s ventricles contract to pump blood. The tallest point of that spike, known as the R-peak, marks the exact moment of each heartbeat. By detecting every R-peak and measuring the time between them — what’s called the R–R interval — we can begin to see the subtle variations in rhythm that form the basis of Heart Rate Variability (HRV).

The process of finding each R-peak begins by looking for quick changes in the signal — the steep rises and drops that happen when your heart contracts. When we differentiate a signal, we’re calculating how fast the signal’s amplitude increases or decreases from one sample to the next.

Differentiation highlights where the signal changes rapidly — the steep slopes.

ECG-signal-processing-HRV
Differentiation highlights where the signal changes rapidly — the steep slopes.

Next, the differentiated signal is squared. This step removes any ambiguity between positive and negative slopes, amplifies large changes, and suppresses smaller fluctuations — turning each strong heartbeat into a tall, clear spike. The result is a waveform that clearly marks where the heart’s electrical activity surges — a perfect setup for the next step: smoothing those peaks through moving-window integration. Integration here means collecting or averaging the signal’s energy over a small time window to make heartbeats stand out and noise fade away.

ECG-signal-processing-HRV
Squaring the differentiated ECG removes signal ambiguity, emphasizes large changes and suppresses small ones

This integration acts as a smoothing step, averaging the signal over roughly one-tenth of a second so that each heartbeat appears as a rounded hill instead of a narrow spike — easier to see, detect, and count accurately.

In this example, I use a fixed 100 ms window. That value isn’t arbitrary — it comes from the method proposed by Pan and Tompkins (1985), who found that a 100–150 ms moving-window integration best matches the typical QRS complex duration (around 80–120 ms). This approach captures the energy of each beat cleanly without blending adjacent ones.

Smoothed ECG signal after moving-window integration (100 ms window). Each rounded hill represents the accumulated energy of a heartbeat, transforming the sharp QRS spikes into smoother peaks that make R-peak detection easier and more reliable.

For the final step in separating the real heartbeats from background noise, we use what’s called an adaptive threshold. Instead of relying on one fixed cutoff, an adaptive threshold adjusts based on the signal itself. It’s calculated as the median of the smoothed signal plus a multiple of its standard deviation. In my case, the multiplier k = 2. Think of this as a sensitivity control — a smaller number makes the detector more responsive to smaller bumps (catching more peaks, but also more noise), while a larger number only flags the strongest ones. Setting k=2 for this data hist the sweet spot — sensitive enough to catch true heartbeats, but stable enough to ignore random fluctuations in the signal.

The dashed line marks the adaptive threshold — it shifts with the signal, sitting just high enough above the average to highlight real heartbeats and ignore random noise.

Those subtle millisecond timing differences from one beat to the next form the foundation of Heart Rate Variability (HRV) — and while the numbers may look small, each millisecond of variation reveals how dynamically your nervous system is responding to the world around you.

​Data to Physiology

​Together, these steps show how we use signal processing on ECG to prepare for creating HRV indices. With signal processing we transform raw electrical activity in preparation to get insights into insight stress, recovery, and autonomic balance through HRV.

Validation: Checking Our Results

Validation of R–R interval detection showing sub-millisecond accuracy. The close agreement between reference and detected values confirms that preprocessing preserved the heart’s natural variability, allowing reliable HRV analysis

The Mean Absolute Error (1.42 ms) and Root Mean Squared Error (2.33 ms) demonstrate millisecond-level precision, while a Relative MAE of only 0.20% confirms that residual timing errors represent a very small fraction of each cardiac cycle.

The Reference Mean R-R Interval (711.1 ms) matches the detected mean exactly, indicating that overall heart rate timing has been preserved without measurable bias. The Reference RMSSD (20.1 ms) and detected RMSSD (20.4 ms) remain nearly identical, which confirms that short-term beat-to-beat variability has been maintained accurately.

This gives a lot of confidence in moving forward with the HRV metrics and analysis.

Making Sense of HRV (Part II) — What the Numbers Mean

Now that we understand how HRV is measured and cleaned, the next step is interpreting what those numbers actually tell us. What does a higher or lower HRV mean for recovery, fitness, or stress? How do metrics like RMSSD, SDNN, and pNN50 differ? And how can we use daily HRV trends — whether from Oura, Whoop, or a Polar strap — to make smarter training and lifestyle choices?

In part two, we’ll explore:

  • Time-domain metrics — the simplest ways to quantify beat-to-beat variability.
  • Frequency-domain analysis — what LF, HF, and LF/HF ratios reveal about autonomic balance.
  • Nonlinear measures — how complexity in heart rhythm reflects adaptability.
  • Practical interpretation — what your HRV patterns say about recovery, stress load, and readiness.

To be continued...

Signal Processing: Learning More...

​If you’re interested in learning more about signal processing, there are excellent resources online. I personally spent time auditing several courses from the Digital Signal Processing Specialization on Coursera. These are VERY math heavy (not one of my superpowers), but also very informative. I found the time investment well worth it!

  • Courses 1 and 2 provide a solid foundation for processing ECG data into HRV metrics.
  • Course 3 explores how wearables digitize and store the signal.
  • Course 4 is optional, depending on your depth of interest.​

Data & Notebook

The Python notebook that covers this analysis and generates the figures.
Companion Notebook: Signal to Meaning (Part I): The Signal Processing That Makes HRV Possible

The dataset — the MIT-BIH Arrhythmia Database from Kaggle — includes reference annotations, allowing us to validate how well our ECG signal processing HRV workflow performed.



Oura Ring Fitbit HRV heart rate variability HRV Analysis weable technology data science