Efficient ECG Compression and QRS Detection for E-Health Applications

Current medical screening and diagnostic procedures have shifted toward recording longer electrocardiogram (ECG) signals, which have traditionally been processed on personal computers (PCs) with high-speed multi-core processors and efficient memory processing. Battery-driven devices are now more commonly used for the same purpose and thus exploring highly efficient, low-power alternatives for local ECG signal collection and processing is essential for efficient and convenient clinical use. Several ECG compression methods have been reported in the current literature with limited discussion on the performance of the compressed and the reconstructed ECG signals in terms of the QRS complex detection accuracy. This paper proposes and evaluates different compression methods based not only on the compression ratio (CR) and percentage root-mean-square difference (PRD), but also based on the accuracy of QRS detection. In this paper, we have developed a lossy method (Methods III) and compared them to the most current lossless and lossy ECG compression methods (Method I and Method II, respectively). The proposed lossy compression method (Method III) achieves CR of 4.5×, PRD of 0.53, as well as an overall sensitivity of 99.78% and positive predictivity of 99.92% are achieved (when coupled with an existing QRS detection algorithm) on the MIT-BIH Arrhythmia database and an overall sensitivity of 99.90% and positive predictivity of 99.84% on the QT database.


Results
The performance of the proposed algorithm was evaluated using the MIT-BIH arrhythmia and QT databases. For a fair and consistent evaluation of the proposed method (Method III) with all results published in the literature, the performance of the QRS detection algorithms from each method was assessed using two statistical measures: sensitivity (SE) and positive predictivity (+P). The SE and +P were calculated as follows: In other words, SE reports the percentage of detected true beats out of all true beats, while the +P reports the percentage of detected true beats out of all detected beats. Note, TP stands for true positives (the number of QRS complexes detected as QRS complexes), FN stands for false negatives (the number of QRS complexes which have not been detected), and FP stands for the number of false positives (non-QRS complexes detected as QRS complexes).
Method I demonstrated the performance of the QRS detector with different parameter values. The optimal W and q values were determined by 8 after testing various combinations of (W, q) with W ranging from 3 to 6 and q ranging from 9 to 17. It was found that optimal detection QRS accuracy was achieved with W = 3 and q = 15. Note that the optimization step of the QRS detector for Method II was not discussed in ref. 9 .
For Method III, a rigorous optimization over all parameters was conducted. This step is carried out once on either an ECGau or a PC. As soon as the optimal parameters are determined, the ECGag will be adjusted accordingly without any further tuning. As this step occurs one time, it does not add any complexity to the ECG signal analysis at ECGag or ECGau level. The value of B varied from b min = 360 Hz to b min = 500 Hz, while the value of K varied from k min = 50 Hz to k min = 360 Hz. As we have multiple objectives, plotting the Pareto frontier (the objective space of possible Pareto solutions) cannot be achieved. Therefore, all Pareto solutions were sorted in descending order according to the overall accuracy (objective function g), as shown in Table 1. The optimal Pareto value of B/K was found to be 4.875, where B = 390 Hz and K = 80 Hz, achieving a maximum value of g = 99.851% with an SE of 99.78% and a +P of 99.92%. It is clear that the highest accuracy of QRS detection was scored using Method III with B/K = 4.875. The results of Method III will be discussed in more detail.
A summary of the QRS detection results for all recordings using Method III with B/K = 4.875 is shown in Table 2. Figures 2,3 and 4 show the performance of Method III under noisy conditions. The first plot (a) in each figure shows the original ECG signal. The second plot (b) shows the compressed ECG signal using Method III. The third plot (c) shows the QRS detection based on the compressed signal shown in plot (b). Figure 2 shows the performance of the QRS detector on a compressed ECG signal using Method III over T waves with large amplitudes, which are often misidentified as QRS peaks due to their amplitude. Figure 3 shows the QRS detection performance using an ECG signal with premature ventricular contractions, which introduce irregular heartbeats in terms of RR interval and morphology. Figure 4 shows that the QRS detector performed well in the presence of noise and baseline wandering within the compressed ECG signal. Table 3 compares the QRS detection performance of well-known compression algorithms with the proposed methods. As shown, Method III outperformed all competing lossless algorithms in terms of increasing BCR and decreasing PRD simultaneously. The multiscale morphology technique scored lower in detection accuracy given its high computational complexity. In comparison, Method III was fast and more efficient for analyzing ECG signals making it better suited for e-health applications. Table 4 compares the compression performance of the four methods with other compression schemes implemented on hardware for wearable applications. Method III outperformed existing well-known lossy and lossless compression methods by scoring the highest BCR at 4.5 while scoring the lowest PRD at 0.53. Note that Methods III and III have already outperformed the state-of-the-art lossless compression methods: delta predictor/ Rice-Golomb coding 10 , adaptive predictor/Huffman coding 11 , simple predictor/Huffman coding 12 , and slope predictor/fixed-length packaging methods 13 in terms of increasing BCR and decreasing PRD simultaneously. The higher the BCR and the lower PRD values in an algorithm, the better the compression performance However, the detection of QRS has to be considered when choosing the optimal compression algorithm.
In this study, the proposed detector was implemented in MATLAB 2012a (MathWorks, Inc., Natick, MA, USA) on an Intel ™ i5 CPU with 2.27 GHz. Figure 5 shows the BCR versus QRS detection performance and processing time. As expected, the processing time decreased as the BCR increased. Method III took an average

