lunes, 8 de abril de 2024

Utilizing Ordinary Differential Calculus to Detect R-Waves in Standard EKGs

 


The electrocardiogram (ECG or EKG) is a vital tool for analyzing heart health. It captures the electrical activity of the heart, with distinct peaks and valleys corresponding to different stages of the heartbeat. 

Willem Einthoven invented the first practical electrocardiograph in 1895 and received the Nobel Prize in Physiology or Medicine in 1924 "for the discovery of the mechanism of the electrocardiogram".

The EKG signal typically consists of several waves: P-wave, QRS complex, and T-wave.

One crucial element of an EKG is the R-wave, which represents the peak of ventricular depolarization: the moment when the main pumping chambers of the heart contract. Detecting R-waves accurately is essential for interpreting cardiac rhythms and identifying abnormalities.

The R-wave typically occurs approximately 200 to 300 milliseconds after the onset of ventricular depolarization. Using the location of the local minima in the first derivative, we can estimate the time of arrival of the R-wave.

While there are numerous methods for R-wave detection, employing ordinary differential calculus can provide a robust analytical approach. 

Let's explore how ordinary differential calculus can help us pinpoint these R-waves.

DISCLAIMER

This approach was tested only in an academic environment, as part of a lecture about Electrocardiography. See Course below.

The Math Behind the Beat

An EKG recording can be thought as a function of time, with voltage on the y-axis and time on the x-axis. The R-wave corresponds to a peak in this voltage function. In Calculus terms, a peak signifies a maximum of the function.

The first derivative of the EKG function represents the rate of change of voltage over time. At the peak (R-wave), this rate of change will be zero. So, finding the maximums of the first derivative will lead us close to the R-waves.

EKG signals are often noisy. The first derivative might have minor fluctuations around the true maximum. To refine our detection, we can take the second derivative. The second derivative represents the rate of change of the rate of change (think acceleration).

At the R-wave, the voltage is at its maximum, so the first derivative is zero. But just before the peak, the voltage is rapidly increasing, resulting in a positive second derivative. Just after the peak, the voltage starts decreasing, leading to a negative second derivative.

Therefore, identifying points where the second derivative transitions from positive to negative will pinpoint the exact location of the R-wave with greater accuracy.

Putting it Together

By analyzing the EKG signal with these derivative properties in mind, we can identify R-waves:

  1. Find Local Maxima in First Derivative: Scan the first derivative for points where the value reaches a maximum. These points correspond to potential R-waves.
  2. Verify with Second Derivative Minimum: For each potential R-wave identified in step 1, check the corresponding point in the second derivative. A true R-wave will have a minimum value at that point in the second derivative.

Benefits and Limitations

This method offers a simple, calculus-based approach to R-wave detection. However, it's important to consider limitations:

  • Noise: Real EKG signals can be noisy due to muscle movement or electrical interference. These can introduce false maxima/minima in the derivatives, requiring additional filtering or noise reduction techniques.
  • ECG Variations: EKG morphology can vary between individuals, and some abnormal heart rhythms might not exhibit the classic R-wave characteristics. More sophisticated algorithms might be needed for robust R-wave detection in such cases.

Conclusion

Understanding R-waves is essential for EKG analysis. By utilizing the concepts of maxima and minima in ordinary differential calculus, we gain valuable insight into the electrical activity of the heart and its rhythm.

Ordinary differential calculus provides a valuable tool for understanding and analyzing EKG signals. By focusing on maxima in the first derivative and minima in the second derivative, we can pinpoint the crucial R-waves, offering valuable insights into heart function. 

However, it's crucial to acknowledge the limitations of this approach and consider real-world complexities for robust R-wave detection in medical applications.

Then, further research and validation are necessary to refine and optimize this method for real world applications.

You can find two versions of the source code: 1) MatLab/Octave, and 2) Python in my GitHub repo Signal/EKG/R-Wave 

Course lecture: 

Cursos/Electro_Medicina/elecmed05_2 Electrocardiografía.ppt

Note: This presentation is written in Spanish.

Recommended lectures

1.  Bronzino,J.D. (Editor)  “The Biomedical Engineering Handbook, 2nd Ed. IEEE Press, 2000 Chapter 13 “Principles of Electrocardiography”

2.  Carr,J.J y Brown,J.M. “Introduction to Biomedical Equipment Technology” Chapter 8 “Electrocardiography” pp 197-233

3.  Del Aguila, C. “Electromedicina” Ed. Hasa, 1994 Capítulo 8 “Bases de la Electrocardiografía” (pp 129-159) y Apéndice III Electrocardiógrafo (pp 475-499)

4. Webster, J.G. (Editor) “BioInstrumentation”, 2003