Design and Implementation of Wearable Dynamic Electrocardiograph Real-Time Monitoring Terminal

In order to detect Electrocardiograph (E.C.G.) signals in people’s daily life accurately, in this study, a wearable real-time dynamic E.C.G. signal detection system based on the Internet of things technology was designed and implemented. Under the STM32 WeChat processor, a flexible fabric was used as the base of the sensor. It can process the collected E.C.G. signal through amplification and filtering of signal conditioning module, so as to satisfy the conversion of A/D. The E.C.G. signal acquisition front end and other hardware and software were designed based on AD8232 chip. And then an adaptive filter was designed based on standardized LMS algorithm (N.L.M.S.). E.C.G. signal in MIT-BIH database was used to detect the accuracy of R wave detection. In order to detect the restraining effect of baseline drift and motion artifact in E.C.G. after filtering, the accuracy of R wave detection in different movements of healthy personnel was tested. The results showed that after using the N.L.M.S. algorithm’s adaptive filter to detect E.C.G. signals in MIT-BIH database, the accuracy (De%), sensitivity (Se%), and specificity (Sp%) calculated by the R-wave were all above 99%. It was then worn on the experimenter’s chest and the E.C.G. signals were detected while experimenters sat still. It is found that it can restrain baseline drift in E.C.G. signal acquisition. In addition, when the experimenter did static standing, walking slowly, squatting and chest expansion, the detection rate of R wave was above 95%. Therefore, the designed system can monitor E.C.G. signals quickly and accurately.


I. INTRODUCTION
Cardiovascular diseases are common diseases of the blood circulation system, with high mortality. With the rapid development of electronic information media and Internet of things technology, the world has entered the information age. The emergence of mobile medicine shows that it is possible to use personal wireless LAN to realize telemedicine in mobile state [1]. At the same time, the research and application of wearable computing devices have become a hot topic.
The most typical application of wearable computing is health and medical monitoring and daily movement monitoring of the elderly, which is a more miniaturized and more user-friendly technology for monitoring. The The associate editor coordinating the review of this manuscript and approving it for publication was Mu-Yen Chen . wearable medical monitoring system integrates the required ultra-micro electronic components, fabrics, and advanced technologies, which can help users monitor their own health or patients' health in real time. The physiological information obtained can also facilitate subsequent doctors' diagnosis, saving diagnosis time and medical cost. With the continuous development of technology, the research and application of wearable devices will become more mature and extensive. By combining sensors in monitoring devices with clothes, chest belts or belts, people can detect various physiological or sports information in the body, and then use wired or wireless communication devices to transmit the information to PC or mobile devices for easy extraction. However, fabric sensors are affected by the environment, and the detection of E.C.G. signals by fabric sensors is affected by motion artifacts and power frequency signals when power is VOLUME 8, 2020 This work is licensed under a Creative Commons Attribution 4.0 License. For more information, see http://creativecommons.org/licenses/by/4.0/ supplied [2]. Therefore, it is very meaningful to suppress the influence of motion artifact in wearable E.C.G. monitoring system. G. signal detection system to simulate the front end of R peak prediction by using an adaptive filter based on N.L.M.S. algorithm. The results showed that the error of detecting heart rate variability was 0.5-4 times /min, and the noise tolerance was greatly reduced, saving 62% of power consumption [16]. By comparing studies at home and abroad, it can be found that the addition of adaptive filter to the wearable E.C.G. signal monitoring system can effectively remove part of the influence of noise and artifact. But there has been relatively little research into its use in wearable real-time E.C.G. signals. Therefore, this study aims to design a wearable E.C.G. signal monitoring system through the fabric electrode, which can monitor the user's E.C.G. signals in real time. At the same time, an adaptive filter based on N.L.M.S. algorithm is designed to filter baseline drift in E.C.G. signal acquisition process and filter motion artifact interference caused by movement. Later, E.C.G. signal data in mit-bih database were used to detect and calculate the accuracy of r-r interphase wave detection, and monitor the monitoring accuracy of R wave in different motion states of the experimental subjects, so as to verify the accuracy and feasibility of the wearable E.C.G. monitoring system designed in this study.

