R-wave of the electrocardiogram as a parameter of the Pythagorean tree

image

While studying the algorithms for detecting events of the electrocardiogram for the research part of the thesis, I found that the duration of the RR interval of the cardiogram, calculated even to the second decimal place, characterizes the cardiovascular system of a particular person quite accurately. Since I have been fond of fractal geometry for quite some time, the thought immediately appeared in my head how to give “personal” qualities to some simple fractal object.

So there was the "Pythagorean Electrocardiographic Tree".

Theoretical part - 1. About the electrocardiogram


A graphic recording of the potential difference created between different parts of the heart muscle during its excitation is called an electrocardiogram (ECG). The orientation and magnitude of these heart potentials on the electrocardiogram are expressed in the amplitude of the teeth and their orientation (polarity) with respect to the isoelectric line. And they cover the range of 0.15 ... 300 Hz with a signal level of 0.3 ... 3 mV.

A normal ECG consists of teeth and line segments (segments) horizontally located between them (Figure 1).

Figure 1 - Schematic representation of a normal electrocardiogram.
image

In clinical practice, leads from various parts of the body surface are used. These leads are called superficial. When registering an ECG, 12 commonly used leads are usually used, six from the limbs and six chest. The first three standard leads were proposed by Einthoven. The heart rate (HR) is determined by the duration of one cardiac cycle, i.e. according to the duration of the interval R - R.

The standard and most convenient for determining heart rate is the II-lead according to Einthoven, because in it the R wave has the greatest amplitude.

Practical part - 1


For calculations, we will use the real ECG of a healthy person in the II lead according to Einthoven obtained from the database of physiological signals [1].

ECG parameters:
• 12-bit ADC resolution;
• Sampling frequency 100 Hz;
• Duration 10 seconds;

Figure 2 - Image of a normal ECG from the database.
image

Next, we define a QRS-complex so that we can then extract the R wave from it. To do this, we use an algorithm based on the weighted and squared operator of the first derivative and on the moving average filter [2].

It sounds more complicated than it looks:

image
where x (n) is the ECG signal, N- the width of the window within which the first-order difference is calculated, squared and weighted using the coefficient (N-i + 1) .

The weighting coefficient decreases linearly, starting from the current difference, to the difference calculated by N samples earlier in time, which provides a smoothing effect.

Further smoothing is performed using a moving average filter over M points:

image

At a sampling frequency of 100 Hz, the filter window width is set as M = N = 8 . This algorithm gives a single peak for each QRS complex and suppresses the P and T waves. As a result of processing, we obtain the following type of ECG (Figure 3).

Figure 3 - Image of an ECG after filtration.
image

The search for the R wave in the processed signal can be performed using a simple peak search algorithm:
1. Scanning a fragment of the signal g (n) , where a peak is expected, and determining the maximum value gmax .
2. The definition of the threshold as a fraction of the maximum, Th = 0.8gmax .
3. For all g (n)> Th, those samples are selected for which the corresponding values ​​of g (n) are greater than a certain given number M of previous or subsequent samples g (n) .

image

The set {p} defined in this way contains the indices of all peaks found in the signal g (n) .
Peaks caused by artifacts can be rejected by additional conditions, for example, the minimum interval between two adjacent peaks.

Figure 4 - Image of an ECG with marked R-teeth.
image

Next is the simple task itself - determining the average length of the RR interval of a given ECG. And in this case it is equal to 733ms. “By Fan” we calculate the heart rate: 60 / 0.733 = 81.85 beats / min. Now we have a quantity characterizing the work of the heart of a particular person.

A little explanation:
The heart is not a metronome; it cannot tap a beat with equal time intervals between beats. RR interval for a healthy person varies within small limits. If the interval fluctuations are significant - this indicates the presence of arrhythmias and other disorders. The oscillation mechanism is a very complex set of processes associated with the electrical conductivity of a particular heart.

Using the value of the average RR interval as a parameter during the construction of the Pythagorean tree, you can give it “unique” (“personal”) features.

Theoretical part - 2. About fractals


Fractals are called geometric objects: lines, surfaces, spatial bodies, having a strongly rugged shape and having the property of self-similarity. The founder of the theory of fractals, the Franco-American mathematician Benoit Mandelbrot, formed the term fractal from the Latin participle fractus. The corresponding verb frangere translates how to break, break, i.e. create fragments of irregular shape. Self-similarity predetermines scale invariance (scaling) of the basic geometric features of a fractal object, their invariability with a change in scale. The repeatability of the broken lines of fractal objects can be complete (in this case we speak of regular fractals), or some element of randomness can be observed (such fractals are called random).

The Pythagorean tree is a type of geometric regular fractal based on the figure known as the Pythagorean Pants [3].

The principle of constructing a geometric fractal is recursion.

Practical part - 2


The algorithm for constructing the Pythagorean tree:
1) We build a vertical segment;
2) From the upper end of this segment, we recursively construct 2 more segments of shorter length at an angle of 90 ° to each other;
3) We call the function of constructing two subsequent segments for each tree branch;

The function of constructing a Pythagorean tree in C.

void Draw(double x, double y, double L, double a) {          
  if(L > max) {
     L*=0.7;
     moveto(x,y);
     lineto((int)(x+L*cos(a)),(int)(y-L*sin(a)));
     x=x+L*cos(a);
     y=y-L*sin(a);
    Draw(x,y,L,a+Pi/n);
    Draw(x,y,L,a-Pi/m); 
  }
}

Figure 5 - Pythagorean tree for ECG at RR: 733ms.

image

The only thing left to change is to use the calculated length of the average RR interval of the ECG as a variable L in the program.

Thus, you can get a "personal" Pythagorean tree that will "breathe", depending on physical activity, and the length of the branches and their twist - "describe your personality" as accurately as possible.

image

image

List of references


1. Research resource of complex physiological signals: physionet.org ;
2. Rangayyan R.M. Analysis of biomedical signals. Practical approach / Per. from English Ed. A.P. Nemirko. - M .: Fizmatlit, 2010 .-- 220 p. - ISBN 978-5-9221-0730-3;
3. ru.wikipedia.org/wiki/%D0%94%D0%B5%D1%80%D0%B5%D0%B2%D0%BE_%D0%9F%D0%B8%D1%84%D0%B0 % D0% B3% D0% BE% D1% 80% D0% B0

Also popular now: