Signal Acquisition-Independent Lossless Electrocardiogram Compression Using Adaptive Linear Prediction

In this paper, we propose a lossless electrocardiogram (ECG) compression method using a prediction error-based adaptive linear prediction technique. This method combines the adaptive linear prediction, which minimizes the prediction error in the ECG signal prediction, and the modified Golomb–Rice coding, which encodes the prediction error to the binary code as the compressed data. We used the PTB Diagnostic ECG database, the European ST-T database, and the MIT-BIH Arrhythmia database for the evaluation and achieved the average compression ratios for single-lead ECG signals of 3.16, 3.75, and 3.52, respectively, despite different signal acquisition setup in each database. As the prediction order is very crucial for this particular problem, we also investigate the validity of the popular linear prediction coefficients that are generally used in ECG compression by determining the prediction coefficients from the three databases using the autocorrelation method. The findings are in agreement with the previous works in that the second-order linear prediction is suitable for the ECG compression application.


Introduction
Cardiovascular disease (CVD) has become the second major cause of death of noncommunicable diseases (NCDs) for several years. Although the trend of NCD mortality was decreased over the last 20 years, the COVID-19 pandemic has aggravated that trend by increasing the risk of illness and death for the existing NCD patient [1].
An electrocardiogram (ECG) signal, consisting of the P, T, and U waves and the QRS complex, represents the electrical activity of the heart [2]. For the diagnosis and treatment of CVD, monitoring and recording of the ECG signals are required. The ECG signal can represent electrical activities, heart rate variability (HRV), and abnormalities of the heart. One approach to the ECG application is telemedicine, which is the implementation of the internet of things (IoT), wireless sensor networks, and embedded systems in the medical system. Also, multi-lead ECG acquisition, long-term monitoring and recording, higher resolution, and frequency of the signal are required for better ECG monitoring and diagnosis. To improve the performance and efficiency of the data transmission, data storage, and clinical application, the data compression process for the ECG signal is important, especially for those requirements mentioned before.
The compression method for the ECG signal is approached in two directions, i.e., lossy and lossless compression. Lossy compression significantly has a higher compression ratio than lossless compression, where the compression ratio is the ratio of the original data size to the compressed data size. However, the lossy compression generally has some reconstruction error which means the reconstructed signal value is different from the original one. While the lossless term for the ECG signal compression implies no error from the reconstructed signal.

Materials and Methods
The proposed compression method aims to increase the compression ratio, which is the ratio of the original data size to the compressed data size while maintaining the lossless feature. In addition, the compression method was designed to be operable in real time without determining any parameters or thresholds. The method proposed in this work is based on the lossless compression concept. The adaptive linear prediction was introduced in recent works where the linear prediction function was changed according to the trend of the ECG signal. However, this concept does not bring the lowest linear prediction error, especially in regions between intervals, abnormal beats, and noisy regions. In addition, the thresholds of some parameters for determining the linear prediction functions may be changed when the data sets or the acquisition setups of the ECG signals are different.
The encoding process in [5] is applied in this work since the process can adaptively adjust the parameters according to the input signal. The overall scheme of the proposed ECG compression method comprising the compression stage and reconstruction stage is shown in Figure 1. encoding process in [5] is applied in this work since the process can adaptively adjust the parameters according to the input signal. The overall scheme of the proposed ECG compression method comprising the compression stage and reconstruction stage is shown in Figure 1.
The compression stage for ECG signal in this work includes 2 processes, i.e., the prediction error-based adaptive linear prediction and the Golomb-Rice coding. The concept of this compression stage is to minimize the ECG signal level into the prediction error for each sample by using linear prediction and to encode the prediction error to the binary format by using length-variable coding. Meanwhile, the reconstruction of the compressed signal data can be done by reversing the compression processes. The related techniques are described in more detail next.

