1. Introduction
According to the World Health Organization’s statistical report, the mortality rate for cardiovascular disease is significantly higher than that of any other disease globally. In 2012, this condition caused nearly 17.5 million deaths worldwide, representing approximately one-third of all fatalities. The China Cardiovascular Disease Report of 2018 reveals that regardless of whether individuals reside in urban or rural areas, they exhibit higher mortality rates related to cardiovascular disease than with other illnesses [
1]. From 1990 to 2016, two out of every five deaths among rural residents in China resulted from cardiovascular disease. In this regard, data analysis indicates a mortality rate of 309.33 per 100,000 individuals due to cardiovascular conditions in rural areas, with such deaths accounting for 45.50% of total deaths. Comparatively, the death rate attributed to cardiovascular diseases in urban areas was 265.11 per 100,000 inhabitants, accounting for 43.16% of total deaths.
Upon overall analysis of the report, it is evident that the number of individuals with cardiovascular diseases in China had reached 290 million in 2017. Moreover, cardiovascular disease accounts for more than 40% of all causes of death, highlighting the significance of detecting such conditions. Within each normal beat of the heart lies a heart rate signal representing the organs’ normal functioning. This makes detecting heart rate signals an essential tool for preventing cardiovascular diseases. Currently, the primary focus of human health platforms involves designing wearable sensors that monitor biophysical, biochemical, and environmental signals. Implantable devices are also available for monitoring neurological, cardiovascular, digestive, and motor system activities [
2]. Thus, the present research primarily emphasizes electrocardiography (ECG) as the most crucial tool for avoiding cardiovascular diseases.
ECG involves recording the electrical activity of the heart as a voltage–time graph via electrodes placed on the skin that detect myocardial depolarization during each heartbeat cycle. ECG primarily records the electrical activity of the heart and serves as a standard clinical cardiac test, providing an essential way to monitor cardiovascular disease while simultaneously examining for a variety of arrhythmias, ventricular hypertrophy, myocardial infarction, myocardial ischemia, and other abnormalities.
The heart consists of numerous cardiomyocytes, which are continuously electrically repolarized and depolarized. As the core unit of ECG, the heartbeat generates a variety of electrical stimulation pulses inside the heart that excite muscle cells in the atria and ventricles, resulting in regular diastole and contractile movements. Depolarization reflects electrical activity during contraction, whereas repolarization reveals the opposite activity. Following the beat cycle, the main elements of the heart, the atria and ventricles, undergo a contraction and diastole process that subsequently causes the heart to move. In this light, the ECG represents a voltage–time relationship of the electrical activity in the heart recorded by electrodes placed on the skin, resulting from a blend of physiological and technological processes. An electrocardiogram provides insight into the heart’s electrical activities, making it the most commonly used clinical heart test and a useful approach to monitor cardiovascular diseases while detecting any corresponding abnormal heart conditions [
3].
As times change, the scale of data continues to expand considerably. Similarly, the collection of physiological signals from individuals is increasing dramatically, making manual data processing impossible [
4]. Consequently, machine learning serves as a vital tool for data analysis. Machine learning enables the automatic extraction of data characteristics through simulating and analyzing portions of the data. It then provides a generalization model characterizing all data to facilitate processing massive datasets.
The creation process for a typical machine learning model involves collecting data to create a predictive model using training data. Some training data is filtered out and serves as verification data that is primarily used to identify the model. The accuracy of test data constitutes the prediction target. Machine learning extracts data features, enabling the model to learn from the training and the distinct features of data, subsequently predicting test data to conveniently acquire classification results. With regards to manual analysis, machine learning processes data rapidly; for instance, it takes less than 30 s to predict 10,000 heartbeat data points with a classification accuracy rate reaching up to 99%. However, training time is necessary in the early stages of testing, requiring at least 30 min to train 100,000 heartbeat data points. Therefore, machine learning proves crucial to enable efficient processing and categorization of big data compared with manual approaches. In the introduction, it is important to note that the heart rate signal, which represents the number of heartbeats per unit of time, can sometimes mistakenly be referred to as the BPM (beats per minute) signal. It is crucial to differentiate between the two to avoid any confusion or misinterpretation.
Improving the overall performance of ECG signal acquisition and analysis systems has become a critical research area in recent years. In this study, we address two core aspects to enhance the effectiveness of ECG signal analysis. Firstly, an embedded system is designed as the signal acquisition front end to improve portability. Secondly, we propose a machine-learning-based approach to tackle the problem of big data in ECG signal analysis. Specifically, we focus on the design of home-made printed circuit boards (PCBs) for ECG acquisition and the development of a reliable algorithm to analyze the acquired signals. Our ultimate goal is to create a complete system for ECG collection and AI-based analysis that allows for real-time monitoring of ECG signals outside of hospital settings [
5]. This system can accurately detect abnormal heart rates and thus provide a robust tool for real-time health monitoring (
Figure 1).
2. Materials and Methods
2.1. System Design
The ECG acquisition system is a critical component of the overall system functionality. Accurate identification of heart rate signals by signal analysis systems depends on the ability of the hardware to collect the correct signals. This, in turn, allows the machine learning model to accurately classify the data. The flow diagram of the full process is depicted in
Figure 2.
The entire system can be divided into two parts: the acquisition front end and the analog-to-digital conversion section. Raw heart rate signals are collected via commercial electrodes using a triple-lead solution and transferred via wire to the acquisition front-end section for processing. After two stages of amplification and two digital filtering processes, the ECG signal is finally transmitted through an amplifier for analog-to-digital conversion and processed through a digital filter. In the final stage, the acquisition system delivers heart rate ECG signals suitable for subsequent classification.
To address the issue of environmental noise, which can lead to amplitudes much larger than the collected ECG signal, appropriate amplifiers should be chosen based on the characteristics of the noise. Useful ECG signals typically lie between the frequencies of 0.05 Hz and 100 Hz, necessitating optimized filters for interference cancellation. Following the amplifier and filter stages, the signal requires sampling and analog-to-digital conversion. According to the Nyquist sampling theorem, the sampling frequency must be at least twice that of the original signal to ensure its integrity [
6]. A sampling frequency of 200 Hz is sufficient to prepare the signal for digital processing. However, since the spectrum of some diseases may extend as high as 500 Hz, the minimum sampling frequency during system design should be 1000 Hz. The choice of sampling frequency depends on the complexity of the analysis of the ECG signal. For remote signal monitoring, wireless communication standard modules such as Zigbee, RFID, or Wi-Fi are necessary [
7]. The collected data are then transmitted to a terminal where they are received, stored, and finally processed.
2.2. Circuit Design
Considering the fundamental requirements of the acquisition front end, selecting an appropriate front-end circuit chip is pivotal from various perspectives. To address potential external interference in distributed devices, an integrated dedicated chip for heart rate signal acquisition with built-in amplification and filtering circuits will be utilized. These components are highly integrated and resistant to external interference. Currently, the most widely used ECG signal acquisition chip on the market is the AD8232. This chip presents several advantages such as the option to choose between two- or three-lead modes for transmission.
Its signal gain (G) can reach up to 100, whereas its high-pass filter adopts a double-pole structure and has a fast recovery function, thereby reducing the long tail phenomenon caused by the high-pass filter of the two-pole structure. Additionally, the module features lead-off detection with an integrated right-leg-drive (RLD) amplifier, which improves the common-mode rejection ratio (CMRR). However, this type of structure may have insufficient accuracy and the package volume of the chip is relatively large. Integrated designs have many disadvantages compared with distributed designs, potentially amplifying the effect of external interference factors on signal collection and leading to increased noise in the final analog signal that could significantly affect subsequent signal analysis and classification [
8]. After achieving a balance between speed and performance, AD8232 was chosen as the optimal chip for this system, combining built-in primary and secondary amplification while working together with peripheral circuits to achieve both high-pass and low-pass filtering.
Upon completion of data collection, it is essential to utilize the three-lead method to increase signal strength and reduce interference from artifacts. This approach also minimizes the impact of common-mode interference on the collected heart rate signal via the RLD in AD8232, which is also utilized for driving the third electrode. During signal collection and transmission, two 180 kΩ resistors are introduced to connect to the input pin as a protective measure against faulty input signals, whereas two 10 MΩ resistors are implemented for input bias. The core task involves implementing an integrated acquisition front-end circuit design using the AD8232 chip in combination with peripheral circuits. Such an approach aims to reduce the design area and improve system portability and stability while simultaneously enhancing the quality of the collected signals, together with the post-processing accuracy and overall diagnostic system confidence. A schematic of the final circuit design is illustrated in
Figure 3.
The primary objective of the acquisition front-end circuit is to obtain as many original heart rate signals as possible. In contrast, the digital part of the circuit focuses on receiving analog signals, performing analog-to-digital conversion, and ultimately communicating with external devices via Bluetooth modules. The circuit primarily comprises the main control chip and peripheral circuits. The data transmission procedure involves a digital circuit that receives the heart rate analog signal from the acquisition front end. Subsequently, other circuits perform analog-to-digital conversion, digital filtering, and ultimately transmit the processed data through the Bluetooth module. The critical modules that require designing are the MCU (microcontroller unit) selection, peripheral circuit design, power supply module design, and Bluetooth module design. It is crucial to ensure the system’s stability and power consumption during the design process.
2.3. Circuit Realization
Altium Designer 20 was utilized to design the printed circuit boards (PCB) in this study.
Figure 4a,b depict the front-side and back-side schematic diagrams of the acquisition front-end PCB circuit.
Meanwhile,
Figure 4c,d present the PCB circuit diagram of the ECG acquisition system prior to and after installation of the Bluetooth telecommunication module, respectively. Following installation, the entire signal acquisition system can be visualized in
Figure 4e, which exhibits the analog signal output from the acquisition front end through an oscilloscope. Through careful inspection, we verify that the acquisition front end can effectively collect a diverse range of abnormal heart rate signals.
The oscilloscope employed in this work is the Agilent DSO7104B. The diagram of normal heart rate, parameter 300 beats per minute (BPM), with a frequency of 5 Hz.
Figure 5A shows atrial tachycardia, which is generally manifested in the atrium. The rate was usually 150–200 beats/min, and the P-wave morphology was different from that of sinus patients. By anterior measurements, it was evident that the P-wave pattern was abnormal and the atrial rate was rapid.
Figure 5B shows supraventricular tachycardia, which is one of the most common arrhythmias. Its clinical manifestation is a series of rapid, regular QRS waveforms with a frequency of 160 to 220 BPM.
Figure 5C is atrial fibrillation; referred to as atrial fibrillation, it is the simplest persistent arrhythmia with a frequency of 300–600 BPM, a rapid heart rate. The signals from the front end of the acquisition can indicate that atrial fibrillation does occur with rapid heart rate.
Figure 5D shows ventricular tachycardia, which refers to tachyarrhythmias occurring in bundle branches, myocardial conduction fibers, and ventricular muscles below the bifurcation of the bundle. Higher frequencies and abnormal QRS waves can be accurately detected through the acquisition front end through
Figure 5E–L, as shown.
Once the data signal is collected by the acquisition front end, which operates at a sampling rate of 360 Hz, the analog signal is transmitted to another module via HC-05 Bluetooth communication technology. In this study, serial port communication is utilized to connect with the terminal system. Subsequently, the recorded data is stored on the terminal system for further processing. Our experimental outcomes validate that the terminal can effectively transmit and record ECG data.
2.4. Schematic System Design
The ECG analysis system represents the ultimate outcome of the overall plan. It is fundamental to accurately collect heart rate signals, as their proper classification facilitates the proper functioning of the entire system. The ECG signal received by the terminal is usually subject to noise. Thus, the signal requires preprocessing. Noise removal should be primarily considered. Additionally, ECG signal classification typically relies on heartbeats. Therefore, segmenting ECG signals becomes necessary. Since QRS waveforms are more recognizable, identifying QRS waveforms first and selecting fixed signal points on both sides serves as an idea for heartbeat segmentation. After this segmentation, it is essential to divide the data into the training set and test set, construct feature engineering, perform traditional model and deep model training individually, and combine the prediction results to obtain the final classification outcome. The design flow chart of the ECG analysis system is presented in
Figure 6.
2.5. Software Design Process
In this study, the internationally recognized standard ECG database has been utilized, with specific emphasis on the MIT-BIH database. This database consists of 48 ECG records, each of which is 30 min in length, sampled at a rate of 360 Hz, and contains a total of 648,000 sampling points. It should be noted that actual training data comprised mainly sampling points corresponding to each heartbeat that were generally set between 200–300 points; for this experiment, 250 points were selected as a compromise. To address the four classification problems observed in the treatment phase, three types of abnormal ECG signals, including left bundle branch block, right bundle branch block, and ventricular premature beats, were used. ECG signals are bioelectrical signals and are vulnerable to external interference, such as common electromyography interference and power frequency interference. Therefore, despite the design of filters in both the acquisition front end and digital circuits, the original data still required preprocessing before being fed into the software analysis to enhance the signal-to-noise ratio of the machine learning model training dataset. The primary algorithm employed for this purpose was wavelet transform.
4. Discussion
Multiple types of models were built for overall classification and model fusion was conducted. Firstly, traditional models such as logistic regression (LR) [
27], support vector machines (SVMs) [
28], and XGBoost were employed, along with feature engineering for classification [
17]. Feature engineering primarily included morphological features and wavelet coefficient features. Subsequently, deep learning models, including CNN and LSTM, were used for classification. The classification results of LR and the SVM are shown in
Table 1.
The experimental results of LR, the SVM, and XGBoost were analyzed (
Table 2 and
Table 3). The overall performance was improved by combining wavelet transformation for coefficient extraction with meaningful first- and second-level features. Additionally, PCA and LDA were employed to reduce the dimensionality of features, ensuring that the feature space was not excessively large. The overall classification accuracy exceeded 96%, with a higher accuracy for normal beats.
However, there was a lower classification accuracy for ventricular premature beats. The core features of ventricular premature beats include a relatively wide and deformed QRS complex, ST segment, as well as a T-wave direction opposite to the QRS complex. The QRS duration is greater than or equal to 0.12 s (the normal limit is less than or equal to 0.11 s). Analysis revealed that the main reason for the lower accuracy was that manual feature engineering fails to effectively capture the distinctive features of ventricular premature beats, especially the differentiation between ST segment and
T-wave direction and QRS complex direction. Furthermore, the discriminatory power of QRS duration is insufficient, which is reflected in the relatively low feature importance obtained from the XGBoost classifier. Therefore, it is necessary to complement the model using deep learning techniques [
29].
XGBoost has several parameters to adjust, as shown in
Table 2. The main parameters that need to be adjusted include:
Learning_rate (eta): This represents the learning rate or step size for the iteration of decision trees. A smaller value leads to a slower iteration, whereas a larger value may result in lower accuracy.
Max_depth: This parameter determines the maximum depth of each decision tree. It is generally set between 5 and 10. Setting it too high can lead to overfitting.
Random seed: The random seed can be adjusted using cross-validation to ensure reproducibility and control randomness.
colsample_bytree and colsample_bylevel: These parameters control the proportion of randomly sampled rows and columns, respectively. They are used to mitigate overfitting by introducing randomness into the sampling process.
To select the best parameters, it is recommended to perform testing and cross-validation. The parameter settings of CNN are shown in
Table 3.
An analysis was conducted on the experimental results of CNN and LSTM, revealing an improvement of approximately 1.4% compared with traditional models and feature engineering [
30]. Furthermore, the performance in detecting ventricular premature beats (VPBs) was better than that of the traditional models. This suggests that the previous approaches of wavelet transformation and manual feature construction were not able to effectively identify the distinguishing characteristics of VPBs from other signals. Therefore, it is necessary to explore various aspects of feature engineering. In the case of large datasets, when proper parameters are set, deep learning generally outperforms traditional machine learning methods [
31]. Additionally, the final experimental results of model fusion are shown in
Table 4 below.
To validate the accuracy of the overall model’s predictive results in practical measurements, two sets of data were collected comprising five left bundle branch block heartbeats and five right bundle branch block heartbeats. The actual prediction accuracy was found to be 100%. It is evident that the accuracy of the model’s predictions in practical scenarios is exceptionally high.
The classification of V (ventricular premature beats) is relatively challenging compared with other symptoms in the overall context. The main reason for this difficulty lies in the inadequate depiction of distinguishing features related to the ST segment, T wave direction, and QRS wave direction. Consequently, the model fails to recognize these features effectively, indicating a need for special design considerations in characterizing the features and model structure for ventricular premature beats. Meanwhile, it is observed that deep models outperform traditional models in general, suggesting that the wavelet coefficients and morphological features do not sufficiently allow the model to learn the differences between ventricular premature beats and other states. Thus, more effective features in this regard should be explored.
Furthermore, within the overall context, except for the CNN’s superior performance in classifying R (right bundle branch block), the accuracy of the fused models is better for the remaining cases. This highlights that fusion of models with low correlation indeed enhance the final predictive results effectively.
Lastly, the accuracy of the model in predicting the normal state is nearly similar. This implies that the manually constructed feature set can effectively depict the heart rate during the normal state, resulting in the highest overall accuracy in normal state classification.
In order to ensure the standardization of the research, it is necessary to adjust the classification criteria according to the AAMI (Association for the Advancement of Medical Instrumentation) standards. AAMI and MIT-BIH fundamentally represent two different classification methods in clinical practice.
Therefore, in order to meet the standards set by AAMI, the classification approach of the AAMI was employed to transform the problem into a five-class classification task. However, due to limited training data for the Q category in the MIT-BIH dataset, this category was excluded, resulting in a four-class classification problem for practical application. To expedite the training process, an improved CNN model was utilized for prediction, as depicted in
Figure 10. In comparison with the previous CNN model, the core component of the modified model involved adjusting the size of the intermediate convolutional kernels from 31 to 91, 61, and 31. The reason for not using larger kernel sizes was because heartbeats inherently consist of short-term data and CNN models are better suited to extracting features by starting with smaller-sized kernels [
32]. The use of different kernel sizes aims to maintain small sizes while maximizing the window for feature extraction. The final accuracy achieved was 99.16%, as indicated by the actual test results presented in
Table 5.
The analysis of the final results leads to the following conclusions. It can be observed that there is an issue of sample imbalance in the S, V, and F classes within the MIT-BIH dataset. Therefore, in the initial phase of the study, these classes were intentionally avoided, and only the N class was used for classification. This approach indeed helped to address the problem of sample imbalance to a certain extent. To tackle sample imbalance, three common strategies are generally employed:
Weighted processing—where different weights are assigned to different samples in the final loss function;
Oversampling—which involves artificially increasing the number of samples by applying a sampling multiplier to the minority class;
Undersampling—which reduces the number of samples in the majority class [
33].
In practice, all three methods were attempted. However, due to the scarcity of samples in certain categories, for example, the F class only had 800 samples in the training set, undersampling was not deemed suitable in some cases, whereas oversampling did not effectively improve the training performance [
34]. Therefore, the focus should be on addressing the imbalance issue at the data level.
The majority of the training data for this study is sourced from the MIT-BIH database. Due to the limited volume of data collected by the embedded system, only a small sample test could be conducted. Therefore, the accuracy achieved does not fully represent the accuracy of this classification system in handling real-time heart rate data. As a result, further in-depth research is required to investigate the real-time performance of the system [
35].
This chapter focuses on the software component of the entire ECG analysis system. Whereas the hardware component is responsible for signal acquisition, the software part is responsible for signal analysis and classification. Firstly, the overall machine learning classification process is defined, including data preprocessing, dataset partitioning, feature engineering, model selection, performance testing, and model fusion. In the data preprocessing phase, attention is given to addressing certain issues in heart rate signals by applying wavelet transformation for denoising purposes. Due to the specific nature of heart rate signals and to facilitate feature engineering, a QRS wave detection algorithm was designed. Subsequently, the dataset was partitioned and three partitioning methods were proposed and selected based on theoretical and practical considerations. Feature engineering was constructed from two perspectives: morphological features and frequency domain features. For model selection, traditional models such as LR, SVMs, and XGBOOST were initially tried in combination with manual feature engineering. However, considering the limitations of traditional models and the strong fitting capabilities and non-requirement of manual feature engineering in deep learning models, LSTM and CNN classic models were adopted for classification. Additionally, traditional models were used for model fusion to prevent overfitting [
36]. Finally, starting from the AAMI standard, a new model was constructed with new classification criteria and the results were analyzed.
5. Conclusions
The main research content of this paper is the study of an ECG signal acquisition and analysis system based on machine learning, and the main achievement is a system that can collect ECG signals and transmit them to the terminal for classification. The overall framework of the system is mainly an ECG signal acquisition system and an ECG analysis system. The signal acquisition system is responsible for collecting ECG data from the human body and sending it to the terminal. The analysis system mainly includes data preprocessing and machine learning models. Software modules are written on the terminal for data reception. The data is preprocessed and then a machine learning model is constructed to classify and set evaluation indicators to evaluate the model results, which mainly improves the convenience of the ECG acquisition system and realizes a system for detecting whether the human heart rate signal is normal. The final experimental results and conclusions are as follows:
(1) Use self-made PCB to realize the design of ECG acquisition system and improve the portability of the system. The overall hardware design mainly includes signal transmission and processing. The main structure of the acquisition system is to first collect ECG signals through commercial electrodes and three-lead methods (the main reason for using three-leads is that three-leads are more accurate than single-leads and are simpler and more portable than twelve-leads). Then, use AD8232 as the acquisition front-end chip. The built-in circuit of the AD8232 chip has the functions of primary and secondary amplification and high-pass and low-pass filtering. Then, use STM32F103 as the main control chip to collect the analog signal obtained by AD8232 through the ADC module after the signal is digitally filtered. Finally, the converted digital signal is sent to the terminal. Finally, it is concluded that a circuit with AD8232 and STM32F103 as the core can accurately collect most types of heart rate signals (normal heart rate and multiple abnormal heart rates).
(2) Design a machine learning model to analyze the collected ECG signals and combine the embedded system to realize a complete system for ECG collection and artificial intelligence analysis. The overall scheme design of the analysis system mainly includes the preprocessing of the ECG signal and the idea of model construction. Collect the data through the terminal and then use the wavelet transform denoising method to filter the data; after the filtering is completed, use the QRS extraction method to achieve the extraction of the heartbeat. The core idea is to use the dual-slope algorithm to extract the position of the QRS wave. The position of the QRS wave divides the data points forward and backward to realize the heartbeat segmentation. The length of the data points is generally in the range of 200–300. In this article, we use 100 points forward and 150 points backward, totaling the division of 250 points that are used as the heartbeat length. We then build different types of models for an overall classification and model fusion. First use traditional models (including logistic regression, support vector machine, XGBOOST) and feature engineering for classification, feature engineering mainly includes morphology features and wavelet coefficient features, then use deep learning models (including convolutional neural networks and long- and short-term memory networks) for classification. Finally, all models are fused to obtain the final result, and the final accuracy of the model is 99.13%.
To deploy the proposed system for real-time monitoring of ECG signals and analysis of potential heart diseases, there are different approaches for implementation in hospitals or at home:
Hospitals: In a hospital setting, the system can be integrated into the existing infrastructure for cardiac monitoring. The ECG monitoring device can be connected to a central monitoring station through wired or wireless connections. The ECG signals can be transmitted in real-time to a dedicated server, where the AL machine learning algorithms are deployed for analysis. The results can be displayed on a monitoring dashboard accessible to healthcare professionals, allowing them to make timely diagnoses and decisions.
Home use: For deployment in a home setting, a portable ECG monitoring device can be developed. This device should be user-friendly, compact, and able to wirelessly transmit the ECG signals to a mobile app or a cloud-based platform. The app or platform can then apply the AL machine learning algorithms to analyze the signals and provide feedback on potential heart diseases. Users can securely access their ECG data and analysis results through the app and, if necessary, share them with healthcare professionals for remote monitoring and consultation.
In both scenarios, it is important to ensure the system’s accuracy, reliability, and data security. Compliance with the relevant regulatory standards and obtaining the necessary approvals may also be required before deploying the system, especially in a medical context.