MODEL FOR GENERATING SIMPLE SYNTHETIC ECG SIGNALS

This paper proposes a mathematical model for generating synthetic artificial ECG signal based on geometrical features of a real ECG signal. By variation of its parameters each particular wave of PQRST complex can be adjusted as needed allowing the generation of arbitrary ECG patterns typical for diseases and arrhythmia. The input parameters are treated to avoid mixing order of PQRST waves in case of automatic parameter variation and allow generating different patterns for each subsequent heartbeat independently. Each particular wave is modelled using an elementary trigonometric function or a Gaussian monopulse. Including possible addition of equipment noise as well as respiration frequency such an artificial signal can be used as a test signal for some signal processing methods. The model was tested by comparison of synthetized patterns against patterns generated by LabVIEW Biomedical Toolkit, while the parameters of model are found using the differential evolution algorithm


INTRODUCTION
The heart is organ essentially made of muscle generating a spatio-temporal electric field every time it contracts during the cardiac pumping cycle.This electric field propagates through complex volume conductor of thorax and abdomen to the skin, where by placing electrodes on the skin surface the spatio-temporal potential difference can be measured.Such an electric potential difference is called the electrocardiographic signal (ECG) and it is one of the most important signals used in diagnostic methods for various cardiovascular diseases.According to placement of the electrodes there are several types of signal recordings called the leads.
There are various signal processing methods [1] used for automatic analysis of ECG signals as well as methods for their compression which are required mainly for processing of long time ECG records.During development and experiments with these methods and algorithms it is essential to test them using suitable test signals.For the purposes of testing there are two approaches.The first one is using large database of real ECG recordings such as Phisionet [2].However as these recordings often contain lots of noise and artifacts they are not always suitable for testing and comparing the accuracy of some methods because it is difficult to measure how the particular method would react in case of the same test signal shape but different levels or types of noise or sampling frequency.Therefore the second approach is to generate a synthetic ECG signal using suitable signal model that can be precisely adjusted according to one needs including possible addition of noise.
The well-known and widely used ECG signal model for these purposes is the dynamical model [3] based on three coupled differential equations.Other methods include modeling the heartbeat using polynomials and rational functions [4] or based on Fourier series [5].The approach presented in this paper uses elementary trigonometric functions and linear function or a derivation of Gaussian pulse to model each particular wave.
The paper is organized as follows: first the basic morphology of a typical ECG heartbeat is discussed followed by detailed introduction of proposed model and its features.Finally the model is tested by comparing various synthetized QRS patterns with patterns generated by LabVIEW Biomedical Toolkit.

MORPHOLOGY OF AN ECG SIGNAL
An ECG signal consists of consecutive heartbeats.Every heartbeat is represented by five waves standardly labelled with the letters P, Q, R, S and T (see Fig. 1).Each of these waves corresponds to depolarization and repolarization of heart muscles [6].The P wave represents activation of atria and it is followed by relatively short isoelectric segment while the cardiac impulse is passed through the A-V node and the His-Purkinje system.Once the muscles of ventricles are excited they get contracted.This contraction provides the main force for circulating blood to the body organs and causes the largest wave present in ECG signal which consists of three components.First downward deflection is ISSN 1335-8243 (print) © 2018 FEI TUKE ISSN 1338-3957 (online), www.aei.tuke.skcalled the Q wave, consecutive upward deflection is called the R wave and the final downward deflection is called the S wave.Group of these three waves is referred to as the QRS complex.The polarity and presence of each particular wave of QRS complex may vary according to the position of sensing leads as well as body abnormalities.Following the QRS complex there is another isoelectric segment.Finally the ventricles return to their electrical resting state and this repolarization can be seen as a low-frequency wave called the T wave.

THE PROPOSED ECG MODEL
According to typical ECG morphology it was decided to model each particular wave of a PQRST complex using elementary mathematical functions which are concatenated and compose a complete heartbeat.Parameters allow amplitude, width and position changes of each respective wave.In case of Q and S wave there are two variants introduced.The first one uses fixed shape of Q and S waves allowing for adjustment of amplitude and width.The second one moreover allows the change of their shape as well.