Discussion
Methods Implementation. To the best of our knowledge, only one ECG compression method category is extensively discussed in current ECG compression literature; this method is referred to as lossless, and can be seen  in Method I. The lossless ECG compression methodology recovers the original ECG signal exactly as is. However, a second methodology is found in communication signal processing literature that is referred to as lossy. With the lossy methods, some samples are trimmed off from the original signal. Depending on the type of lossy method being used, the eliminated data may or may not be noticeable to the user. Several lossy compression methods have been reported in the literature [14][15][16][17][18][19][20][21][22] . These lossy compression methods are strongly embedded in lossless compression methods due to the risk of potential distortion 23 .
Based on a scan of current literature, the application of the lossy compression method to compress ECG signals, without it being embedded (or part of) in a lossless, has not yet been investigated. We therefore developed a pure lossy method (Method III) and compared it to the most current lossless ECG compression method (Method I) and the most current lossy ECG compression method (Method II). Note that Method II is not a pure lossy compression method, since removal of data bits within a lossless framework is implemented.
In Method I, within the signal regions with steep amplitude variations (such as the QRS complex), the predictor statistics were considerably different and resulted in higher prediction error. Therefore, Deepu et al. 8 used prediction error as a marker to locate the QRS complex in ECG signals. By contrast, Method III does not need the linear predictor step used in Method I.
One advantage of using the prediction error in Method I is that the output has low dynamic range (a smaller amplitude than the original ECG signal) and centers around zero amplitude except for the areas corresponding to    Table 4. Compression performance comparison with other algorithms. BCR stands for bit compression ratio, PRD stands for percentage root-mean-square difference, N/R stands for Not Reported, and the symbol ≈ means nearly equal.