Prediction Error-Based Adaptive Linear Prediction
The linear prediction has been implemented in many related works for ECG compression since it has the benefit of low complexity for implementation in hardware such as Silicon-on-Chip (SoC) and Field Programmable Gate Array (FPGA). In this research, we exploited the modified forward linear prediction for the linear prediction process. The predicted value x (n) for the linear prediction order p of the signal x(n) can be predicted from the linear combination of the past signal value x(n − i) with the linear prediction function in Equation (1) where a (i), i = 1, p, are the linear prediction coefficients, and the prediction error e (n) of the prediction order p can be defined with Equation (2), i.e., Therefore, the main factor that affects the compression ratio in this approach is the prediction error. The compression ratio can be maximized by minimizing the prediction error. This means the linear prediction order and the linear prediction coefficients must be determined or selected appropriately for each ECG signal. One of the methods to determine the linear prediction coefficients is by using the autocorrelation method, which can be solved by using the Yule-Walker equations with the Levinson-Durbin algorithm The compression stage for ECG signal in this work includes 2 processes, i.e., the prediction error-based adaptive linear prediction and the Golomb-Rice coding. The concept of this compression stage is to minimize the ECG signal level into the prediction error for each sample by using linear prediction and to encode the prediction error to the binary format by using length-variable coding. Meanwhile, the reconstruction of the compressed signal data can be done by reversing the compression processes. The related techniques are described in more detail next.

Prediction Error-Based Adaptive Linear Prediction
The linear prediction has been implemented in many related works for ECG compression since it has the benefit of low complexity for implementation in hardware such as Silicon-on-Chip (SoC) and Field Programmable Gate Array (FPGA). In this research, we exploited the modified forward linear prediction for the linear prediction process. The predicted valuex p (n) for the linear prediction order p of the signal x(n) can be predicted from the linear combination of the past signal value x(n − i) with the linear prediction function in Equation (1) where a p (i), i = 1, p, are the linear prediction coefficients, and the prediction error e p (n) of the prediction order p can be defined with Equation (2), i.e., Therefore, the main factor that affects the compression ratio in this approach is the prediction error. The compression ratio can be maximized by minimizing the prediction error. This means the linear prediction order and the linear prediction coefficients must be determined or selected appropriately for each ECG signal. One of the methods to determine the linear prediction coefficients is by using the autocorrelation method, which can be solved by using the Yule-Walker equations with the Levinson-Durbin algorithm [17]. In terms of adaptive linear prediction (ALP), the order of the linear prediction function can be changed following the trends or the region of the ECG signal to give the lowest prediction error. We initially proposed a compression method and tested it on small data in [18]. The algorithm of the prediction error-based adaptive linear prediction consists of 2 steps. The first step is to calculate the prediction value and the prediction error of each linear prediction function from the 1st to 4th order. These coefficients of the linear prediction were used in many related works using the triangle of binomial transform coefficients like Pascal's triangle. All 4 linear prediction functions are shown in Equations (3)-(6), respectively.
The second step is to compare the absolute value of each prediction error from the first step. The smallest absolute prediction error is chosen to be the determined absolute prediction error as shown in Equation (7), e(n) = min e p (n) The block diagram that summarizes the prediction error-based adaptive linear prediction method is shown in Figure 2.   Figure 3 illustrates an ECG signal from the MIT Arrhythmia database record number "100" along with its prediction errors from the 1st to 4th linear prediction orders and the determined prediction error from Equation (7). We can see that the lower order of linear prediction function yields a better prediction error in the flat region, whereas the higher order yields a better prediction error in the high slope region.