III. PROPOSED METHOD
A. FRAMEWORK DESIDN OF WEARABLE DYNAMIC E.C.G.

MONITORING SYSTEM
The design of wearable E.C.G. monitoring system based on triple lead includes hardware part and software part. Among them, the hardware part is used to build a platform for collecting, processing, and transmitting the dynamic E.C.G. signals of users, so as to provide data support for subsequent processing of E.C.G. signal data and diagnosis of diseases. The overall framework of wearable E.C.G. monitoring system includes six parts. First, mobile terminals, including mobile phones and tablets. Second, the PC part, including data storage and processing. Third, the computing processing unit, including a microprocessor and a time control system. Fourth, the power supply, which can ensure the whole system has a stable voltage. Fifth, the acquisition unit, which is mainly responsible for the collection of E.C.G. signals. Sixth, fabric electrode, which can be worn on the chest of the user. The preconditioning circuit amplifies the collected E.C.G. signals and then performs filtering and conditioning. The processed E.C.G. signals are converted and stored by the acquisition unit for A/D, and the acquired E.C.G. data are transmitted to the mobile terminal and PC by the wireless transmission module, which is ultimately used for real-time display of E.C.G. waves and data de-noising analysis. On this basis, in addition to ensuring the perfection of functions, the accuracy of the detected signal R wave should be more than 90% (excluding motion artifact). The overall framework of E.C.G. monitoring system is shown in Fig. 1  The technical indexes of terminal hardware of the threelead real-time monitoring device for dynamic E.C.G. include: the standard 3 lead is used for synchronous E.C.G. signal acquisition with a collection time of 24h; A/D whose conversion bit is 24 bit; the sampling rate was 250 Hz; the dynamic range of input is ±6 mV and the dc polarization voltage of ±300 mV needs to be superimposed; the input impedance should be more than 10 M ; the common mode suppression shall be no less than 80dB; the gain accuracy requires error should be no more than 10%; the system noise should be no more than 50 micron vp-v; the multi-channel crosstalk shall be no more than 0.2m vp-v; the response range of frequency is 0.67-40 Hz; the smallest signal that can be picked up is 50 microns; the data storage is equipped with a standard external 32G Micro SD card; the bluetooth 4.0 is used for data transmission; the removable rechargeable lithium battery is chosen, 1800mAh, with a sustainable life of more than 24h; when bluetooth is in working state, the total power of the terminal's hardware is about 70mA, and when bluetooth is in standby state, the power is about 40mA.