PQRST complex with fixed shape Q and S waves
Now the functions used for generating a single heartbeat will be described in detail.A heartbeat starts with a short isoelectric segment which is simply modelled by a function: where K B is the width and k is the sample number within one wave segment.Ongoing P wave is modelled using a cosine function: where A P is the amplitude and K P is the width of P wave.
There is again a short isoelectric segment: where K PQ is the width.The Q wave is modelled using a segment created by section of a Gaussian monopulse (a differentiated Gaussian pulse): for , where A Q is the amplitude and K Q is the width of Q wave.The R wave is modelled using a sinewave segment: where A R is the amplitude and K R is the width of R wave.The S wave is modelled again using a segment of Gaussian monopulse: where A S is the amplitude, K S is the basic width of the S wave.K CS is a parameter which allows slight adjustment of S wave shape by cutting away a portion at the end.Now the transition between S and T wave is described as a linear function: for , where s m is the slope parameter and K ST is the width of transition segment.The T wave is modelled using a segment of cosine function: , where A T is the amplitude and K T is the width of T wave.The final transition from T wave back to isoelectric line is modelled using function: where s I is the parameter for setting the transition slope between T wave and isoelectric line and K I is the width of the ending section.
A complete heartbeat H( 1 b,n) is given as concatenation of all waves modelled by (1-8) in such a way, that the beginning of each segment is appended to the end of a previous one, while their order is always the same starting with (1) and ending with (8).Here 1 b denotes the set of heartbeat parameters for the first variant: ( 1 0 ) and n denotes the sample number within one generated heartbeat in such a way, that n = 0, 1, 2, …, N 1 -1.Each segment of a heartbeat has maximum length defined by width parameters (K x ).Thus the sum of all segment lengths is N 1 =K B +K P +K PQ +K Q +K R +K S -K CS +K ST +K T +K I .

PQRST complex with adjustable Q and S waves
This variant differs from the previous one by usage of two linear functions to model Q and S wave instead of a Gaussian monopulse, which allows adjusting the shape of respective waves more precisely.Here all the modelling functions are the same as for the previous section, except of equations ( 4) and (6).The equation ( 4) is replaced by concatenation of two functions: ISSN 1335-8243 (print) © 2018 FEI TUKE ISSN 1338-3957 (online), www.aei.tuke.sk where K Q1 is the width of downward deflection, K Q2 is the width of upward deflection and A Q is the amplitude of Q wave.Similarly the equation ( 6) is replaced by concatenation of two functions: where K S1 is the width of downward deflection, K S2 is the width of upward deflection, s s is the slope parameter of upward deflection and A S is the amplitude of S wave.The argument of S(K S -K CS ) in equation ( 7) is now replaced by K S2 .
A complete heartbeat H( 2 b,n) is then adjusted using modified set of parameters 2 b for the second variant: here n denotes the sample number n = 0, 1, 2, …, N 2 -1, and N 2 =K B +K P +K PQ +K Q1 +K Q2 +K R +K S1 +K S2 +K ST +K T +K I is the sum of all segment width parameters.

Building a custom ECG signal
For simplification let's denote the function of one heartbeat generated using any of the described variants as H(b,n), where b is the set of parameters 1 b or 2 b and, n = 0, 1, 2, …, N=N 1 -1 in case of 1 b or N=N 2 -1 in case of 2 b respectively.Because the concatenation of functions forming a heartbeat obviously leads to an unnatural sharp edges present in resulting signal, the generated heartbeat is filtered using a Savitzky-Golay smoothing filter with window size of 7: for n=0, 1, 2, …, N, where H(b,n±j)=0 if the sum n±j is out of the specified interval for n.The filter plays a significant role while using the second model variant, because it forms the smooth shape of Q and S waves.
A complete ECG signal now can be built by concatenating multiple heartbeats H f (b i ,n), where the set of parameters b i can vary in each consecutive heartbeat.The beginning and ending segment of each heartbeat aligns smoothly with isoelectric line, thus there are no artifacts present at the position of their joint.This allows creating a completely custom-made ECG signal which can include various irregular heartbeats present at custom positions.
Even mixing the heartbeats generated from both proposed model variants is possible.As an example, a short signal containing a premature ventricular contraction (PVC) is modelled in Fig. 2 using the first model variant.

Equipment noise and the respiration frequency
To make the modelled signal more realistic, it is possible to add white noise into resulting signal for simulating the equipment noise.If needed, powerline noise can be added as a small amplitude sinewave of powerline frequency 50Hz or 60Hz.Adding a suitable amount of noise can also hide some unnatural perturbations which can be present in modelled signal due to imprecise parameter setting or due to constraints of modelling functions used.
The respiration causes a baseline wander of ECG signal [7].It means that the isoelectric line relatively slowly periodically changes its position.A simple way to model this effect is to add a sinewave of respiration frequency into ECG signal, which may vary from about 0.2Hz to 0.5Hz (approximately 12 to 30 breaths per minute).
An example of synthetized hypokalemia ECG signal with addition of equipment noise and effect of respiration can be seen in Fig. 3.

