A Real-time QRS Detector Based on Low-pass Differentiator and Hilbert Transform

. Electrocardiogram(ECG) is an important physiological signal of the human body. It is widely used in identification and arrhythmia detection. The first step of ECG application is signal segmentation, that is, the QRS detection. An effective and real-time QRS detection algorithm is proposed in this paper. A differentiator with adjustable center frequency is used to capture the first derivative information of the frequency band of the electrocardiogram. Then Hilbert transform is used to generate the envelope of the first derivative. After that, a dual threshold method is introduced to decrease FP and FN. Finally, a more precise R wave position is determined based on derivative method. The detector is validated on MIT-BIH arrhythmia database. The result show that the proposed algorithm has a high Sensitivity of 99.87%, Specificity of 99.84%, and the detection error rate is 0.28%. The average execution time of a 30 minutes record is 2.45s.


Introduction
Many methods have been utilized in QRS detection.The most common methods are based on wavelet transform(WT) [1] , the derivative [2] , empirical mode decomposition(EMD) [3] , mathematical morphology [4] and Artificial Neural Networks(ANN).In [5] , many algorithms for detecting important ECG waveform have been reviewed and compared.The overview is focused on the description of the principles.Algorithmic details can be found in the original papers that are referenced at the end of this article.Most WT-based methods use a quadratic spline as prototype wavelet.First, algorithme à trous algorithm is used to decompose the signal into several scales.QRS complexes are detected using an algorithm based on the multiscale approach.This algorithm searches across the scales for "maximum modulus lines" exceeding some thresholds at scales [1] .After rejecting all isolated and redundant maximum lines, the zero crossing of the WT at scale between a positive maximum-negative minimum pair is marked as a QRS.Because of the use of multiple scale signals, the algorithm is time-consuming and complex.Derivative based method is mainly introduced by [2] and [6] .The preprocessing steps are bandpass filter and differentiation, then the signal is squared and finally a moving window integration is applied.In [7] , several important first-derivative based QRS detection algorithms are compared, including traditional first-derivative based squaring function (Hamilton-Tompkins) and Hilbert transform-based methods for QRS detection and their modifications with improved detection thresholds.EMD method [8] needs to decompose the signal as well as the wavelet.When signals are decomposed into IMF components, they usually need to be screened many times and spend a lot of time.Therefore, when the data volume is large, the realtime performance of the algorithm decreases.Mathematical morphology is often used to eliminate baseline drift and separate R wave from P and T.An adaptive structuring element is employed instead of the fixed structure [4] .The structuring element is updated based on the characteristics of the previously detected QRS complexes.The more the structuring element resembles the QRS complex in the ECG, the more accurate the feature signal.Hence, the length and scale of the structuring element has drastic effects on the feature signal.It's troublesome to select appropriate structuring element.ANN needs training for a period at the beginning of a signal.So, this method is more suitable to peopleoriented, and the generalization ability is weak.Moreover, sometimes the shape of QRS varies greatly with time.Hence, this method cannot achieve satisfactory results.
Although WT and EMD can achieve high accuracy, the algorithms are complex and time consuming.Derivative-based methods are often used in real-time analysis or for large datasets since they do not require extensive computations [7] .But it's prone to be suffered from noisy signals, electrode artifacts and baseline drift.Hence, a reliable and cost-effective QRS detector is intensely demanded.

Low pass filter
We choose the FIR linear low pass filter to reduce the high-frequency noise.Typical frequency components of a QRS complex range from about 10 Hz to about 25 Hz [9] .Accordingly, we designed a filter with cut-off frequency at 25Hz.The reason for selecting linear filter is to avoid phase distortion, thus influence the location of feature points.

