Real Time Detection of R–Peak in QRS Complex of ECG Using Microcontroller

Received Jul 27, 2017 Revised Aug 17, 2017 Accepted Dec 21, 2017 Real-time detection of R peaks in QRS complex of ECG signal is the first step in the processing of ECG waveform. Based on this, various other ECG parameters can be extracted. These parameters provide substantial information about various heart diseases. In this paper, we are proposing a method to detect R–peaks of ECG signal dynamically. The most prominent role in the R–peak detector is executed by the microcontroller. This method originates by acquiring signal from the subject and necessary pre-processing is carried out on the signal in order to achieve the denoised signal. Subsequently, this filtered signal is handed over to microcontroller where a pulse is generated for each R–peak that is found in the QRS complex of ECG signal. The microcontroller is embedded with a signal processing algorithm. The algorithm used to determine the R–peaks is double differentiation method which is straightforward and robust.


INTRODUCTION
The electrical conductivity of heart is nothing but ECG which can be acquired by placing the electrodes in a specific configuration on the surface of the skin. ECG signal gives the vital information about the functionality of heart. R wave has its own significance in the QRS complex. By detecting R peaks, the first crucial step is finished in analyzing the ECG. The other features are obtained with reference to R-wave. The acquired ECG signal on the skin surface is poor in amplitude which is around 0.05mv to 3 mV and the frequency range of the ECG signal is 0.01 to 300 Hz [1]. In consideration of the weak and noisy ECG signal, it has to be boosted without amplifying the noise. Hence, we have used low pass, high pass and notch filters. Subsequently, peaks of the ECG signal are to be detected dynamically, using a microcontroller.
Many methods such as Derivative approach, Wavelet approach, neural network approach, Hilbert transform approach are available in the literature [2] for detection of QRS complex. All of these algorithms are highly sensitive to noise. Moreover, these algorithms are complex, time-consuming and are difficult to implement dynamically on the microcontroller [3][4][5][6][7][8][9][10].
In this paper, we have proposed an algorithm based on Double differentiation approach. In this process, analogue ECG signal is given to ADC channel of microcontroller where the signal is sampled. This signal is nothing nut the discrete signal. Later, first and second differentiation procedures are performed on the discrete signal. Next, summing and scaling of the derivatives are carried out for the discrete signals. Next, the obtained values are compared with a threshold, i.e. obtained during the initial phases of processing. This threshold value is dynamically derived, as the signal characteristics vary from subject to subject. This process provides an output on the I/O pin of a microcontroller as and when the R-wave appears in the ECG signal.

DESIGN AND METHODOLOGY 2.1. Design
In this proposed work, we have designed an ECG amplifier for acquiring and pre-processing the signal. The block diagram of ECG amplifier is shown in Figure 1.
In Figure 1, it is observed that the ECG signal is acquired from the subject's body by connecting electrodes in lead II configuration. The acquired signal from the subject is very low in amplitude which is around 0.05 to 5mV and easily distorted by movement artefacts and other noise sources like power lines. In this procedure, retaining the signal without distortion is important. In consequence, the signal is amplified by the instrumentation amplifier whose gain is large enough to amplify the signal. This signal is then passed through high pass filter with a cut-off frequency of 0.5 Hz to remove the noise caused by electrode half-cell potential variations.
Subsequently, the signal is passed through notch filter to remove the mains noise whose frequency is 50Hz. Once again, the signal is passed through low pass filter with a cut-off frequency of 1 KHz to remove redundant high frequency components that are present in the signal. Finally, the denoised signal is obtained. Considering that, we are feeding the ECG signal to ADC channel of the microcontroller. The input must be within the ADC limits and it should be unipolar in nature. Here, an amplifier is used to raise the signal amplitude so that the signal amplitude is within±2.5 V. Then the signal is fed through a level shifter, so that the signal is within 0-5V range. The output of the ECG amplifier can be seen in Figure 2. with necessary signal processing techniques, a pulse is generated at each R-peak in QRS complex of ECG signal which is shown in Figure 3.

Methodology
In Biomedical signal processing text book [11], the author proposed a method on double differentiation. We have modified that algorithm in order to perform a dynamic operation on the discrete form of ECG signal. The proposed algorithm is simple to implement. This process involves three stages which are explained in further sections.

Shifting and Smoothing of the data:
For every 2ms, interrupt is generated from the built-in timer to receive the sample from ADC channel which is stored in X [0]. In the process of shifting of data, we have collected five samples from ADC channel. Though we have used filters in the hardware section, because of differentiation, high frequency noise gets amplified. Consequently, to reduce that noise, a 5-point averaging method is used.

Differentiation:
After acquiring 5 samples, first differentiation Y0 and second differentiation Y1 are carried by using the equations (1) and (2). (1) These differentiated outputs Y0[0] and Y1[0] are undergoing for further smoothing by using the equations (3) and (4) which are stored in Ys0 and Ys1 respectively. Summing and scaling of first and second smoothed derivatives Ys0 and Ys1 are calculated by using the equation (5) and is stored in YT.

Detecting R-peaks in QRS complex:
For detecting R-peak, we need to find the threshold value Yth which is calculated as the 80% of the maximum peak Yp.
The physiological signals are not having same amplitude for all subjects. These vary from person to person in nature. In order to obtain the peak value, we have to adopt a new technique. Initially, when the signal is interfaced to the microcontroller, the first five records are used to obtain the peak value. This peak value Yp is subsequently used for obtaining the threshold value.
For any point, YT [i] that exceeds or equals threshold value Yth is compared.
Subsequently, if eight succeeding values are greater than or equal to the threshold Yth, then the segment might be thought of containing part of QRS complex. Correspondingly, a pulse is generated at the digital output pin of the microcontroller. This method is simple and straightforward to implement when compared with the other algorithms and produces a pulse that is proportional to every R-peak of QRS complex.

RESULTS AND ANALYSIS
We have tested our device on different subjects, using Storage oscilloscope. Here one channel is connected to ECG amplifier and another channel is connected to R-peak detector. Therefore, one can witness ECG and detected R-peaks simultaneously. By using this algorithm, we have detected pulse for every Rpeak of QRS complex [12][13].
Below, we are illustrating ECG signals along with their detected peaks which are generated accurately. In Figure 4, the R-R distance of subject 1 is 0.7 sec. The distance between the corresponding pulses is also 0.7 sec.  From Figure 6, the R-R distance of subject 3 ECG is 0.75 sec and the measured distance between the corresponding pulses is also same which is 0.75 sec. Since the derivative of the signal is calculated as the rate of change of signal, sometimes it may give rise to two peaks which are close to each other. The second pulse can be rejected in the algorithm.