Modified Golomb-Rice Coding
The concept of entropy coding is to encode the data in length-variable code format. Many related works introduced Huffman coding and Golomb-Rice coding for data compression since they are lossless compression methods. Golomb-Rice coding was introduced by Solomon W. Golomb [19] and was modified by Robert F. Rice [20,21]. The idea of this method is to convert the data value to the quotient and remainder by using the power of 2, which is suitable for storing the compressed data in binary format.  The non-negative prediction error is then encoded into the quotient and remainder by using the power k(n) of 2 in Equations (9) and (10), The modified Golomb-Rice coding process converts the prediction error to a nonnegative integer value since the prediction error from the linear prediction process is the signed integer value, while the encoding input must be a non-negative value [5]. For the non-negative value M(n), the prediction error e(n) can be converted by Equation (8).
The non-negative prediction error is then encoded into the quotient and remainder by using the power k(n) of 2 in Equations (9) and (10), where k(n) is the base-2 logarithm of the mean absolute error (MAE) of the 3 latest samples, defined as Equations (11) and (12), k(n) = log 2 (MAE(e(n))) The compressed data c(n) includes the quotient q(n), which is encoded in unary format, one of the '0 bit for the quotient and the remainder separation, and the remainder r(n), which is encoded in binary format, i.e., The length of the compressed data depends upon the absolute prediction error and the parameter k(n). The block diagram of the Golomb-Rice coding can be shown in Figure 4.
where k(n) is the base-2 logarithm of the mean absolute error (MAE) of the 3 latest samples, defined as Equations (11) and (12), The compressed data c(n) includes the quotient q(n), which is encoded in unary format, one of the '0′ bit for the quotient and the remainder separation, and the remainder r(n), which is encoded in binary format, i.e., The length of the compressed data depends upon the absolute prediction error and the parameter k(n). The block diagram of the Golomb-Rice coding can be shown in  The flowchart of the proposed ECG lossless compression method is shown in Figure  5. The flowchart of the proposed ECG lossless compression method is shown in Figure 5.
ples, defined as Equations (11) and (12), The compressed data c(n) includes the quotient q(n), which is encoded in unary format, one of the '0′ bit for the quotient and the remainder separation, and the remainder r(n), which is encoded in binary format, i.e., The length of the compressed data depends upon the absolute prediction error and the parameter k(n). The block diagram of the Golomb-Rice coding can be shown in  The flowchart of the proposed ECG lossless compression method is shown in Figure  5.

Data Reconstruction Process
The ECG signal can be reconstructed back by reversing the compression process. The compressed data is encoded with the modified Golomb-Rice coding as described earlier.
Then the reconstructed ECG signal value x r (n) can be computed with Equation (2) sincê x p (n) can be computed with the 4 recently reconstructed signals, and e(n) is received as the compressed data. The reconstructed signal x r (n) will be the same as the original ECG data x(n). Hence, this is a lossless compression method since there is no reconstruction error. Note that the first 4 samples of the ECG signal data must be encoded and stored directly to compute the 1st to 4th order of the linear prediction at the compression and reconstruction process. The data packet of the compressed data is shown in Figure 6.
x (n) can be computed with the 4 recently reconstructed signals, and e(n) is received as the compressed data. The reconstructed signal x (n) will be the same as the original ECG data x(n). Hence, this is a lossless compression method since there is no reconstruction error. Note that the first 4 samples of the ECG signal data must be encoded and stored directly to compute the 1st to 4th order of the linear prediction at the compression and reconstruction process. The data packet of the compressed data is shown in Figure 6.  Figure 7 illustrates the proof of the lossless compression method. The first plot is an example of ECG signal data from the record number "100" with 2 s in time duration. The second plot is the prediction error that is determined before the encoding process. Then the third plot is the decoded prediction error from the compressed data, whereas the fourth plot is the reconstructed ECG signal data. The last plot shows the difference between the original data and the reconstructed data to confirm that there is no reconstruction error in the proposed method. The compression ratio achieved from this example is 3.63.  Figure 7 illustrates the proof of the lossless compression method. The first plot is an example of ECG signal data from the record number "100" with 2 s in time duration. The second plot is the prediction error that is determined before the encoding process. Then the third plot is the decoded prediction error from the compressed data, whereas the fourth plot is the reconstructed ECG signal data. The last plot shows the difference between the original data and the reconstructed data to confirm that there is no reconstruction error in the proposed method. The compression ratio achieved from this example is 3.63.

