Compressing electrocardiogram signals using parameterized wavelets Cristiano M. Agulhari
Rosanna M. R. Silveira
Ivanil S. Bonatti
Telematics Department, FEEC/UNICAMP 13083-970 - Campinas - SP Brazil
National Institute of Telecommunications - Inatel 37540-000 - Santa Rita do Sapucaí - MG - Brazil
Telematics Department, FEEC/UNICAMP 13083-970 - Campinas - SP Brazil
[email protected]
[email protected]
[email protected] ABSTRACT
A compression method, based on the choice of a wavelet that matches the electrocardiogram signal to be compressed, is proposed in this paper. The scaling filter that minimizes the distortion of the compressed signal are used to determine the wavelet. The scaling filter is used to generate the coefficients of projection of the ECG signal in the scaling and wavelet subspaces, and only the most significant coefficients are retained. Coding methods are applied to the retained coefficients in order to improve the compression.
Categories and Subject Descriptors 8 [Computer Applications in Health Care]: Signal and Image Processing in Health
General Terms Signal Processing
Keywords Data compression, electrocardiogram signals, ECG, wavelet
1. INTRODUCTION Data compression is a key component of communications and storage systems. The decompressed data must be identical to the original data in the lossless compression context. This feature is mandatory, for example, in the storage of texts whose reliability must be preserved [22]. Even in systems that perform lossy compression, lossless compression is a key component since the encoding of the original data with as few bits as possible is critical to the effectiveness of the system. Most lossy compression algorithms belong to the following categories: • Direct data compression methods, which detect redundancies by analyzing the signal samples [16];
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. To copy otherwise, to republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. SAC’08 March 16-20, 2008, Fortaleza, Ceará, Brazil Copyright 2008 ACM 978-1-59593-753-7/08/0003 ...$5.00.
• Pattern recognition methods, in which some parameters of the signal are extracted and used for compression [13]; • Predictive methods, which calculate the error between the real and the predicted data and quantize and code both the error and the information needed to reproduce the prediction [20]; or • Transform methods, which first transform the signal to another time-frequency representation better suited for detecting and removing redundancies [3], [4], [5], [9], [14], [17], [18] and [19]. The wavelet-based compression algorithm proposed in this paper belongs to the latter category. All so-called firstgeneration wavelet systems are built from a single scaling function by scaling and translation operations. Almost all useful wavelet systems satisfy the multi-resolution conditions, i.e. if the basic expansion signals are made half as wide and translated in steps in the same way, they will represent a larger class of signals exactly or give a better approximation of any signal. The lower resolution coefficients can be calculated from the higher resolution coefficients by a treestructured algorithm called a filter bank. Because there are several representations for wavelets, they can be designed to fit individual applications being ideal for adaptive systems that adjust themselves to suit the signal [8]. Compression techniques using wavelets have been applied in many different engineering sectors with efficiency, especially in electrocardiogram (ECG) signals [14]. An ECG is a set of electrical signals measured by electrodes placed in contact with the human body. The ECGs are almost periodic consisting of cardiac beat pulses with periods of approximately one second. The efficiency of ECG compression using wavelets depends on the shape of the wavelet, motivating a series of researches on the choice of different waveforms for this technique [4], [9], [14], [19] and [21]. The method proposed in this paper consists of searching the scaling function that yields the highest compression. The search is formulated as a minimization problem on the scaling filter, which is parameterized in order to satisfy some constraints. A decomposition procedure is then applied to the ECG signal to find the coefficients of projection of the signal in the scaling and wavelet subspaces. A certain number of coefficients is retained and encoded. A string that informs the position of the retained coefficients must also be encoded to compose the compressed signal.
The remainder of the paper is organized as follows. Section 2 presents the algorithm used to compress the ECG signals. The method to define the wavelet used in the compression procedure is described in Section 3. Section 4 details the coding algorithms. Section 5 presents some numerical experiments and Section 6 concludes the paper.
2. ECG COMPRESSION The goal of transform-based methods, in the compression context, is to concentrate the energy of the signal in a small amount of transformed coefficients. Consequently it is possible to discard the coefficients smaller than a given threshold without affecting considerably the distortion of the reconstructed signal. The broad outlines of the ECG compression method consist of: • Preprocessing of the ECG signal in order to attain a resulting signal with a zero mean, since in ECG signal the important part is not the signal level but the time variation of the ECG waveform [3]. • Choice of the wavelet that yields the better compression of the ECG signal. • Selection of the significant wavelet coefficients by retaining the largest coefficients computed by the wavelet decomposition of the ECG signal. The number of significant coefficients selected is given by Nη , (1) σ being Nη the number of coefficients of the wavelet decomposition of the ECG signal on the resolution level η, NR the number of significant coefficients obtained and σ the pre-specified Retention Ratio. NR =
• Encoding the position of the significant coefficients, defined by a string of zeros and ones (if the coefficient is significant there is a corresponding one in the string, otherwise a zero is used). The string is encoded using the method described on the Section 4.2. • Quantization and encoding of the significant coefficients using a source code applied to a quantized version of the significant coefficients, as explained in subsection 4.1. The broad outlines of the ECG decompression method consist of: • Decoding the significant coefficients and the string that contains the position of the significant coefficients. • Reconstruction of the ECG signal samples by performing the wavelet reconstruction procedure. The positions of the non significant coefficients are filled with zero. The compression ratio (CR) is defined as s CR = c+p+h
(2)
where s is the total number of bits of the original samples of the ECG signal, c is the total number of bits used to encode all the significant coefficients, p is the total number of
bits resulting of the encoding of the string that contains the position of the significant coefficients and h is a header containing the parameters necessary to reconstruct the signal. The percent root-mean-square distortion (PRD) is given by 1/2 X (ν[k] − νˆ[k])2 k × 100 (3) PRD = X 2 (ν[k] − ν[k]) k
being ν[k] the original signal, νˆ[k] the reconstructed signal and ν[k] the mean of the original signal. The CR and the PRD are highly dependent on the number of significant coefficients, on the chosen wavelet and on the number of quantization levels considered on the method.
3.
CHOICE OF THE WAVELET
A nonzero real function ϕ(x) that can be expressed in terms of a weighted sum of shifted ϕ(2x) as X √ k ∈ Z, x, ℓ[k] ∈ R (4) ℓ[k] 2ϕ(2x − k), ϕ(x) = k
is a scaling function, being ℓ[n] the scaling filter [10]. The wavelet function is defined from the scaling function as X √ (5) h[k] 2ϕ(2x − k), ψ(x) = k
where h[n] is the wavelet filter. The sequence h[n] can be obtained from the sequence ℓ[n] as h[n] = (−1)n ℓ[m − n − 1],
(6)
where m is the order of the scaling and wavelet filters. The decomposition procedure to find the coefficients of projection of a signal in the scaling and wavelet subspaces is given by [8] aη−1 [n] = {ℓ[−n] ∗ aη [n]}↓2
(7)
bη−1 [n] = {h[−n] ∗ aη [n]}↓2 ,
(8)
aη [n] = ℓ[n] ∗ {aη−1 [n]}↑2 + h[n] ∗ {bη−1 [n]}↑2
(9)
and being aη [n] the coefficients of projection in the scaling subspace on the level η, bη [n] the coefficients of projection in the wavelet subspace on the level η, ∗ the convolution operator and {.}↓2 the downsample operator. The reconstruction procedure is given by
being {.}↑2 the upsample operator. Given a function f (x) to be compressed, the samples f [n] can be seen as the projection coefficients of the signal f (x) on the scaling subspace on the level η if the sampling rate is 2η . Therefore, Equations (7) and (8) allow the computation of the coefficients in a rate equal to 2η−1 by inputting the samples f [n] in the filters ℓ[−n] and h[−n]. The number κ of samples of the discrete version of the function ϕ(x) is given by κ = (m − 1)2η−1 + 1.
(10)
The number Mk of coefficients bk [n], k = {0, . . . , η − 1} is given by Mk + m − 1 Mk−1 = (11) 2
with Mη = N (number of samples of the f [n]). Note that the choice of the wavelet that yields the better compression for a given signal is reduced to the problem of determining the proper scaling filter ℓ[n]. In order to determine the proper scaling filter, a set of constraints must be satisfied. Since there are m/2 + 1 constraints applied to the scaling filter with m coefficients, there are γ degrees of freedom in the choice of ℓ[n], being γ given by m γ= − 1. (12) 2 Using the method described in [21], it is possible to express the scaling coefficients ℓ[n] using a set of parameters θ in a way that the constraints applied to the scaling filter are embedded on the parameterization and the search of a proper scaling filter becomes a search on the domain of the parameters. The set of parameters θ is defined as θ = {θ1 , θ2 , . . . , θγ }, θk ∈ [0, π], k ∈ [1, γ].
(13)
The wavelet that yields the better compression for the ECG signal is obtained by solving the following optimization problem min PRD(θ). θ
(14)
Since the function PRD(θ) is a non-convex function with several local minima, the optimization problem is solved using a genetic algorithm, implemented using the Genetic Algorithm Tool package of Matlab [7]. The value of PRD(θ) in the optimization problem described in the Equation (14) is computed by the following steps: 1. For a set of parameters θ, find the scaling and wavelet coefficients; 2. Compute the resolution η by 2(ρ − 1) η ≈ log2 , m−1
(15)
where ρ is the number of samples of one beat pulse of the ECG signal. The value of η is computed to produce κ approximately equal to ρ (number of samples of the scaling function) given by Equation (10); 3. Decompose the ECG signal on the resolution η as described in Equations (7) and (8), keeping the NR largest coefficients and replacing the remaining coefficients by zero, where NR is given by Equation (1) for a retention ratio σ previously defined; 4. Compute the reconstructed signal νˆθ [n] using Equation (9) and the quadratic distortion PRD(θ) using Equation (3).
4. CODING The coding methods used were chosen after a series of tests, detailed in the Technical Reports [1] and [2], using three possible coding algorithms: Huffman [15], Lempel-ZivWelch (LZW) [23] and variants of the Run Length Encoding (RLE) method [6], [12]. The Huffman method consists of constructing a dictionary of symbols in which the symbols that appear more frequently in the sequence are encoded using a lesser number of bits and both the dictionary and the
encoded sequence must be stored. The LZW method consists of constructing a dictionary containing all the primary symbols of the sequence and then updating the dictionary as the sequence is encoded, in a way that the dictionary can be fully reconstructed in the decompression procedure using only the encoded sequence. The basic RLE method consists on counting the number of consecutive symbols (runs) that appear in the input sequence and then outputting the length of the runs in the encoded sequence.
4.1
Quantization and encoding of the significant coefficients
The significant coefficients are quantized using q = 11 bits. The minimum value cmin of the retained coefficients is stored and subtracted from all the coefficients, being cmin used to recover the actual coefficients in the decompression procedure. The resulting coefficients are then encoded using the LZW algorithm [23], as justified in [2]. The output encoded symbols have b bits obtained by the application of the LZW algorithm.
4.2
Encoding the position of the significant coefficients
In order to map the position of the significant coefficients (bitmap), a string of zeros and ones is constructed in a way that if the coefficient is significant there is a corresponding one in the string, otherwise a zero is used. The string is divided into three sections, being the first and second section delimited by the first zero that appears in the string. The second and the third sections are delimited by the first occurrence of z = 40 consecutive zeros in the string. The first section is composed by a sequence of consecutive ones, the second section is composed by alternate sequences of zeros and ones and the third section is composed by long sequences of zeros with a few occurrences of ones. If the number of consecutive zeros is smaller than z the string is divided in only two sections. The number of consecutive ones in the first section is encoded by 9 bits. The second section is encoded in two steps. First, the basic RLE method is applied [12], then the Huffman compression method [15] is applied on the result of the first step. The third section is compressed using the RLE method proposed by [6]. The application of these methods are justified in [1].
4.3
Structure of the compressed signal
The compressed signal is composed by the following components: • The header, which contains: – The encoded parameters θ that generates the wavelet used to compress the signal; – The number of bits of the encoded sequence of the second section of the bitmap; – The number b of bits; – The encoded minimum value cmin . • The encoded bitmap; • The encoded significant coefficients.
The goal of the experiments is to compare the compression method proposed in this paper with the method proposed by Rajoub in [19] with the modifications suggested by [3]. The ECG signals to the Arrythmia database of the “Research Resource for Complex Physiologic Signals” [11]. In the first experiment the retention ratio σ varies in the proposed method in order to be equal to the retention ratio obtained by the Rajoub method for each signal. In the second experiment the retention ratio is fixed in σ = 4. In the method proposed by Rajoub, it was used the BiorSpline (bior4.4) wavelet and the resolution level of decomposition considered is η = 5. The choice of the significant coefficients is done by analyzing the EPE (Energy Packing Efficiency). The EPE is a measure of the preserved energy in a certain subspace after thresholding the coefficients of the subspace. For example, EPEA5 is the EPE of the scaling subspace of level 5, and EPED5 is the EPE of the level 5 wavelet subspace. The experiments were conducted with EPEA5 = 100%, EPED5 = 99.5% and EPED4−D1 = 99.5%. All the coefficients in the scaling subspace in the Rajoub method are significant. The method proposed in this paper considered the resolution level of decomposition η = 6, the order of the scaling filter m = 10, the number of bits of quantization q = 11, each scaling parameter is encoded using 11 bits, the number b of bits that composes each symbol in the output of the LZW algorithm is encoded using 4 bits and the value cmin of the minimum retained coefficient is encoded using 11 bits. Table 1 shows a comparison of both methods by analyzing the distortion obtained for each method. The column “ECG” contains the name used in the Arrythmia database [11] of the ECG signals studied and the column “σ” contains the retention ratio considered for each signal. The Table 2 shows the same comparison when keeping the retention ratio σ = 4 for both methods. Figure 1 shows a comparison of both methods by analyzing the compression ratio obtained, using the same data considered in Table 1, and Figure 2 shows the comparison of the compression ratio obtained keeping the retention ratio fixed to σ = 4. Table 1: PRD resulting from the proposed method and from Rajoub using ECG signals from the Arrythmia database. ECG 104 0 107 0 111 0 112 0 115 0 116 0 117 0 118 0 119 0 201 0
PRD Rajoub 3.60 2.82 3.88 4.47 5.31 5.52 4.00 5.09 3.47 5.05
PRD 2.50 1.43 3.16 3.39 5.00 5.13 3.64 2.71 2.49 3.40
σ 4 5 3 5 13 11 5 5 8 5
Note that the distortion of both methods are similar. However, the compression ratio obtained by applying the proposed method are significatively higher than the compression ratio obtained by the method proposed by Rajoub for
Table 2: PRD resulting from the proposed method and from Rajoub using ECG signals from the Arrythmia database, keeping the retention ratio fixed to σ = 4. ECG 104 0 107 0 111 0 112 0 115 0 116 0 117 0 118 0 119 0 201 0
PRD Rajoub 3.61 1.40 4.44 2.59 1.48 1.62 2.59 2.00 1.55 2.69
PRD 2.80 1.13 3.65 2.78 1.62 1.31 2.74 2.19 1.34 2.84
14
12
Proposed Method
5. NUMERICAL EXPERIMENTS
10
8
6
4
2
0
0
2
4
6
8
Rajoub
10
12
14
Figure 1: Compression ratios from the proposed method and from Rajoub.
all the cases studied.
6.
CONCLUSIONS
A technique to compress electrocardiogram signals has been proposed in this paper. This technique consists of finding a specialized wavelet for each signal to be compressed in a way that the distortion of the resulting signal is minimized. Several coding methods were exhaustively analyzed and the methods that presented the best results are chosen to encode the bitmap and the significant coefficients of projection of the signal in the wavelet subspaces. Numerical experiments were conducted in order to compare the proposed method with the one proposed by Rajoub [19]. The experiments have shown that the proposed method results in higher compression ratios both for a variable retention ratio, as suggested by Rajoub, and for a fixed retention ratio, as suggested in the present paper.
6
Proposed Method
5
4
3
2
1
0
0
1
2
3
Rajoub
4
5
6
Figure 2: Compression ratios from the proposed method and from Rajoub, keeping the retention ratio fixed to σ = 4.
Acknowledgments This work was supported by CNPq, CAPES, FAPESP and INATEL.
7. ADDITIONAL AUTHORS Pedro L. D. Peres (email:
[email protected]).
8. REFERENCES [1] C. M. Agulhari, R. M. R. Silveira, and I. S. Bonatti. Lossless compression applied to sequences of bits. Technical report, Unicamp, Brazil, http://www.dt.fee.unicamp.br/˜ ivanil/lossless bitmap agulhari 2007.pdf, 2007. [2] C. M. Agulhari, R. M. R. Silveira, and I. S. Bonatti. Lossless compression applied to wavelet coefficients. Technical report, Unicamp, Brazil, http://www.dt.fee.unicamp.br/˜ ivanil/lossless significant coefficients agulhari 2007.pdf, 2007. [3] A. Alshamali and A. S. Al-Fahoum. Comments on “An efficient coding algorithm for the compression of ECG signals using the wavelet transform”. IEEE Transactions on Biomedical Engineering, 50(8):1034 – 1037, Aug. 2003. [4] R. Besar, C. Eswaran, S. Sarib, and R. Simpson. On the choice of the wavelets for ECG data compression. In Proceedings of Acoustics, Speech, and Signal Processing ICASSP ’00, volume 6, pages 3614 – 3617, June 2000. [5] B. Bradie. Wavelet packet-based compression of single lead ECG. IEEE Transactions on Biomedical Engineering, 43(5):493 – 501, May 1996. [6] S. D. Bradley. Optmizing a scheme for run length encoding. Proceedings of the IEEE, 57(1), Jan 1969. [7] J. R. Buck, M. M. Daniel, and A. C. Singer. Computer Explorations in Signals and Systems Using MATLABr . Signal Processing. Prentice Hall, second edition, 2002.
[8] C. S. Burrus, R. A. Gopinath, and H. Guo. Introduction to Wavelets and Wavelet Transforms - A Primer. Prentice Hall, 1st. edition, 1998. [9] J. Chen and S. Itoh. A wavelet transform-based ECG compression method guaranteeing desired signal quality. IEEE Transactions on Biomedical Engineering, 45(12):1414 – 1419, Dec. 1998. [10] I. Daubechies. Ten Lectures on Wavelets. Society for Industrial amd Applied Mathematics, 8th. edition, 1992. [11] A. L. Goldberger, L. A. N. Amaral, L. Glass, J. M. Hausdorff, P. C. Ivanov, R. G. Mark, J. E. Mietus, G. B. Moody, C.-K. Peng, and H. E. Stanley. PhysioBank, PhysioToolkit, and PhysioNet: Components of a new research resource for complex physiologic signals. Circulation, 101(23):215–220, June 2000. [12] S. Golomb. Run-length encoding. IEEE Transactions on Information Theory, IT-12:399 – 401, 1966. [13] Y. Hao and P. Marziliano. An efficient wavelet-based pattern matching scheme for ecg data compression. 2004 IEEE International Workshop on Biomedical Circuits and Systems, pages S2/4 – S5–8, 2004. [14] M. L. Hilton. Wavelet and wavelet packet compression of electrocardiograms. IEEE Transactions on Biomedical Engineering, 44(5):394 – 402, May 1997. [15] D. A. Huffman. A method for the construction of minimum-redundancy codes. Proc. IRE, 40:1098–1101, 1952. [16] S. M. S. Jalaleddine, C. G. Hutchens, R. D. Strattan, and W. A. Coberly. ECG data compression techniques - a unified approach. IEEE Transactions on Biomedical Engineering, 37:329 – 343, April 1990. [17] Z. Lu, D. Y. Kim, and W. A. Pearlman. Wavelet compression of ECG signals by the set partitioning in hierarchical trees algorithm. IEEE Transactions on Biomedical Engineering, 47(7):849 – 856, July 2000. [18] S. G. Miaou, H. L. Yen, and C. L. Lin. Wavelet-based ECG compression using dynamic vector quantization with tree codevectors in single codebook. IEEE Transactions on Biomedical Engineering, 49(7):671 – 680, July 2002. [19] B. A. Rajoub. An efficient coding algorithm for the compression of ECG signals using the wavelet transform. IEEE Transactions on Biomedical Engineering, 49(4):355 – 362, April 2002. [20] A. G. Ramakrishnan and S. Saha. ECG coding by wavelet-based linear prediction. IEEE Transactions on Biomedical Engineering, 44(12):1253 – 1261, Dec. 1997. [21] R. M. R. Silveira, C. M. Agulhari, I. S. Bonatti, and P. L. D. Peres. Compress˜ ao de sinais de eletrocardiogramas com wavelets determinadas por otimiza¸c˜ ao gen´etica. Simp´ osio Brasileiro de Telecomunica¸c˜ oes - SBrT 2007, 2007. [22] J. A. Storer. Data compression: methods and theory. Computer Science Press, Inc., New York, NY, USA, 1988. [23] T. A. Welch. A technique for high-performance data compression. Computer, 17(6):8 – 19, Jun 1984.