An Efﬁcient Technique for Compressing ECG Signals Using QRS Detection, Estimation, and 2D DWT Coefﬁcients Thresholding

. This paper presents an e ﬃ cient electrocardiogram (ECG) signals compression technique based on QRS detection, estimation, and 2D DWT coe ﬃ cients thresholding. Firstly, the original ECG signal is preprocessed by detecting QRS complex, then the di ﬀ erence between the preprocessed ECG signal and the estimated QRS-complex waveform is estimated. 2D approaches utilize the fact that ECG signals generally show redundancy between adjacent beats and between adjacent samples. The error signal is cut and aligned to form a 2-D matrix, then the 2-D matrix is wavelet transformed and the resulting wavelet coe ﬃ cients are segmented into groups and thresholded. There are two grouping techniques proposed to segment the DWT coe ﬃ cients. The threshold level of each group of coe ﬃ cients is calculated based on entropy of coe ﬃ cients. The resulted thresholded DWT coe ﬃ cients are coded using the coding technique given in the work by (Abo-Zahhad and Rajoub, 2002). The compression algorithm is tested for 24 di ﬀ erent records selected from the MIT-BIH Arrhythmia Database (MIT-BIH Arrhythmia Database). The experimental results show that the proposed method achieves high compression ratio with relatively low distortion and low computational complexity in comparison with other methods.


Introduction
The electrocardiogram (ECG) is an invaluable tool for diagnosis of heart diseases.ECG signals are usually sampled at 200-500 samples/s with 8-12 bits resolution.Considering long monitoring periods, compression is required to handle such vast amount of data.It can increase the capacity of databases where hundreds of thousands of ECG signals are stored for subsequent monitoring and evaluation.Other applications of ECG compression include transmission via telephone or mobile radio to an ECG center for further processing.
Many of the previous works has employed the QRScomplex detection in compressing the ECG waveform.The detection of the QRS complex specifically, the detection of the peak of the QRS complex, or R wave in an electrocardiogram (ECG) signal is a difficult problem since it has a time-varying morphology and is subject to physiological variations due to the patient and to corruption due to noise.For a tutorial on ECG signals, readers are referred to [12].
As noted in [13], most of the current QRS detectors can be divided into two stages: a preprocessor stage to emphasize the QRS complex and a decision stage to threshold the QRSenhanced signal.Typically, the preprocessor stage consists of both linear and nonlinear filtering of the ECG.The ECG signal is first bandpass filtered to reduce noise and differentiated to emphasize the large slope of the R wave; it is then squared to further exploit the high-frequency content of the QRS complex.
This paper is organized as follows.Section 2 presents the QRS significant features extraction and QRS-complex estimation.Section 3 is concerned with the preprocessing of the original ECG signal.Section 4 is a review of the two-dimensional discrete wavelet transform.Section 5 is an overview of coefficients grouping and thresholding and entropy principle.Section 6 shows the coding technique.Section 7 displays the experimental results of the compression algorithm on the selected records and a comparison with other coders in the literature.Finally, the paper is concluded in Section 8.

QRS-Complex Detection and Estimation
The ECG signal is composed from three main components, namely, the QRS complexes, P-wave: and T-wave as shown in Figure 1.Since the QRS complexes have a time-varying morphology, they are not always the strongest signal component in an ECG signal.Therefore, P-waves or T-waves with characteristics similar to that of the QRS complex, as well as spikes from high-frequency pacemakers, can compromise the detection of the QRS complex.In addition, there are many sources of noise in a clinical environment that can degrade the ECG signal.These include power line interference, muscle contraction noise, poor electrode contact, patient movement, and baseline wandering due to respiration [14].Therefore, QRS detectors must be invariant to different noise sources and should be able to detect QRS complexes even when the morphology of the ECG signal is varying with respect to time.The significant features of the ECG signal are the P, QRS, and T-waves.In this work only the QRS waves are detected.Moreover, for best quality of QRS estimation and the duration between the Q-R and R-S are detected and transmitted with the code stream.The QRS-complex estimation produce the typical QRS-complex waveform using the parameters extracted from the original ECG signal.The estimation algorithm is a MATLAB based estimator and is able to produce normal QRS waveform using a shifted and scaled versions of a triangular and sinusoidal wave forms.

Preprocessing of the Original ECG Signal
ECG signal preprocessing consists of three steps: (i) curettage, (ii) normalization and mean removal, (iii) and conversion the error matrix into 2D matrix.
where e(n) is the error signal, e = [e 1 e 2 e 3 e 4 • • • e N ], and N is the length of the original ECG signal.The benefit of this step is to preserve the QRS signal which contains the most energy of the ECG signal.