Linear Prediction Coefficient Determination
As for a linear prediction-based ECG compression method, the prediction order and coefficients are very crucial. Some questions still remain to answer, for example, which of Equations (1)-(4) is the best for ECG signal prediction? Are the coefficients in those equations good enough? Hence, they deserve a close investigation of how or how well we could come up with them. Consider a function that predicts the current sample by using the linear combination of the past samples as in Equation (1); the linear prediction coeffi- Figure 7. Example of signals in the proposed lossless ECG compression method: original ECG signal, prediction error before encoding and after the decoding process, reconstructed ECG signal, and the reconstruction error for the MITDB record number "100". To convert the amplitude to millivolts, divide the value by 200.

Linear Prediction Coefficient Determination
As for a linear prediction-based ECG compression method, the prediction order and coefficients are very crucial. Some questions still remain to answer, for example, which of Equations (1)-(4) is the best for ECG signal prediction? Are the coefficients in those equations good enough? Hence, they deserve a close investigation of how or how well we could come up with them. Consider a function that predicts the current sample by using the linear combination of the past samples as in Equation (1); the linear prediction coefficients are a set of coefficients that minimize the prediction error One of the approaches to determine the coefficients a k , k = 1, 2, . . . , p, is by using the autocorrelation method [17]. Yule-Walker equations were used to solve the coefficients with the autocorrelation of the signal x(n), i.e., solve the following equation: where R(k) is the autocorrelation of x(n) for time lag k = 1, 2, . . . , p. This equation can be solved by using the well-known Levinson-Durbin recursive procedure [22].

ECG Data Sets
For the performance evaluation for data compression in this research, we used three public data sets of ECG signals, i.e., the PTB Diagnostic ECG database (PTBDB), the European ST-T database (EDB), and the MIT-BIH Arrhythmia database (MITDB). As mentioned earlier, we initially tried to compress a part of MITDB in [18]. However, more experiments needed to be done, and some issues needed to be investigated. Hence, in this research, extensive experiments were performed on these three ECG data sets. It is worthwhile noting that these three data sets have totally different characteristics [23]  As we can see, these three data sets are different in all of these features, i.e., number of records, time duration per record, sampling frequency, and resolution. Hence, they will be very good candidates to be used in the evaluation of lossless ECG compression across different data sets or different setups.

Lossless Compression Performance
The performance of a data compression method is defined in terms of the compression ratio (CR), i.e., CR = B 0 /B C (16) where B 0 is the original ECG data size and B C is the compressed ECG data size. The compression ratio can indicate the reduced data size of the compressed data compared to the original data size. The larger compression ratio means more data size has been reduced. The average compression ratio from all records of each database is used to compare the compression performance with other methods. For the lossy compression method, the reconstructed error of the compressed signal data is also defined by using Percent Root-Mean-Square Difference (PRD). Since there is no reconstruction error for the lossless compression, the PRD for the lossless compression is always 0.
For the PTBDB ECG records, the EDB ECG records, and the MITDB ECG records, the proposed compression method achieved average compression ratios of 3.16, 3.75, and 3.52, respectively. Figure 8a,b,c illustrates the compression ratio achieved for each record from the PTBDB, EDB, and MITDB data sets, respectively. These results clearly demonstrate different ranges and deviations of compression ratios in different data sets. For the PTBDB ECG records, the EDB ECG records, and the MITDB ECG records, the proposed compression method achieved average compression ratios of 3.16, 3.75, and 3.52, respectively. Figure 8a,b,c illustrates the compression ratio achieved for each record from the PTBDB, EDB, and MITDB data sets, respectively. These results clearly demonstrate different ranges and deviations of compression ratios in different data sets.
To evaluate the data compression performance of the proposed method to other state-of-the-art methods, its compression ratios achieved are compared to the related works for PTBDB, EDB, and MITDB data sets, as shown in Tables 1-3, respectively.