Figure 5.
Compression ratio versus performance. Here, BCR stands for bit compression ratio, PT stands for average processing time, SE stands for sensitivity, and +P stands for positive predictivity.
the QRS complexes. However, a lossless coding scheme is required to preserve the data. The output of the coding step is used to transmit the data instead of transmitting the whole signal to save power/memory resources. It is not required to apply a lossless coding scheme for Methods III, because the number of samples that represent the signal have already been reduced; using a lossless coding scheme would further reduce the quality of the signal and increase the consumption of power/memory resources unnecessarily.
Coding the output of the four methods can be carried out using variable-length coding schemes like Huffman and arithmetic coding 24 . All four methods are compatible with any of these existing coding schemes. The complexity of encoder/decoder implementation, however, is high for these techniques, although they produced optimal bit representations 24 .
Method I applied a coding-packaging scheme that gives a practical, fixed-length 16-bit output and has low hardware complexity 8 . The coding-packaging routine is based on the two's complement, which is a mathematical operation on binary numbers, representation of the prediction error signal. As most of the error prediction signal is around zero amplitude, it can be represented with only a few bits. Again, Method III does not need this step, as it will increase complexity and render these algorithms less suitable for wearable devices and e-health applications.
Compression Performance. It can be seen in Table 4 that lossless ECG techniques, such as the delta predictor and Rice-Golomb coding scheme 10 , achieved a maximum BCR of 2.38. However, Rice-Golomb coding is highly complex and requires a dedicated memory 8 . The two-stage adaptive predictor and the Huffman coding schemes 11 achieved a BCR of 2.43, but Huffman coding is highly complex, generates variable-length coded data, and would need further packaging to interface with a standard input/output 8 . Simple predictor and Huffman coding 12 achieved a BCR of 1.92. The slope predictor and a fixed-length packaging scheme 12 achieved a BCR of 2.25. Method I (linear predictor and fixed-length packaging) achieved a BCR of 2.28. On the other hand, the proposed lossy compression technique, Method III, achieved a BCR of 4.5.
In general, there are many lossy compression techniques to achieve higher BCR but these require complicated signal processing techniques 13 . These approaches also require the usage of more complex hardware, which is not suitable for low-power wearable applications 25,26 , and are therefore not included in the comparison.
Method III achieved a BCR of 4.5 without the need for any packaging. The compression performance of Method III is substantially higher than that in refs 8,10,11 , and Method III validates the compression quality based on the QRS detection accuracy, which is essential for wearable applications. However, ECG compression techniques have typically been applied without being validated based on the QRS detection, making it difficult to assess the quality of the compression technique. Note that although Method III is a lossy compression method, the main features of the ECG signal morphology were preserved, as shown in Figs 2, 3 and 4. This indicates that a lossy compression method can be sufficient for ECG signal compression, in contrast to lossless methods that are more complex and require larger energy consumption.
In a lossy such as Method III, the minimum rate at which the ECG signal can be sampled-without losing the main events, such as the QRS complexes-has to be twice the highest frequency to achieve the Nyquist rate [F s > 2F max ]. In other words, the ECG sampling frequency has to be greater than or equal to 40 Hz.
Recent research into the implementation of lossy methods in an ambulatory environment faces many challenges 27 . The current lossy algorithms, including the compressive sensing algorithms, do not compare favorably with other state-of-the-art lossless compression techniques when considering only CR vs. reconstruction quality 27 . Therefore, the choice of using a lossy algorithm depends on its ability to provide a low-power implementation. However, the implementation of lossy algorithms are included in lossless framework, which adds more complexity to the expected nature of lossy algorithms. The main advantage of the proposed Method III, which is a pure lossy algorithm, is that it accomplishes a higher compression rate, and higher PRD (higher reconstruction signal quality) while achieving the highest QRS detection rate. QRS Detection. The literature cites many QRS algorithms that have not been tested against a standard database, making the results difficult to compare and evaluate. Furthermore, many algorithms scored a high detection performance using the overall number of detected beats (i.e., QRS complexes), as shown in Table 2. Note that the QRS detector in ref. 28 scored a high overall performance with a SE of 99.89% and a +P of 99.94%. However, the study's authors excluded files 214 and 215 in the MIT-BIH arrhythmia database 29 , and therefore this algorithm may not be superior in terms of performance. In addition, their algorithm was based on wavelet feature extraction and singularity for classification without applying any compression techniques, which is considered unsuitable for e-health applications.
As noted, some investigators have excluded records from the MIT-BIH arrhythmia database 29 for the sake of reducing noise in the processed ECG signals; consequently, their algorithms appeared to achieve improved performance. Other researchers excluded segments with ventricular flutter 30 and signals from patients with paced beats 31 from their investigations. In contrast, we tested the QRS detector over the compressed ECG signal without excluding any record or particular segment making the results more robust and the algorithm more efficient.
It is worth noting that Method III achieved a higher QRS detection accuracy because it worked as a filter that captured only the QRS complexes. The evidence of this claim can be seen in Fig. 6, where the main frequencies of the QRS complexes lie in the range of 0.5 Hz to 40 Hz. Method III with a sampling frequency of 80 Hz not only captures the main frequencies of the QRS complexes but also confirms the findings in refs [32][33][34] .
The detection performance of the Method III on the QT database on a record by record basis is shown in Table 5. The overall comparison of our results with the existing QRS detection algorithms on the QT database is demonstrated in Table 6. It summarizes the performances in terms of number of beats, SE, and +P. Note that the proposed algorithm performed higher in terms of SE and +P when compared to the Pan-Tompkins 33  with high performance over the 111,201 automatically annotated heart beats. Moreover, the proposed QRS detector has not been re-tuned, in other words we applied Method III to the QT database without changing the value of any parameter and without re-training the algorithm. The results are promising, and Method III (with the parameters B = 390 Hz and K = 80 Hz) can be applied over different databases, sampling frequencies, types of arrhythmia, and noise.