Low pass differentiator with adjustable center frequency
Although most high frequency noise is eliminated by the first step, some QRS-like artifacts (e.g.muscle noise) are remaining.Large amplitude P and T wave which have obvious large slope may cause false positive detection(FP).Hence, a narrowband low pass differentiator is required to further enhance the R peak.
Many specialized articles have studied the design of low pass differential.Authors in [10] , [11] introduced a design method of linear phase FIR band-pass maximally flat digital differentiator with an arbitrary center frequency.But the transfer function for both of TYPE Ⅲ and TYPE Ⅳ is achieved through complex Jacobi polynomial.It's hard to get the filter coefficients, so that it can't calculate in real time.In [12] , a novel approach to designing approximately linear phase infinite-impulseresponse (IIR) digital filters in the passband region is introduced.The proposed approach yields digital IIR filters whose numerators represent linear phase finiteimpulse-response (FIR) filters.However, the cut-off frequency is unable to be accurately controlled.This IIR differentiator is adopted in [13] .Based on the above considerations, we finally chose the method in [14] .
The frequency response of an ideal DD is (1).Equation ( 2) represents an approximation of () H is maximally linear at the spot frequencies ω=π/p [14] .In (2), n must be an even and , where N is the order of the FIR differentiator.A complex formula for calculating coefficients i d in an iterative way is given in [14] .However, we adopt another simple way introduced by [15] to compute the coefficients effectively.More details about the formula and its proof can be found in [15] .For convenience, we choose integer p to be an even.From (2), it is easy to derive the filter coefficients of the FIR differentiator through the Z transform.
The sampling frequency of the records is 360 Hz in MIT-BIH arrhythmia database.The energy of the R peak in QRS wave is concentrated around 8~16 Hz.According to this, we choose p=14.With the increase of n, the frequency response curve is flatter at the vicinity of the center frequency ω=π/p and has a better approximation to ideal difference.However, the larger the value of n, the higher the order of the differentiator, the heavier the computational burden.In this paper, n=4 is adopted.Of course, you can try other n values, but you need to compromise between computation time and accuracy.Note that the difference produces a fixed group delay 2 np .The approximation and the idea difference are shown in Fig. 2.

Hilbert transform
Through low pass filtering and difference, the R wave usually generates two wave peaks.However, R waves always have many forms, including positive, negative, bidirectional, RS ' R , fragmented QRS (f-QRS) and so on.Hence, more than two peaks will be produced by one QRS wave and we need to use envelope to combine several adjacent peaks into an event and smooth the ripples.
Hilbert transform usually has two applications: one is to produce 90 degree of phase shift, the other is to generate the envelope of signal.In [16] , the first application has been used to detect QRS.We now use the second.Given a real time function () xt , its Hilbert transform is defined as [16] 1 1 ( ) [ ( )] ( ) It can be seen from ( 3) that the independent variable is not changed as result of this transformation, so the output () xt is also a time dependent function.Applying the Fourier transform, we have Where sgn f = +1 for f >0 and -1 for f <0.In the frequency domain, the result is then obtained by multiplying the spectrum of the () + ) for negative frequencies andj ( 。 -90 ) for positive frequencies [16] .The envelope of the signal () After differentiation, the signal is passed through a non-linear transformation to obtain positive peaks regardless of polarity of QRS complexes.The main objective of transformation is to use single-sided threshold mechanism and to enhance the QRS complexes [17]   .Most papers adopt squaring function to further attenuate other ECG features, leaving the QRS complexes as outstanding positive peaks in the signal, just like what is mentioned in [2] , [6] .The major disadvantage of this approach is that by squaring the differentiated ECG, normal QRS peaks with small magnitude and wide arrhythmic peaks with decreased slope are reduced in the output of the transform [7] .In [17] , four non-linear transformations are compared, including the absolute value, energy value, Shannon entropy value, and Shannon energy value.Another transform function arctan is introduced by [18] and [19] .Let dECG denote the signal after difference.In this paper we choose arctan as the nonlinear transformation, which is calculated as ( ) This transform makes the difference signal to have non-linear characteristics.The values of ynare limited to constant range from 0 to π/2, even though the first differences of ECG signals have different amplitude according the record.The () yn is not sensitive to changes in morphology and amplitude of the QRS complex [19] .
Let () ŷndenotes the Hilbert transform of () yn.Then the feature signal is expressed in (7).

QRS events detection
This process is performed on feature signal.Considering the algorithm that needs to be real time, we process the signal frame by frame.In this paper, we choose 5 seconds as the length of frame.The length of the moving window is 5 seconds that permits to compare every QRS to its neighbors and extract the majority of these complex.In addition, this length doesn't allow to have a large difference between the largest and smallest QRS in this window due to the behavior of the ECG signal, which changes gradually [20] .Unlike most papers, such as [1] , [21] , where they use a single value as the local threshold in each moving window, we here adopt dual adaptive threshold algorithm introduced by [22] .In adaptive threshold algorithm, a pair of thresholds named as up-limited threshold (ULT) and down-limited threshold (DLT) are set at the beginning of detection.If the detecting results using ULT and DLT are not the same value, there must be some missing or fault detection.In this case, the value of ULT must be reduced and the value of DLT must be increased [22] .In each moving window, ULT and DLT are defined as Where α and β are factor coefficients, and the range of the value is (0,1).Therefore, the values of ULT and DLT must be changed according to their weights and the differences in the last calculation process [22] : After QRS events are determined on z(n), we need to give a more precise location of R wave.This process is performed on y(n).When each QRS event is detected, we take the final d TH value as the initial threshold and reduce this threshold until least two peaks are detected corresponding to the QRS event on y(n).Then we take the minimum between these two peaks as the R peak position.

