Matlab Code for Rr Interval Calculation
This guide explains how to calculate RR intervals in MATLAB, including code examples, formulas, and a practical calculator. RR intervals are fundamental in cardiac physiology and ECG analysis.
What is an RR Interval?
The RR interval is the time between two consecutive R waves in an electrocardiogram (ECG or EKG). It represents the duration of one complete heart cycle and is measured in milliseconds (ms).
RR intervals are crucial in:
- Heart rate variability (HRV) analysis
- Cardiac rhythm assessment
- Detection of arrhythmias
- Stress and fatigue monitoring
In healthy individuals, RR intervals typically range from 600ms to 1000ms, corresponding to heart rates between 60 and 100 beats per minute (bpm).
MATLAB Code for RR Interval Calculation
Here's a MATLAB function to calculate RR intervals from ECG data:
The code uses the Pan-Tompkins algorithm to detect R-peaks, which is a standard method for QRS complex detection in ECG signals. The RR intervals are then calculated as the time difference between consecutive R-peaks.
Key Assumptions
- The input ECG signal is properly filtered and baseline corrected
- The sampling frequency is known and consistent
- The signal contains clear R-peaks (may need adjustment for noisy signals)
Example Calculation
Let's calculate RR intervals for a sample ECG signal with the following parameters:
- Sampling frequency: 1000 Hz
- R-peak locations: [100, 350, 600, 850] samples
RR intervals would be calculated as:
RR1 = (350 - 100) × (1000/1000) = 250 ms
RR2 = (600 - 350) × (1000/1000) = 250 ms
RR3 = (850 - 600) × (1000/1000) = 250 ms
In this example, all RR intervals are equal (250 ms), which would correspond to a regular heart rate of 240 beats per minute (60,000 ms/min ÷ 250 ms/beat).
Frequently Asked Questions
- What units are RR intervals measured in?
- RR intervals are typically measured in milliseconds (ms).
- How do I convert RR intervals to heart rate?
- Heart rate (in beats per minute) can be calculated as 60,000 ms/min ÷ RR interval (ms).
- What is the normal range for RR intervals?
- In healthy individuals, RR intervals typically range from 600ms to 1000ms, corresponding to heart rates between 60 and 100 bpm.
- How accurate is the Pan-Tompkins algorithm for R-peak detection?
- The Pan-Tompkins algorithm is widely used and generally accurate for clean ECG signals, but may need adjustment for noisy or abnormal ECG patterns.
- Can I use this code for real-time RR interval calculation?
- Yes, the code can be adapted for real-time processing by implementing it in a streaming data context with appropriate buffering.