B. HARDWARE DESIGN OF E.C.G. SIGNAL AQUISITION
Since the collected dynamic E.C.G. signals are weak current signals, it is necessary to amplify the E.C.G. signals. To avoid amplifying the electrocardiogram signal as well as the noise signal, the acquired E.C.G. signal should be filtered and adjusted before A/D conversion. Generally, the electrocardiogram signal collected by human body is about 1mV, and the collected electrocardiogram signal frequency is within 0.1-100Hz, which is vulnerable to interference from high and low frequency electromyography signals and power supply signals. In order to meet the basic input voltage of the subsequent A/D conversion and ensure the purity of the signal, in this study, the two-stage signal amplification was adopted and an analog conversion circuit with filtering and notch circuit was designed to simulate signals with high Signal to Noise Ratio (SNR). The overall framework of signal processing circuit is shown in Fig. 2.
The input energy consumption of the multi-frequency lowamplitude E.C.G. signal is low, and the input impedance in the preamplifier circuit needs to be increased (>2M ). In addition, it is necessary to have a higher common mode rejection ratio of interference noise, which will inhibit more power frequency interference and some other infections caused by physiological effects, and the amplified signal components will be correspondingly improved. In this design, AD8232 chip is used as the front end of E.C.G. signal acquisition, and its power is 3.3v. AD8232 can produce A weak E.C.G. signal in motion with A common-mode rejection ratio of 80dB and A low-power current of 170 µA. The signals of the left and right electrodes and reference electrodes are input to AD8232, and then output through the second-order highpass filtering circuit to the low-pass filtering circuit.
The E.C.G. signal is weak and easily disturbed by ambient noise. AD8232 amplifying circuit consists of two parts: the power supply filtering circuit and the circuit for filtering and amplifying the collected E.C.G. signals. When the power supply is filtered, it consists of two resistors and a transformer. When further filtering is carried out, a low-pass filter composed of a resistor and a transformer is added. The amplification of the E.C.G. signal is determined by the size of the resistor. The resistances used in this design were 1 M and 4.3 K respectively, so the maximum multiple that can amplify the E.C.G. signal can be obtained as follows: In (1), y represents the signal amplification factor, and R represents the resistance in the circuit.The maximum heart rate after vigorous exercise is 200 beats/min, which is similar to 3.3 Hz. In order to detect the signal, the following (2) was used to calculate the cut-off frequency of the filter in this study, and the optimal filter frequency was about 3.4H.
In order to ensure the accuracy and rapidity of signal acquisition, a three-axis accelerometer ADXL345 with micro-power consumption was adopted based on STM32 microprocessing chip in this study. Moreover, STM32 microprocessing chip is characterized by low energy consumption, small size, and stable system, and it is equipped with SPI, USB, and other interfaces. ADXL345 contains SPI bus with data input signal line, output line number line, enabling signal, and serial shift clock. The computing processing unit includes five parts: storage module, processing module, manmachine interface, USB interface, and power supply module. In order to ensure the comfort of user when wearing, the chip with light weight, low consumption, high performance and large storage space and circuit are required. Its specific framework is shown in Fig. 3.

C. SOFTWARE DESIGN OF E.C.G. SIGNAK AQUISITION
In order to transmit the collected E.C.G. signal data to the mobile client and PC, the bluetooth is used as the wireless carrier of data transmission, and the bluetooth analog serial port is connected to the bluetooth adapter of mobile phone and tablet computer for communication. The wearable E.C.G. signal acquisition system transmits the collected E.C.G. signal to PC or mobile terminal via bluetooth. When the PC is paired with bluetooth and connected successfully, the PC will assign a COM port to bluetooth. When the PC opens the corresponding COM port, it can receive the data sent by the E.C.G. collection module. The data package analysis process of E.C.G. signal is shown in Fig. 4. The calculation method of E.C.G. signal needs to be defined according to the meaning of value corresponding to different CODE values. If CODE is 0x02, vLength is N/A, and value is defined as Singal quality. If 0x03, vLength is N/A, and value is defined as the real-time  heart rate. If 0x80, vLength is 2, value is defined as 16-bit raw data. The rest can be ignored.
Since the collected E.C.G. data is relatively large, it is necessary to choose SD card with large capacity and fast data reading speed to store E.C.G. signal data. The reading and writing process of SD card is shown in Fig. 5.
When the collected E.C.G. signal is finally saved, the PC side triggers a function that automatically creates a new TXT document and saves the data.

D. DESIGN OF ADAPTIVE FILTER AND ADAPTIVE FILTER ALGORITHM
The commonly used filtering methods are hardware filtering and software filtering. The former is easy to implement but not suitable for high frequency field devices. The latter is more flexible to remove interference by the algorithm, but occupies a large memory space. The signal of moving artifact belongs to unstable random signal, which has no fixed frequency range, so ordinary filtering methods can't achieve effective filtering results. The emergence of adaptive filter can effectively solve this problem. Previous studies have shown that adaptive filter can effectively remove motion artifacts. It can automatically adjust parameters to adapt to the real situation, and has been widely used in the fields of noise filtering, spectral line enhancement, and system recognition, but it needs to set the signal reference related to motion artifact. In this design, adaptive filtering technology was used to solve the problem of noise background in the process of E.C.G. signal extraction.
As shown in Fig. 6, the adaptive filter has signal source v and noise source m, whose input signals are x and r respectively. Then the system output e can be expressed as follows.
In the above equation, x is the input signal, v is the useful signal, m is the unknown noise signal, r is the reference noise signal, and y is the output signal after r is filtered through the adaptive filter. If y is very close to m, that is, y ≈ m, then e ≈ v. But v is not related to m, and v is not related to y. And m in x needs to be removed, so the output power needs to be minimized, so as to maximize the output signal of SNR and ensure the energy of v. The output power minimum value obtained is as follows. (4) After that, the standardized LMS algorithm (N.L.M.S.) is applied to remove motion artifacts. The most important thing in N.L.M.S. is the setting of step size factor µ, µ can be used to control the convergence rate of the filter and the equilibrium state between the steady-state errors, and the value of muon must be positive: In order to avoid the denominator of (5) being zero and the correction factor γ being between 0-1, the N.L.M.S. can be updated as follows.

E. DESIGN OF R WAVE DETECTION ALGORITHM
In the feature detection of E.C.G. signal, QRS wave group is the most characteristic wave in the signal, which is easy to distinguish. QRS can calculate heart rate by measuring the interval of R-R. When dynamic threshold R wave detection is carried out, an initial threshold should be set first, and then the data should be scanned backwards and the threshold should be compared. It is necessary to determine the initial threshold by taking the first 4,000 sampling points in the E.C.G. and finding the maximum value Max. The threshold is determined according to the relationship between R wave and T amplitude (R amplitude is 6 times T amplitude). The initial threshold is as follows: When the E.C.G. is larger than the threshold value, the E.C.G. maximum value is taken as the peak of the R wave. The initial threshold value and the average value of the E.C.G. maximum value are taken as the new threshold value. This method can be used to improve the accuracy of R wave detection. The accuracy of R wave (De%) can reflect the specificity of E.C.G. signal detection, and the calculation equation is as follows.
The sensitivity of R wave (Se%) can reflect the false positive (FP) probability of E.C.G. signal detection. The higher the sensitivity, the lower the missed detection rate. The equation is as follows.
The specificity of R wave (Sp%) can reflect the false negative (FN) probability of E.C.G. signal detection. The higher the specificity is, the lower the false detection rate is. The equation is as follows.

A. FABRIC ELECTRODE TEST
The contact impedance between electrode and skin is one of the important factors affecting signal quality in E.C.G. signal monitoring. Theoretically, the smaller the impedance is, the higher the performance of the electrode will be. Therefore, VOLUME 8, 2020 it is required in the research that the same tester wear the same clothes and fabric electrodes be set of different sizes to study the relationship between fabric area and contact impedance. In this study, fabric electrodes with width of 3cm but different lengths were made, and the Ag/AgCl viscous electrodes were used as the control. The results were shown in Fig. 7A. It can be seen that as the length of the fabric electrode increases, that is, the area of the fabric electrode increases, the impedance between the electrode and the skin decreases. However, the effect of fabric electrode with a length of 5cm is not significantly different from that of fabric electrode with a length of 10cm. Since the fabric electrode with a length of 10cm is not easy to be worn, and the relative displacement may occur due to the movement of the body, the fabric electrode with a length of 5cm is adopted in this study for subsequent experiments. The concrete object is shown in Fig.7B. According to the structure of the adaptive filter designed above and the selection of reference signals, the collected E.C.G. signals of users with motion artifacts were used as input source signals. The motion information acquired synchronously by the accelerometer was taken as a reference, and data processing and motion artifact removal were carried out on the PC based on N.L.M.S. algorithm. The specific framework is shown in Fig. 8. In the LMS algorithm, the step factor muon is set as 0.05, while in the N.L.M.S. algorithm, the step factor muon is time-varying, the correction factor is set as 0.1, and the number of iterations is the default value.