Battery-driven ECG Devices.
Based on the recommendation in ref. 35 , the better the computational efficiency, the faster the algorithm, and vice versa. Consequently, the faster the algorithm, the more suitable it is for real-time monitoring. In this study we used a computationally efficient QRS detector 33 along with an optimal compression technique (Method III) to improve both the processing and transmission time.
With advances in computational power, the emphasis on algorithm complexity is slowly decreasing. However, the demand for computationally efficient algorithms still remains for instances where ECG signals are collected and analyzed locally in hospitals, in the home setting, or in remote/rural areas where patient access to hospitals access is limited. Developing a computationally efficient algorithm to accommodate the new trend toward the use of mobile ECG devices is required for these cases. Moreover, implementing a joint compression and QRS detection algorithm to analyze long-term recorded signals in a time-efficient manner is also needed.
Typically, processing long recorded ECG signals is carried out on PCs with efficient memory and high-speed multi-core processors. This advantage is still not available for battery-operated devices: current wearable devices have limited memory and processing power [36][37][38] . In general, battery-driven ECG devices follow one of three strategies: 1) collect ECG signals for offline analysis; 2) collect ECG signals for real-time analysis within the device itself; or 3) collect ECG signals in real time and analyze the transmitted signals via a remote connection to a separate server. Each strategy has its own advantages and disadvantages in terms of processing time and power consumption. Our proposed Method III can be implemented in each strategy to improve both analysis time and QRS detection accuracy. E-health Systems. E-health systems often use ECGags (e.g., mobile phones or personal digital assistants) merely to collect ECG data (either wirelessly or via a wired connection) that are then sent to an ECGau (e.g., a central monitoring station using 4 G mobile telecommunication or internet) for further analysis 39,40 . Applying the proposed compression Method III at the ECGag level is beneficial as it: reduces the transmission delay, saves bandwidth, saves energy on the battery-drived device, saves memory for storage, and speeds up real-time diagnosis feedback. Although some analysis can be done locally on the ECGags before transmitting the compressed ECG signals, the analysis and the subsequent transmission of the ECG signals require a large a mount of energy that is taxes on the ECGag's limited battery life. Thus, investigating efficient methods for local analysis and transmission of ECG signals is needed in terms of compression and QRS detection. Overall, there is a need for a computationally efficient compression technique and a computationally efficient QRS detector for real-time analysis that must be robust and improve QRS detection accuracy. Simple compression and QRS detection algorithms offer low-cost hardware implementation in both power and size for body sensor networks 41 . Method III can be implemented in the hardware of the ECGag device (or the ECG sensor circuit) and also can be embedded in the software (or an app) of the ECGag device. Because of the robustness, performance, efficiency, and simplicity in implementation, Method III is considered ideal for e-health applications, as it can be implemented on both ECGags and ECGaus. The red curve curve represents the power spectra of Method III with a sampling frequency of 80 Hz. Note, the blue curves represent the power spectra of frequencies between 50 Hz and 360 Hz. The green curve represents the power spectra of QRS complexes (sampled at 360 Hz). It is clear that the optimal frequency band to detect QRS complexes is 0.5-40 Hz.  Table 5. Performance of Method III using B/K = 4.875 on the QT database. The results were obtained using the optimal values of B and K, which are 390 Hz and 80 Hz, respectively. TP stands for true positives (the number of QRS complexes detected as QRS complexes), FN stands for false negatives (the number of QRS complexes which have not been detected), FP stands for the number of false positives (non-QRS complexes detected as QRS complexes), SE stands for sensitivity, and +P stands for positive predictivity.
The proposed method could play a major role in the early detection of disease in low-and middle-income countries (LMICs) where there are major challenges with providing high-quality and universally accessible health care. This is because it follows the framework recommended in ref. 42 for tackling noncommunicable diseases by achieving simplicity and reliability. Application of the method may increase the capability to develop e-health technologies that significantly impact morbidity and mortality rates, especially for those living in LMICs.