Ref.
Compression Method Average CR [4] Multi-channel ALP (1st, 2nd, and 4th order weight average) + Golomb-Rice Coding 3.98 (Multi-lead) To evaluate the data compression performance of the proposed method to other stateof-the-art methods, its compression ratios achieved are compared to the related works for PTBDB, EDB, and MITDB data sets, as shown in Tables 1-3, respectively.

Linear Prediction Coefficient Comparison
For the compression method proposed in this research, the linear prediction coefficients are determined by using Pascal's triangle of binomial transform coefficients, as shown in Equations (3)-(6). In the related works, each order of the linear prediction with these coefficients was used for different regions or trends of the ECG signal. The low-order linear prediction function yields a lower prediction error at the flat region, while the highorder yields better performance in the complex interval or the high slope region. In [6], it was mentioned that the 2nd order of the linear prediction function yielded the best performance from the 1st to 4th order by comparing mean absolute prediction error and root-mean-square prediction error.
In this section, the linear prediction coefficients for the ECG signal were determined by using the autocorrelation method mentioned in Section 2.4. The highest order to determine the coefficients was varied from 1 to 4, and each coefficient was also rounded to an integer value. This would make it usable in the lossless compression method since all the signal values and parameters must be in the integer format. The proposed and average determined coefficients are shown in Tables 4 and 5, respectively. In addition, the average determined coefficients rounded to the nearest integers are shown in Table 6.

Discussion
From the compression results compared to the state-of-the-art works in Tables 1-3 in Section 4.1, the proposed compression method achieved compression ratios close to or better than that of the others. The results demonstrate that the proposed lossless ECG signal compression method is very robust. It can be applied even in different ECG signal acquisition setups, i.e., different numbers of records, different time duration per record, different sampling frequencies, or different resolutions (number of bits per sample). For the PTBDB data set, the result in [4,5] showed CR of 3.98 and 4.07, which is higher than the 3.16 achieved by the proposed method. However, we cannot really compare them because, in [4], data from other channels were required to reconstruct the data in the channel of interest. It was not a single-lead ECG signal reconstruction like what we have here. For the EDB and MITDB data sets, it is interesting that the results in [8] yielded very high CRs compared to other existing methods. In [8], however, it was mentioned that not all data were used; there was data selection to make it comparable to a previous method. Meanwhile, we applied the proposed method for the entire data in each data set. Hence, the results may not be comparable. To make a fair comparison, we need to make sure that all methods take the exact same ECG signals as the inputs.
We compare the prediction error for each order and the determined absolute prediction error from the MITDB data set in Figure 2 (see Section 2.1), the PTBDB data set in Figure 9, and the EDB data set in Figure 10. The results in these figures show that the higher resolution and sampling frequency of the ECG signal will cause a higher prediction error which in turn decreases the compression ratio. In the PTBDB data set, the high frequency and resolution of the original signals also significantly increases the low-order prediction errors in the flat regions, whereas it is lower for the MITDB and EDB data sets. This is the reason that the average CR for the PTBDB data set is lower than that for the MITDB and EDB data sets. Tables 4-6 in Section 4.2, the proposed and algorithmdetermined linear prediction coefficients were compared. Each order of the proposed coefficient was chosen to minimize the prediction error for the different signal regions. Meanwhile, the determined coefficient was calculated to fit the entire length of the signal. Therefore, the results show that the 2nd order of the linear prediction function is sufficient to predict the ECG signal with an acceptable prediction error. The corresponding coefficients are a 1 = 2 and a 2 = −1. It is very interesting that although all three data sets are different in signal acquisition setups, especially the sampling frequency, which dictates the temporal information, they still produce the same rounded prediction coefficients. This is in agreement with the results in [7] in that, using the mean absolute prediction error and root-mean-square prediction error, the 2nd order of the linear prediction function yielded the best prediction performance. From the results shown in Tables 4-6 in Section 4.2, the proposed and algorithmdetermined linear prediction coefficients were compared. Each order of the proposed coefficient was chosen to minimize the prediction error for the different signal regions. Meanwhile, the determined coefficient was calculated to fit the entire length of the signal. Therefore, the results show that the 2nd order of the linear prediction function is sufficient to predict the ECG signal with an acceptable prediction error. The corresponding coefficients are a = 2 and a = −1. It is very interesting that although all three data sets are different in signal acquisition setups, especially the sampling frequency, which dictates the temporal information, they still produce the same rounded prediction coefficients. This is in agreement with the results in [7] in that, using the mean absolute prediction error and root-mean-square prediction error, the 2nd order of the linear prediction function yielded the best prediction performance. Figure 9. The ECG signal, prediction errors for linear prediction orders 1, 2, 3, and 4, and the determined prediction error of PTBDB record "s0014lre". To convert the amplitude to millivolts, divide the value by 2000. Figure 10. The ECG signal, prediction errors for linear prediction orders 1, 2, 3, and 4, and the determined prediction error of EDB record "e0103". To convert the amplitude to millivolts, divide the value by 200.