PERFORMANCE
To test the possibilities of QRS pattern generation using proposed model its parameters were adjusted to fit typical irregular heartbeats.As a reference the irregular beats for various diagnoses were generated using ECG signal generator from LabVIEW Biomedical Toolkit.Each reference pattern H r (n) was extracted from 60bpm signal generated with sampling frequency of 512Hz and contains one QRS complex with length of 1s.The set of model parameters b was found using differential evolution optimization algorithm [8] (DE) solving the problem: where MSE is the mean square error between the reference and modeled heartbeat: Initial bounds for b parameters were set in a following way: -0.2 to 2 for amplitude parameters, 0-150 for segment length parameters and 0-200 for slope parameters.After first iterations of DE the b parameter bounds were adjusted according to data found in Table 1.The length parameter of last segment K I is calculated so that the total sum of length parameters N=N 1 -1 or N=N 2 -1 is always equal to 512 and thus it is excluded from the set of parameters being optimized.Signal output of the model with such a configuration does not need resampling.
Irregular QRS patterns used as a reference for which the model was tested correspond to atrial tachycardia (a), ventricular tachycardia (b), junctional tachycardia (c), atrioventricular block (d), hyperkalemia (e), hypokalemia (f), hypercalcemia (g) and hypocalcemia (h).Resulting QRS patterns modelled using first model variant for each diagnosis can be seen in Fig. 4. Corresponding parameter setting 1 b found by DE and resulting MSE is listed in Table 2.For the second model variant the found parameters and MSE is listed in Table 3. Results were obtained using simulation in LabVIEW programming environment.DE optimization used uniform crossover method, population size of 500, and maximum number of 200 iterations for all the testing results provided.The listed parameters are average values for 10 runs of DE.
It should be noted that listed amplitude parameters except the A T are approximately corresponding to respective amplitudes of generated waves in the units of mV.Yet this relation does not always apply if the Q and S segment is narrow and considering the signal is filtered.The finite amplitude of T wave is a function of preceding segment amplitudes.
If the particular segment is not present in the signal it results in a zero length or amplitude parameter.Such a situation can be seen for example in Table 2 where the K PQ is zero for cases (a) or (b).Here the short isoelectric segment between P and Q wave is missing (Fig. 4b) or already modelled by initial slope of Q wave if the wave is large enough (Fig. 4a).As it can be seen from higher MSE for (a) and (b) diagnosis, the second model variant is problematic when it comes to modelling patterns where the Q and S waves have low frequencies and thus are too wide.In this case the linear functions used for modelling create sharp edges present at the peaks of each wave and the filter (16) window size is too low to smooth these artifacts.Thus for the purpose of modelling low frequency Q and S waves the first model variant is performing better.For some situations where the Q and S waves are of high frequency e.g.diagnosis (e) and (g), the second model variant performs better.However, because the second model variant has more adjustable parameters and they are more difficult to set, for general purposes of simulating an ECG signal the first model variant is much suitable and simpler to use.

CONCLUSIONS
Two ECG model variants were introduced for generation of artificial ECG signals.Both models allow creating a custom-made signal including irregularities occurring at custom positions and at custom time instances as well as addition of equipment noise and respiration effect.The possibility of various irregular heartbeats generation was tested against reference QRS patterns generated by LabVIEW Biomedical Toolkit.Differential evolution optimization algorithm was used to find the model parameters fitting the reference QRS patterns corresponding to various diagnoses and the MSE was evaluated for each case.
It was shown that the first model is suitable for modelling low frequency Q and S waves, while the second model variant using linear functions performs better in some cases of high frequency Q and S waves.However, because the first model uses fewer setting parameters it is much simpler to use and can be used universally.Second model variant is less suitable for generating QRS patterns where the Q and S waves are too wide.The relatively complex setting of heartbeat frequency of long-term signals by adjusting the length parameters of each wave segment is its complication.It can be solved by resampling the generated signal into suitable form.

Fig. 1
Fig. 1 PQRST complex of a normal lead II ECG recording

Fig. 2
Fig. 2 Modelled ECG signal containing a PVC heartbeat

Fig. 3
Fig. 3 An example of modelled hypokalemia ECG signal with noise and respiration frequency added

Table 1
DE parameters bound setting for both model variants

Table 2
First variant model parameter sets for each diagnosis

Table 3
Second variant model parameter sets for each diagnosis