Result and discussion
The process of the whole algorithm is shown in Fig. 3.A wider scope of signal segment taken from record 105 is shown in Fig. 4.  We use MIT-BIH arrhythmia database to validate the proposed algorithm.The database can be obtained from [23]   .The MIT-BIH Arrhythmia Database contains 48 halfhour excerpts of two-channel ambulatory ECG recordings, obtained from 47 subjects studied by the BIH Arrhythmia Laboratory between 1975 and 1979.The database was the first generally available set of standard test material for evaluation of arrhythmia detectors and has been used for that purpose as well as for basic research into cardiac dynamics at more than 500 sites worldwide.The recordings were digitized at 360 samples per second per channel with 11-bit resolution over a 10-mV range.Two or more cardiologists independently annotated each record.Much more information about this database may be found in [24] .
To evaluate the performance of the proposed detection, the sensitivity (Se), the positive predictivity (+P), and the detection error rate (DER) can be computed by using the following equations, respectively In the upper form, TP represents the number of real R waves detected, FN indicates the number of missing R waves, and FP indicates the number of spikes that are erroneously regarded as R waves.The detection results of all 48 records on Lead I are shown at Table I.In this paper, we use α =0.6, β=0.2 and u w = d w =0.1.
These parameters are determined by experiments, not necessarily the optimum.In addition to the aforementioned fundamentals of the algorithm, the refractory period and search back mechanism are also introduced to reduce FP and FN respectively.More details about refractory period and search back can be found in [2] and [6] .
From Table II, we can see that the proposed QRS detection algorithm has a comparable performance with mature methods.However, our method only need to be performed on the first derivative of signal and its envelope.It has great advantages in terms of algorithm complexity and computation compared with waveletbased methods.
The proposed algorithm was implemented on a 1.80-GHz Intel Core i5-3337U CPU using MATLAB version R2015b.The average processing time required for performing our method on each 30 min ECG data in the MIT-BIH database is approximately 2.45 s.
In [25] , authors present an effective R-wave detection method based on digital differentiation and integration of fractional order.The pre-processing step is based on a fractional order digital band-pass filter followed by a five points differentiator of fractional order 1.5.The detection step is a new and simple strategy which is also based on fractional order operators for the localization of the R waves.This algorithm was implemented on a 3.06-GHz Pentium IV PC using MATLAB version 6.1.The average time required for performing the algorithm on each ECG record in the database is about 7 s.Compared to our method, it has a bad real-time property.

Conclusion
This paper proposed an effective and real-time QRS detection algorithm.The algorithm used a differentiator with adjustable center frequency to capture the first derivative information of the frequency band of the electrocardiogram.Then it used Hilbert transform to generate the envelope of the first derivative.After that, we introduced a dual threshold method to decrease FP and FN.The detector is validated on MIT-BIH arrhythmia database.The result show that the proposed algorithm has a high Sensitivity of 99.87%, Specificity of 99.84%, and the detection error rate is 0.28%.The average execution time of a 30 minutes record is 2.45s.

Figure 1 .
Figure 1.The frame of the QRS detection.

Figure 2 .
Figure 2. The approximation and the idea difference curves

N
is not equal to d N , there must be some missing or fault detection.

TH
are the missing and fault thresholds in the last calculation, u w and d w are weight factors of missing and fault detection.(10) ~ (12) are iterative updated until u N is equal to d N .MATEC Web of Conferences 175, (2018) https://doi.org/10.1051/matecconf/2018175IFCAE-IOT 2018 02008 02008

Figure 3 .
Figure 3. From top to bottom, each subgraph is :(a) origin signal (b) signal after low pass filter (c) signal through difference and non-linear transformation arctan (d)envelope

Figure 4 .
Figure 4.A segment from record 105 and the performance of proposed algorithm.The red 'O' represents the R position.
includes low pass filter, low pass differential and rectification and Hilbert transform, and finally generates feature signals.Then QRS detection is performed on feature signals.Several adaptive time and amplitude thresholds are employed on this process.The overview of the whole algorithm is shown in Fig.1.

Table . 1
Performance evaluation of the detection method

Table . 2
Effectiveness of heartbeat segmentation methods