Conclusions
In this research, a lossless ECG signal compression method was proposed. The method exploited the prediction error-based adaptive linear prediction and the modified Golomb-Rice coding. The evaluation results of the proposed method on the PTB Diagnostic database, the European ST-T database, and the MIT-BIH Arrhythmia database achieved an average compression ratio (CR) of 3.16, 3.75, and 3.52, respectively. These average CRs on these three data sets are comparable to or better than most of the other related works. The results also suggested that the proposed lossless ECG signal compression method was very robust and could be applied in different ECG signal acquisition setups, i.e., numbers of records, time duration per record, sampling frequencies, or resolution. In addition, the proposed linear prediction coefficients were compared to the coefficients determined by the autocorrelation method with Yule-Walker equations and the Levinson-Durbin method. The results demonstrated the agreement with previous work, i.e., the 2nd order of the linear prediction function is suitable to apply to ECG signal compression with the corresponding prediction coefficients a = 2 and a = −1 . Even though the proposed method is robust to different ECG signal acquisition setups, its obvious limitation is that it is specifically designed for ECG signals only. The ongoing and future trends of this work include how to further increase the compression ratio in this lossless ECG signal compression and how to implement the proposed method to other Figure 10. The ECG signal, prediction errors for linear prediction orders 1, 2, 3, and 4, and the determined prediction error of EDB record "e0103". To convert the amplitude to millivolts, divide the value by 200.

Conclusions
In this research, a lossless ECG signal compression method was proposed. The method exploited the prediction error-based adaptive linear prediction and the modified Golomb-Rice coding. The evaluation results of the proposed method on the PTB Diagnostic database, the European ST-T database, and the MIT-BIH Arrhythmia database achieved an average compression ratio (CR) of 3.16, 3.75, and 3.52, respectively. These average CRs on these three data sets are comparable to or better than most of the other related works. The results also suggested that the proposed lossless ECG signal compression method was very robust and could be applied in different ECG signal acquisition setups, i.e., numbers of records, time duration per record, sampling frequencies, or resolution. In addition, the proposed linear prediction coefficients were compared to the coefficients determined by the autocorrelation method with Yule-Walker equations and the Levinson-Durbin method. The results demonstrated the agreement with previous work, i.e., the 2nd order of the linear prediction function is suitable to apply to ECG signal compression with the corresponding prediction coefficients a 1 = 2 and a 2 = −1. Even though the proposed method is robust to different ECG signal acquisition setups, its obvious limitation is that it is specifically designed for ECG signals only. The ongoing and future trends of this work include how to further increase the compression ratio in this lossless ECG signal compression and how to implement the proposed method to other signals in which lossless compression is required. We can anticipate that the determination of the prediction coefficients of each particular signal will be crucial. If the proper prediction coefficients are determined, efficient lossless compression will be achieved by the proposed method.