Normalization and Mean
Removal.Normalization of the error signal is done by dividing the error signal on the maximum value of the error signal A m , which is calculated using (2) as follows: Mean removal is performed by subtracting the mean value M x from each sample of the signal method.The mean of the ECG signal is calculated using the following equation: where N is the number of samples in the error signal and e(n) is the samples of the error signal.Normalization and mean removal is done by the following equation: where y(n) is the normalized mean removed error signal.
The main benefit of this step is to guarantee that the absolute values of all DWT coefficients are less than one.

Conversion into 2D Matrix.
The dependencies in ECG signals can be broadly classified into two types: the dependencies among a single ECG cycle and the dependencies across ECG cycles.These dependencies are sometimes referred to as intrabeat and interbeat dependencies, respectively.An efficient compression scheme needs to exploit both dependencies to achieve maximum data compression.To compress the ECG data using the proposed coding scheme, the one-dimensional ECG signal has to be converted into a two-dimensional matrix.Thus, the first step in the presented algorithm is to separate each "period" of the ECG.This step is done with assistant of QRS complex detection which is described in Section 2. Each period is then stored as row in the 2D Matrix.It can be seen that the intrabeat dependencies are in the horizontal direction of the matrix and the interbeat dependencies are in the vertical direction.The created image is shown in Figure 2. Since each ECG period can have different lengths, using the constructed 2D ECG matrix using will have a different number of data points in each row.In the literature, there are many approaches tried to overcome this problem.In [16], the compression system using JPEG2000 normalizes each ECG period to the same length.Some approaches [20] tend to add a number of zeros at the end of each heartbeat data sequence.Some drawbacks appear in approaches like the bits needed to be sent "or stored" to identify the length of each period [16,20] which reduce the compression ratio (CR).Another drawback is the discontinuity in the matrix resulting from padding the end of each heartbeat with appropriate number of zeros [20].Here, a novel technique is proposed for converting the 1D ECG signal into 2D array and warding the drawbacks of the previous approaches.Firstly, 32 periods are aligned with reference to the R signal and all periods are cut at a certain length L. The length L is chosen at the minimum period length downward to a multiple of 32 "where 32 is the length of the constructed 2D ECG array."For example, if the minimum period length is 267, then the length L = 224.The residual of all periods is assembled into one row then segmented into 32 by 32 matrices.After that, the 32 × 32 matrices are added beside the first array "32 by L matrix."This approach exploits the benefit of the interbeat dependencies without additional bits.

Two-Dimensional Discrete Wavelet Transform (2D-DWT)
The continuous wavelet transform (CWT) is provided by (5), where x(t) is the signal to be analyzed.ψ(t) is the mother wavelet or the basis function.All the wavelet functions used in the transformation are derived from the mother wavelet through translation (shifting) and scaling (dilation or compression).Consider the following: The mother wavelet is used to generate all the basis functions, the translation parameter τ relates to the location of the wavelet function as it is shifted through the signal, and the scale parameter S is defined as |1/frequency| and corresponds to frequency information.Notice that the wavelet transform merely performs the convolution operation of the signal and the basic function.The wavelet series is just a sampled version of CWT and its computation may consume significant amount of time and resources, depending on the resolution required.
The discrete wavelet transform (DWT), which is based on subband coding, is found to yield a fast computation of wavelet transform.It is easy to implement and reduces the computation time and required resources.In DWT, a time-scale representation of the digital signal is obtained using digital filtering techniques.The signal to be analyzed is passed through filters with different cut-off frequencies at different scales.Wavelets can be realized by iteration of filters with rescaling.The resolution of the signal, which is a measure of the amount of detail information in the signal, is determined by the filtering operations, and the scale is determined by upsampling and downsampling (subsampling) operations.
The DWT is computed by successive lowpass and highpass filtering of the discrete time-domain signal where n is an integer, as shown in Figure 3.The lowpass filter is denoted by G 0 while the high-pass filter is denoted by H 0 .At each level, the high-pass filter produces detail information d[n], while the low-pass filter associated with scaling function produces coarse approximations a[n].Figure 4 shows the reconstruction of the original signal from the wavelet coefficients.Basically, the reconstruction is the reverse process of decomposition.The approximation and detail coefficients at every level are upsampled by two, passed through the low-pass and high-pass synthesis filters, and then added.This process is continued through the same number of levels as in the decomposition process to obtain the original signal.In most wavelet transform applications, it is required that the original signal be synthesized from the wavelet coefficients.So the analysis and synthesis filters have to be selected carefully to achieve perfect reconstruction.The 2D-DWT is simply the application of the 1D-DWT repeatedly to first horizontal data of the image, then the vertical data of the image as shown in Figure 5 and the inverse 2D-DWT is shown in Figure 6.

Modelling and Simulation in Engineering
Figure 3: Three-level wavelet decomposition tree.

