HR/HRV DSP Block

The Heart Rate/Heart Rate Variability (HR/HRV) DSP Block processes physiological signals like PPG (Photoplethysmogram) or ECG (Electrocardiogram) to extract key metrics such as heart rate and HRV (Heart Rate Variability). Heart rate (HR) measures the number of beats per minute (BPM), while heart rate variability (HRV) measures the time intervals between successive heartbeats, also known as interbeat intervals (IBIs).

The HR/HRV DSP Block simplifies these measurements, offering real-time heart rate estimation and HRV analysis on resource-constrained edge devices. The block leverages cutting-edge algorithms for precise feature extraction, ensuring robust performance even in motion-heavy environments.

Once the features are extracted, they can be used to estimate heart rate or, combined with other HRV metrics, inform downstream machine learning tasks such as stress detection, HR prediction, or heart health analysis.

  • Flash footprint: As little as ~7.5 KB for the core algorithm.

  • RAM footprint: As little as ~1.6 KB for the algorithm, with additional RAM for buffering input signals (dependent on window size).

Evaluation available for everyone, deployment only available to Enterprise Plan

All users (Community, Professional and Enterprise Plan) can extract HR/HRV features using this DSP Block for testing purposes. However, the deployment option is only available for Enterprise users. Contact your Solution Engineer to enable it.

To see a demonstration of how to utilize the HR/HRV DSP Block, refer to our tutorial Processing PPG input with HR/HRV DSP Block

Configuration

The HR/HRV DSP Block is designed to extract valuable physiological data from both PPG and ECG signals, with optional accelerometer inputs for enhanced accuracy in motion-prone locations. By configuring this block, you can obtain critical metrics like Heart Rate (HR) and Heart Rate Variability (HRV) in real-time, enabling applications such as fitness tracking, stress monitoring, and health diagnostics. The extracted features can be fine-tuned to match the performance and constraints of edge devices, ensuring both efficiency and accuracy.

Example Configuration:

  • HR Window Size: 2 seconds

  • Frequency: 50 Hz

  • Optional Accelerometer Axes (X, Y, Z) for motion artifact removal.

Outputs

OutputDescription

Heart Rate (HR)

Measured in beats per minute (BPM), updated based on the window size.

Configuration Parameters

ParameterDescription

Window Size

Set the duration for HR calculation (minimum: 2 seconds).

Window Shift

Defines how much the window moves forward after each calculation.

Zero-Pad Data

Optionally pad data to fill the window completely.

Sampling Rate

Recommended at 50 Hz for optimal performance.

Best Practices

Tip: Use accelerometer data whenever possible to enhance the accuracy of heart rate and HRV estimation in dynamic environments.

  • Ensure Clean Input Data: PPG data should be filtered to remove noise and motion artifacts, especially when using accelerometer data to enhance filtering.

  • Optimize Window Sizes: Adjust the HRV window size and update interval to meet the specific needs of your application.

  • Sampling Rate: Input data should ideally be sampled at 50 Hz to ensure accurate heart rate and HRV computation.

Deployment

Once deployed, the HR block can be used to estimate heart rate and HRV in real-time, providing valuable insights into physiological health and well-being. The block can be integrated into a wide range of applications, including fitness trackers, health monitors, and stress detection systems.

  • IBI Binary Library Deployment: The block can be compiled into an IBI binary library, enabling heart rate and HRV feature extraction directly on-device.

  • Standalone HRV Feature Library: The HRV feature extraction library can run standalone, directly using IBI data when available, making it suitable for advanced health monitoring solutions.

  • Signal Quality Assessment: The block includes a signal quality assessment module to ensure accurate heart rate and HRV estimation.

  • Sleep Analysis Features: The block can be extended to include sleep analysis features, providing a comprehensive health monitoring solution.

Heart Rate Calculation with the HR/HRV DSP Block

One important caveat when working with the HR/HRV DSP Block is that you can still extract heart rate (HR) from the DSP feature extraction process, even when running a classifier, by defining a specific macro. This is particularly useful if your model is performing classification tasks but you'd also like to access heart rate data.

Enabling Runtime Heart Rate Calculation

If you want to extract heart rate from the HR/HRV DSP Block during inference, make sure to define the following macro:

#if EI_DSP_ENABLE_RUNTIME_HR == 1
    ei_impulse_result_hr_t hr_calcs;
#endif

ei_impulse_result_hr_t Structure When this macro is enabled, the heart rate calculation will be stored in the ei_impulse_result_hr_t structure, which is defined as follows:

typedef struct {
    float heart_rate;  // The calculated heart rate in beats per minute (BPM)
} ei_impulse_result_hr_t;

How to Use Runtime HR Calculation

When you run inference on your classifier, the runtime HR calculation will allow you to access the heart rate, in addition to any classification results. For example, after running run_classifier(), you can print the heart rate:

See the example code below for a simple implementation of the HR block in a C++ application:

#include "edge-impulse-sdk/classifier/ei_run_classifier.h"

#if EI_DSP_ENABLE_RUNTIME_HR == 1
ei_impulse_result_hr_t hr_calcs;
#endif

int main() {
    // Initialize signal (PPG data, etc.)
    signal_t signal;
    ei_impulse_result_t result;

    // Run the classifier
    run_classifier(&signal, &result, false);

    #if EI_DSP_ENABLE_RUNTIME_HR == 1
    printf("Heart rate: %.2f BPM\n", hr_calcs.heart_rate);
    #endif

    return 0;
}

This code snippet demonstrates how to access the heart rate calculation from the HR/HRV DSP Block during inference. By defining the macro EI_DSP_ENABLE_RUNTIME_HR, you can extract heart rate data in addition to classification results, providing valuable insights into physiological health and well-being.

Using HR Block to Only Estimate Heart Rate

If you want to use the HR block solely for heart rate estimation without any classification, you can configure the Regression Learn Block to "pass through" the DSP result. This can be achieved by setting up a simple neural network in Expert Mode:

import tensorflow as tf

# Example: Setting up a basic HR model in Edge Impulse
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.InputLayer(input_shape=1))
model.add(tf.keras.layers.Dense(1, name='y_pred', activation='linear'))

Train the model (though there's effectively no training needed in this case). You can then use Model Testing or Live Classification to evaluate the heart rate estimation.

Optimizing for MCU-Based Deployments

To optimize for MCU-based systems, your enterprise representative can provide a MAP file. This file contains a detailed breakdown of the memory footprint (Flash and RAM) for the HR/HRV DSP Block, including the IBI processing components. This data is critical for fine-tuning and optimizing the deployment of the block on resource-constrained devices.

Key Metrics

MetricDescription

Flash Usage

~7.5 KB

RAM Usage

~1.6 KB (additional RAM required for buffering input signals, depending on window size)

Understanding these metrics allows you to better optimize the HR/HRV DSP Block for your specific hardware platform.

Conclusion

The HR/HRV DSP Block enables real-time extraction of key metrics such as heart rate and HRV from physiological signals like PPG or ECG. These metrics are critical for applications in fitness tracking, stress detection, and medical diagnostics.

To go further, follow our step-by-step guides in the tutorials section as be begin to add other scenarios for working with the HR/HRV DSP Block.: Processing PPG input with HR/HRV DSP Block

Last updated