Conclusions
Our proposed lossy compression Method III is a simple yet efficient method that is validated with QRS detection and should be used for wearable, point-of-care, and e-health ECG devices. Method III outperformed existing compression algorithms by achieving a compression ratio of 4.5× with the highest QRS detection accuracy (an SE of 99.78% and a +P of 99.92% using the MIT-BIH arrhythmia database). Results show that Method III is suitable for wearable sensors and processing long-term recordings and large databases as well as for expanding telemedicine capabilities in the near future. To the best of our knowledge, this is the first simple algorithm that improves QRS detection using data compression.

Methods
Data Used. The MIT-BIH arrhythmia database, which contains 109,984 heart beats 29 , was used to evaluate the performance of the compression methods. This database is widely used to evaluate ECG compression and QRS detection algorithms as it includes different types of noise and various shapes of arrhythmic QRS complexes 33 . Moreover, the database contains annotation of R peaks for all ECG signals. The benchmark database contains 48 half-hour ambulatory ECG recordings. These recordings have 11-bit resolution over 10 mV and are sampled at 360 Hz. This database is used for training the proposed method and for comparison against the published ECG compression methods.
The QT database with 111,301 beats 43 is used for evaluating the performance of our proposed compression algorithm. The QT database contains 105 records of 15-minute recording sampled at 250 Hz.

Compression Method I: Adaptive Linear Prediction.
Method I is our benchmark lossless compression method to compare and evaluate our proposed lossy method against. Several forward-prediction based approaches were used for QRS detection as reported in refs 8,44,45 . Linear forward prediction was used to estimate the current sample x[n] of the ECG signal in these approaches from its past m samples: In this paper, we evaluated the recently published work by Deepu and Lian 8 on ECG compression techniques using adaptive linear prediction. The block diagram representation of this method is shown in Fig. 7(a). The method applied a QRS detector on the prediction error e[n] signal, followed by fixed-length packaging.