Coefficients Grouping and Thresholding
As a consequence of DWT decomposition, the resulted coefficients are classified into a few coefficients that contain the most energy of the signal "important coefficients" and a huge number of coefficients which contain less amount of energy of the signal "less important coefficients."For efficient compression ratio and signal quality, this property have to be exploited correctly by dedicating more bits to represent the important coefficients and less bits to represent less important coefficients.Thresholding is a process that converts a range of coefficients values to a certain level based on threshold value λ.Normally, hard thresholding and soft thresholding techniques are used for such denoising process.Hard and soft thresholding with threshold λ are defined as follows.
The hard thresholding operator is defined as The soft thresholding operator on the other hand is defined as Hard thresholding is "keep or kill" procedure and is more intuitively appealing and also it introduces artifacts in the recovered images.But soft thresholding is more efficient and it is used for the entire algorithm.In [21], thresholding methods are categorized into the following five groups based on the information the algorithm manipulates.
( (3) Attribute-based methods search for a measure of similarity between the adjacent samples and periods.
(4) The spatial methods use higher-order probability distribution and/or correlation between samples.
(5) Local methods adapt the threshold value on each subband signal to the signal energy.
In this paper, entropy-based thresholding technique is adopted as a thresholding method.This class of algorithms exploits the entropy of the distribution of the coefficients levels.For illustration, consider a source S that generates random symbols s 1 , s 2 , . . ., s N .For example, S may be a digital image, and s i represents one of N possible pixel levels.If P i denotes the probability of occurrence of symbol s i , then where I(s i ) is defined as the self-information for the symbol s i , that is, the information we get from receiving s i .If the base of the logarithm is two, then self-information is measured in bits.According to Shannon, the average information "Entropy" of a source S is defined as For information theory, if the symbols are distinct, then the average number of bits needed to encode them is always bounded by their entropy.In practice, the entropy of a source in general is unknown, and estimates for the entropy depend on the probability model adapted for the structure of the   symbols.For example, in a probability model, assume a source generates six distinct symbols (s 1 = 4, s 2 = 5, s 3 = 6, s 4 = 7, s 5 = 8, and s 6 = 9) and that each symbol is generated with equal probability, that is, p i = 1/6, for I = 1, 2, 3, 4, 5, 6.The self-information of each symbol is I(s i ) = 0.4308.From the definition of the entropy [7], for this probability model H(S) = 2.585.In other words, using this model a coding scheme for this sequence cannot be found that can code better than 2.585 bit per sample.
In a different model, assume that the probability of each symbol is p 1 = p 3 = 3/10 and p 2 = p 4 = p 5 = p 6 = 1/10.Using this model, I(s 1 ) = I(s 3 ) = 1.75, I(s 2 ) = I(s 4 ) = I(s 5 ) = I(s 6 ) = 3.3, and H(S) = 2.371.As a consequence of this discussion, it can be concluded that coefficients which occurred a few times yield to more information "more bits in coding" and those coefficients which occurred many times yield to less amount of information "less bits in coding." Hard thresholding of a certain group of subbands coefficients is done by eliminating all coefficients that are smaller than a certain threshold level L. This process introduces distortion in a certain aspect in the reconstructed signal.To decrease the effect of thresholding, a soft thresholding technique is applied in this work.The coefficients which value with high self-information I(s) are thresholded to the nearest value that has low I(s).The thresholding value λ in this proposal is not a constant value as normally used in the literature [22], the thresholding value λ is a variable depending on the self-information of the coefficients values.
To explore the effect of proposed thresholding technique, many thresholding rules "coefficients grouping" for the DWT coefficients had been suggested.In [23], the authors propose a list of six rules to group the wavelet coefficients.In this paper, two rules for "coefficients grouping" are listed to group the 2D wavelet coefficients.After wavelet transformation of the error signal, the wavelet coefficients are grouped to be thresholded upon a certain threshold value λ.
The results coefficients of wavelet transform can be presented as in the following equation: where A is the row vectors of the approximation coefficients, H is the row vectors of the horizontal detail coefficients, V is row vectors of the vertical detail coefficients, and D is the row vectors of the diagonal detail coefficients.The first grouping scheme arranges the wavelet coefficients into three groups as in the following equations: The second grouping scheme divides the wavelet coefficients into five groups as in the following equations: Figures 7 and 8 show the first and second grouping schemes of 3-level 2D DWT decomposition.
The following steps describe the entropy thresholding algorithm.
(1) Calculate the histogram and pdf distribution function of levels in each group of coefficients and the self-information of all levels as in ( 8) and the entropy.
(2) Arrange the levels from the highest to the lowest based on the self-information of levels.
(3) Threshold all coefficients which have levels with the highest self-information.

The Coding Technique System
Figure 9 illustrates the QRS-complex estimation compression algorithm.The coding process is manipulated by dividing the coded stream into two parts: the header part and the thresholded coefficients part.The header part consists of two sections.The first section has 3 bits dedicated for pointing out the dimension of the 2D ECG signal (e.g., the 32 × 32 matrix is coded as "101"), 9 bits dedicated for storing the length of each period, 12 bits dedicated for storing the maximum value in the original signal, and 12 bits dedicated for storing the mean of the normalized signal.The second section has 36 bits to represent the Q, R, and S values and 12 bits to represent Q-R and R-S duration.Figures 10(a) and 10(b) illustrate the coding stream that represents the header part.The significant and insignificant coefficients are coded separately.The runs of significant coefficients are coded as follows.
(i) One bit of value "1" identifies the run of significant coefficients.
(ii) A sign bit to encode the sign of the significant coefficient.
(iii) Eight bits to encode the value of the significant coefficient.
Figure 10(c) illustrates the coding stream that represents runs of significant coefficients.
The runs of insignificant coefficients are coded with variable-length coding VLC based on run length encoding as follows.
Modelling and Simulation in Engineering (i) One bit of value "0" identifies the run of insignificant coefficients.
(ii) Four bits to represent the number of bits needed to code the run length.
(iii) Variable in length (from 1 to 16 bits) to encode the run length.The compression ratio CR, the percent RMS difference PRD, and peak signal-to-noise ratio PSNR will be used as a performance measure.The CR and PSNR are calculated respectively by (13) as follows: where x(n) and x(n) represent the original and the reconstructed signal, respectively.Three different PRD formulas can be found in the open literature.The first formula is described by (14) as follows: Modelling and Simulation in Engineering The second formula is expressed by (15) as follows: Finally, the last formula is expressed by The RMS of a set of values is the square root of the arithmetic mean (average) of the squares of the original values as

Experimental Results
The MIT-BIH Arrhythmia Database [24]   7.1.Experiment 1.This experiment conclude testing the proposed algorithm on records 100 and 220 in order to explore and reveal the effectiveness of the proposed method on the clinical diagnosis information of the reconstructed ECG signal.Figure 11 shows the compression performance of the proposed method of the selected two records of the MIT-BIH Arrhythmia Database.The evaluation of the figure shows that the reconstructed ECG signal had preserved the

Conclusion
In this paper, new wavelet based ECG compression technique is proposed, associated with acceptable PRD and PSNR values.It is based on converting 1D ECG signal with irregular periods into 2D matrix of size L × L. The length L is chosen at the minimum period length downward to a multiple of 32.
The residual of all periods is assembled into one row then segmented into 32 by 32 matrices.This approach exploits the benefit of the interbeat dependencies without additional bits.Numerical results show that the 2D ECG compression is better than 1D ECG compression methods as shown in Table 1.Table 1 illustrates also the detailed comparison between the proposed algorithm and the last listed methods for 117, 119, 205, and 220 ECG records.It is clear that the proposed algorithm has the highest CR with acceptable PRD.Also, it is clear that the coding and decoding stages in the proposed algorithm are fast and easy to implement.Moreover, the proposed algorithm has a good performance for different ECG signals considered from clinical point of view and all the clinical information is preserved after reconstruction.Finally, it should be noted that a further improvement in results may be achieved with sophisticated implementation of compression system in any simulation program as LABVIEW.

3. 1 .
The ECG Signal Curettage.The curettage process means to subtract the estimated QRS signal x
) Histogram shape-based methods, where, for example, the peaks, valleys, and curvatures of the smoothed histogram are analyzed.(2) Entropy-based methods result in algorithms that use the entropy of the original and the transformed signals and the cross-entropy between the original and binarized signals.

Figure 10 (
Figure 10(d) illustrates the coding stream that represents runs of insignificant coefficients.The compression ratio CR, the percent RMS difference PRD, and peak signal-to-noise ratio PSNR will be used as

Figure 12 :
Figure 12: CR-PRD curves for the selected records of Experiment 2.

Table 1 :
[25]ormance comparison with previous 2D compression algorithms.In this experiment the proposed algorithm was applied to 10 ECG records selected randomly from the MIT-BIH arrhythmia database.These records are 100, 101, 102, 103, 107, 109, 111, 115, 117, and 119.Figure12explore the results of this experiment.The results demonstrate that the compression results versus the percentage RMS difference for the tested records are converging to each other, which mean that the proposed compression method is opportune for all ECG signals.7.3.Experiment 3.This experiment is a comparison of the proposed compression algorithm with previous compression methods based on 2D ECG signal in the literature as follows.In[16], Bilgin et al. applied the image coding standard-JPEG to ECG signal compression.In[20], Tai et al. adopted a modified SPIHT method to compress ECG signals.In[18], Lee and Buckley proposed an ECG compression method based on the 2D DCT.In[25], Xingyuan and Juan have applied wavelet-based hybrid ECG compression technique on ECG signals.