C. SIMULATION VERIFICATION RESULTS BASED ON MIT-BIH DATA
Quantitative evaluation of R-wave detection of E.C.G. signals by the adaptive threshold algorithm proposed in this study was carried out with E.C.G. signal data in MIT-BIH  database. As shown in Table 1, a total of 47164 E.C.G. signals of 23 types were detected in this study, the number of FP detected was 53, and the number of FN detected was 46. Fig. 9 showed that the Sp% calculated by the adaptive threshold algorithm was above 99%, while only one of De% and Se% was less than 99%, but it was 98.90% and 98.66% respectively, indicating that the computational method proposed in this study had a high accuracy.

D. ACTUAL TEST VERIFICATION RESULTS
The adaptive algorithms based on LMS and N.L.M.S. are respectively applied to the baseline drift suppression of E.C.G. signals, and the results are shown in Fig. 10. According to Fig. 10A, the original E.C.G. of the study object is interfered by baseline drift, and the amplitude of some E.C.G. signals has exceeded the average amplitude of R wave,  P wave and T wave, which will affect the accuracy of E.C.G. signal detection of R wave. It can be seen from Fig. 10B that after filtering with LMS algorithm, E.C.G. waveform has little difference from that in Fig. 10A. As shown in Fig. 10C, the N.L.M.S. algorithm can significantly suppress the interference of baseline drift in E.C.G. after filtering, and the waveform is clearer and easier to locate the R wave. The experimenter was then asked to stand quietly for 30 seconds, and after the E.C.G. signal was stable, the E.C.G. data was recorded for 5 minutes. The experimenter was asked to stand quietly for 30 seconds, and after E.C.G. signal was stable, ambulate for 5 minutes, and the E.C.G. data was recorded while the experimenter was ambulating. The experimenter was asked to stand quietly for 30 seconds. After the E.C.G. signal was stable, the squat motion was repeated for 5 minutes, and the E.C.G. data during the squat was recorded. The experimenter was asked to stand quietly for 30 seconds,  and after the E.C.G. signal was stable, the E.C.G. data was recorded by repeated chest enlargement for 5 minutes. The results are shown in 11 and Table 2.
According to Table 2, R wave has the highest detection accuracy when standing still, up to 99.49%. The accuracy of R wave detection is 98.88% when walking slowly. The accuracy of R wave detection in squatting is 98.27%. The accuracy of R wave detection during chest enlargement was 97.64%. On the whole, the detection accuracy of R wave is relatively high, which is also in line with the expected target.

V. CONCLUSION
In this study, a wearable E.C.G. signal monitoring system was built based on STM32 by taking a fabric electrode with good toughness as the sensor carrier, and a signal adjustment module including signal acquisition, amplification, and filtering was designed. After that, the acquisition module of E.C.G. data, data storage, transmission, and interface module were designed. The collected E.C.G. signal was transmitted to the client by thte Bluetooth. The effect of moving artifact baseline drift in E.C.G. signal collection is effectively reduced by using N.L.M.S. adaptive filter. After adjusting the threshold algorithm in the adaptive filter, FP and FN values of R wave detection is reduced. In addition, under different motion states of the monitored objects, the detection accuracy of R wave reaches more than 95%. With the continuous development of science and technology, wearable health monitoring system will be more portable and popular, and will develop towards a more intelligent direction. In addition to monitoring E.C.G. signals, fabric electrode sensors can also be used to monitor physiological indicators such as respiratory rate, breathing depth, temperature changes, and blood pressure, which requires more stable, powerful, and diverse filtering processors. The filter processor designed in this study can only filter the interference in the monitoring process of E.C.G. signals, which has limitations. The future medical development will be more flexible and user-friendly, and a wearable health monitoring software that can transmit data to the mobile terminal through WIFI transmission will be designed in the future, which is more user-friendly and easier to operate.