Compression Method II: Compressive Sampling Matching Pursuit. Method II is our benchmark
lossy compression method to compare and evaluate our proposed lossy method against. It is based on compressive sensing for potential implementation in e-health systems as described in ref. 9 . In Method II the ECG signal goes throw of four processing stages: sampling, redundancy removal module, quantization and Huffman encoding, as shown in Fig. 7(b). The output signal y[n] is then transmitted to a remote ECGau where the reconstruction of original ECG signal is performed. The novelty of this algorithm relies on the reconstruction algorithm that relies on prior knowledge of ECG wavelet coefficient structure to improve reconstruction quality.
Compression Method III: Decimating by a Factor B/K. Method III is our proposed lossy compression method. This method achieved a sampling rate conversion by first applying an interpolation step (upsampling followed by a lowpass Filter [LPF]), by factor B and then decimating (LPF followed by downsampling) the output by factor K as discussed in refs 46,47 . The two filters can be combined as a single LPF with a frequency response H(ω), which possess the following frequency response characteristic: , 0 min( / , / ) 0, otherwise (5) where H(ω) is acting as a LPF for the interpolator and smoothing filter for the decimator. The block diagram for the decimation by a factor B/K method is shown in Fig. 7(c). The interpolation step can be expressed as follows: [ / ], 0, , 2 , 0, otherwise (6) Then, the interpolated signal goes to the LPF as follows: l After downsampling J[n] by a factor K, the output signal of the decimator is: where m is the data samples of the compressed ECG signals. In other words, if we desire a sampling rate conversion by a ratio B/K (where B and K are integers), we can achieve this by first interpolating by B and then decimating by K. The reason to introduce the interpolation step before the decimation step is to preserve the desired spectral characteristics of the processed signal 48 . We have two variables B and K to resample the ECG signal from B to K. An optimization step is needed to determine the optimal values of B and K. Any change in these parameters affects the overall performance of the algorithm proposed in this paper. The two variables are interrelated and cannot be optimized in isolation. Our goal is to find the Pareto optimal point, within all possible Pareto solutions 49 for our multi-objective problem. Our aggregate objective function denoted by g is a combination of the three objective functions: TP(B, K), FP(B, K), and FN(B, K) into a scalar function is defined as follows:  where g is the traditional F-measure or balanced F-score, which is the harmonic mean of sensitivity and positive predictivity. TP(B, K), FP(B, K), and FN(B, K) are the three objective functions to be maximized jointly. The Pareto frontier is formed with solutions (the values of two decision variables) that optimizes all parameters. Once the Pareto solutions are achieved, the optimal solution will be used for the implementation. In other words, we are systematically enumerating all possible combinations of B and K that maximizes the value of g. Note, the Pareto optimal solution assures simultaneous improvement of all objectives.

QRS Detection.
The detection algorithm of the QRS complex published in refs 33,35 , a two event-related moving averages (TERMA) algorithm 50 , was used during the data analysis to capture the QRS complexes. TERMA is a fast (computationally efficient) and suitable algorithm for implementation on battery-operated mobile devices, as recommended in refs 33,35 . Therefore, the use of TERMA in combination with the proposed compression algorithm is expected to improve the overall ECG signal analysis, storage capacity, processing time, and signal transmission. In other words, an immediate feedback to the user can be achieved at the ECGag level, long recorded ECG signals can be saved at the ECGags, the transmission between the ECGags and ECGaus will be optimized, and the decision making at the ECGau level will speed up. The TERMA-based QRS detection algorithm 50 consists of four stages (filtering, enhancing, generating potential blocks, and thresholding) and uses five parameters (starting frequency [F 1 ], end frequency [F 2 ], first moving average [MA event with a window size of W 1 ], second moving average [MA cycle with a window size of W 2 ], and rejection threshold [β]). First, the ECG signal was passed through a third-order Butterworth filter with a bandpass filter F 1 − F 2 . The resulting signal was then squared, and two moving averages (MA event and MA cycle ) were applied with a rejection threshold (β) to generate blocks of interest. After applying a rigorous optimization step discussed in ref. 33 , the optimal parameters for the QRS detector were F 1 = 8 Hz, F 2 = 20 Hz, W 1 = 97 ms, W 2 = 611 ms, and β = 8. Therefore, the QRS detector was within these optimal parameters.
The TERMA-based QRS detector will only be applied to proposed Methods III. Since the QRS detection performance was not reported for Method II, Method I is the benchmark to compare the proposed methods against as described in ref. 8 . Method I will use its already incorporated QRS detector, which removes the high-frequency impulse noise from the prediction error signal. The output will be run through the Savtizky-Golay filter to smooth the incoming signal by approximating the signal within a specified window of size W to a polynomial of order q that best matched the given signal in a least-squares sense.
Compression Ratio. The bit compression ratio (BCR) was calculated as follows: where BW c and BW u refer to the bit widths of compressed and uncompressed samples, respectively. If we evaluate the performance of a compression algorithm based only on BCR, we can conclude that the higher the BCR, the better the compression algorithm.
Percentage Root Means Squared Difference. The percentage root means squared difference (PRD) is used to quantify the recovered signal quality by measuring the error between original and reconstructed signal, as follows: where x is raw ECG signal while x is the reconstructed ECG signal. If we evaluate the performance of a compression algorithm based only on PRD, we can conclude that the lower the PRD, the better the compression algorithm.