Designing Very Fast and Accurate Convolutional Neural Networks With Application in ICD and Smart Electrocardiograph Devices

An implantable cardioverter-defibrillator (ICD) is a device that must detect VT and VF arrhythmias on time and treat them. In this project, three CNN networks are designed to introduce the practical methods of using deep learning in heart electrophysiology signals processing. This project presents two speedy intelligent detection methods of ventricular fibrillation and ventricular tachycardia arrhythmias for ICD devices. It also provides another quick, innovative diagnosis method for use in intelligent electrocardiograph devices to detect abnormal cardiac signals. The first network is 1D-CNN for smart electrocardiographic devices to detect abnormal ECG signals. Dataset MIT-BIH has been used to train this network. This network with the most optimal number of parameters due to high detection speed has a high accuracy of 91%. The second and third networks are 2D-CNNs for use in implantable defibrillators. For the second network, a data set of 20 patients with cardiac arrhythmia and 20 patients without cardiac arrhythmia in an 8-month period of ICD check-up has been prepared. The third network is trained using the Spontaneous Ventricular Tachyarrhythmia Database. The second and third networks are designed to detect EGM signals in VF and VT modes with the optimal number of parameters and 100% accuracy in the second network and 90% in the third network. All three designed networks are in an optimal condition regarding the number of parameters and layers, so they have optimal speed and energy consumption.


I. INTRODUCTION
The electrical current of the heart enters the soft tissues around the heart and even reaches the surface of the skin, so can place leads in the areas around the heart, on the surface of the skin and record the (ECG) electrical current of the heart [1], [2]. When muscles contract or transmit a nerve message in the body, electrical signals are generated by the movement of ions in the relevant tissues. Nerve and muscle tape, muscle imaging, electromyography, The associate editor coordinating the review of this manuscript and approving it for publication was Wei Wei . or EGM is the recording of electrical signals from nerve and muscle activity that are non-invasive (for example, by placing a surface electrode on the body) or invasively (for example, by inserting the needle electrode is applied to the target tissue. It is worth noting that recording noninvasive surface EGM signals poses a lower risk to the test subject or patient and is, therefore, a relatively more common measurement method for non-physician users (such as nonmedical researchers) [3], [5]. Electrical stimulation in the heart does not follow a specified route, causing atrial or ventricular cells to be excited irregularly. VT and VF are examples of cardiac arrhythmias. In another type of cardiac arrhythmia, the atrial and ventricular beats are separated, and each is stimulated with different rhythms and from separate centers. Defibrillation is one of the fastest and most practical methods of treating ventricular fibrillation [6], [7].
Defibrillator devices restore the standard heart rate by sending an electric pulse or shock to the heart. They are used to prevent or correct arrhythmias and heartbeats that are uneven, too slow, or too fast [8]. Defibrillators come in a variety of configurations. Automated external defibrillators (AEDs) installed in public areas are intended to save the lives of those who suffer cardiac arrest unexpectedly. Even unskilled viewers can use these gadgets in an emergency [9]. Other defibrillators can prevent sudden death among people at risk for dangerous arrhythmias, including implantable cardioverter defibrillators (ICDs), which are surgically inserted into the patient's body [10]. There are two main types of implantable defibrillators produced worldwide: the first type is devices that detect ventricular defibrillation and the second type, in addition to diagnosing ventricular fibrillation, also detects tachycardia arrhythmias. In defibrillators, the heart's electrical signal is recorded, then the analog signal is converted to digital by a signal recording processor and finally transmitted to a central or main processor. In the main processor, it is detected whether the heart is in a state of fibrillation or not; in case of detection of fibrillation or tachycardia, appropriate electrical energy enters the heart. Most existing defibrillators' main processors are microcontrollers and work with a signal-processing approach [11], [12], [13].
One of the challenges of implantable defibrillator devices is the detection speed because if the detection speed is low, the patient may die. Another challenge in implantable defibrillator devices is the optimization of energy consumption because the battery replacement of these devices must be done through surgery. Another challenge of implantable defibrillator devices is that these devices themselves may cause malfunction of the heart. This paper aims to provide artificial neural networks based on deep learning for the first and second challenges, which have optimal speed and energy consumption in addition to having good accuracy. To solve the third challenge, the article aims to introduce an artificial neural network that is an ECG signal processor that can process with Recognize speed the abnormal ECG signals of the patient with an implantable defibrillator.

II. MODERN APPROACH
They are being cared for in the hospital when heart patients have recently had surgery, and a defibrillator has been implanted in their bodies. In this process, it is better to use smart electrocardiogram devices to check the patient's ECG signals in the shortest possible time and give an alarm if it is abnormal. Two types of smart electrocardiogram devices are fixed in hospitals and portable. Portable electrocardiogram devices such as holters can help monitor patients with cardiac arrhythmias and their treatment process [14]. In smart electrocardiogram devices, different methods can be used to design the data processing section. [15] has introduced an old intelligent rule-based ECG signal processing algorithm without using neural networks, which can process ECG signals based on signal processing algorithms. [16] has presented several networks based on long short-term memory (LSTM) neural networks, with accuracy between 96.8% and 99.79%, and their hidden size is 128. [17] has introduced several models based on Angle Transform + LSTM with an accuracy percentage of between 98.75 and 100 and a hidden size of 128. [18] has introduced a method of processing ECG signals based on the Support Vector Machine (SVM) machine learning algorithm. In smart electrocardiogram devices, deep learning neural networks can be used, and CNN networks are a good option in this field. Classifiers are more critical than features in modern approach-based algorithms. Deep learning is the foundation of modern techniques. One of the important features of networks based on deep learning is that the networks self-extract and learn the important features of training examples. This solves the problem of defining features for examples that do not have special features or are difficult to define. Convolutional networks are among the networks that use deep learning. In convolution networks, we have a feature extraction part where the specified kernels are convoluted on the data. As a result of the output of the convolution layers, feature maps are produced that can be used in Max pooling sections to reduce their dimensions and the processing volume, and it can increase the processing speed. Figure 1 shows one step of kernel convolution in the convolution network. Finally, after one step of kernel convolution on the data, a part of the first feature map regions is determined. The next part in convolution networks after the feature extraction part is the analysis part of the extracted features, which can be used in this part of the fully connected network. Figure 2 shows the flatting stage and the data entry into the feature analysis section. As it can be seen, all twodimensional data are converted to one-dimensional data, and in this example, the two-dimensional data is converted to one-dimensional data linearly. It means that in the onedimensional data, the first line of the two-dimensional data is placed first, then the second and third lines, which can be recognized from the color of the Matrix pools.  One of the types of convolution networks is onedimensional convolution networks. These networks can be used to process one-dimensional data. Figure 3 shows a one-dimensional convolution network. There are feature extraction and analysis parts in these networks, but there is no more flatting part. ECG signals may be mapped into various attributes using deep learning-based neural network topologies. Some examples of deep learning-based classifiers include 1D CNNs, 2D CNNs [19], and dense neural networks [20]. Since achieving LSTM networks with acceptable performance requires a high number of parameters, it is expected that the output networks will not have high speed; therefore, CNN networks can be used for emergency applications because they can be designed with acceptable performance and also good speed for emergency applications with control of the number of parameters and the number of layers [21].
The network algorithm designed in this field can be used in various monitoring devices for abnormal ECG signals, such as intelligent electrocardiographs. According to Figure 4, the ECG signal enters the processing part of the device, and then it detects if the signal is abnormal. Due to the minimization of the number of parameters in the presented method, simultaneous detection will be appropriate. Convolution is used instead of multiplication in formula 1, the only difference being that convolution is presented in formula 1.
The convolution kernel index is j, the filter size is M , and the input feature map index is I . For the i th and j th output maps, respectively, k ij is the convolution kernel. There are several methods for diagnosing cardiac arrhythmias, depending on the application. One diagnostic approach is classifying cardiac signals into two categories: normal and abnormal. In [22] with a one-dimensional CNN network design with the number of parameters 19911 and with 95.2 accuracies in [23] with CNN network design with the number of parameters 40210050 and with 98.13 accuracies, in [24] CNN network with the number of parameters 652139 and with 96.18 accuracies. In implantable ICD devices, a shock lead is inserted into the heart, which can receive and process the heart's EGM signal through the communication path that enters the heart; also, it can receive and process the ECG signal. In this case, the cost of manufacturing the device is higher because in terms of equipment, in addition to the way of communication with the heart to shock the heart, we also have to use leads to receive the ECG signal. Another method is the simultaneous use of EGM and ECG signals. In this case, in addition to increasing the cost of manufacturing the device, we will also face an increase in battery consumption. Deep learning algorithms can be used to signal processing to improve the performance efficiency and accuracy of implantable ICD devices. In [25], a 1D-CNN network has been constructed and launched with an accuracy of 84.6 percent based on 135 pairs of RR interval time series collected by implanted cardioverter defibrillators (ICDs) (Medtronic Jewel PlusTM ICD 7218). In [26], Each block of ResNet-18 has a 1-D convolution filter replaced with a 2-D convolution filter in order to make the design acceptable for unipolar EGM analysis. The validation of this network is 90.4% using personal dataset. In [27] introduced ANN by using Spontaneous Ventricular Tachyarrhythmia Database. This network has 75.6% accuracy for EGM for VT and VF detection. [28] introduces four different CNN networks that process the EGM signal so that they can be used in an in-house defibrillator. These networks have an accuracy of 79.1%, 90.6%, 86.3%, 91.4%. [29] has used three CNN networks for EGM processing in ICD devices, which have 98.1%, 96.6% and 93.2% accuracy.
Neural networks processing ECG signals, which divide these signals into two categories, normal and abnormal, are helpful for the use of emergency applications; apart from the need to have good accuracy, they must also have a high detection speed. EGM signal processing neural networks that can be used in implantable defibrillator devices, in addition to having proper diagnosis speed and accuracy, should also have optimal energy consumption because battery replacement in these devices is difficult and must be done by surgery.
Fewer parameters in artificial neural networks reduce energy consumption [30]. Also, reducing the number of artificial neural network layers can reduce energy consumption in addition to increasing processing speed [31].
The main goal and innovation of this article is the design of neural network architecture based on deep learning that can be used in implantable defibrillator devices in such a way that, in addition to the percentage of accuracy, special attention is given to the speed of diagnosis and the optimality of energy consumption. Another goal of this article is to design a neural network based on deep learning to check the non-destructive use of the implanted defibrillator by dividing the ECG signals into two categories, normal and abnormal, with an emphasis on the appropriate detection speed along with appropriate accuracy. With the mentioned objectives, the architecture of networks should be such that the number of parameters and the number of layers are in an optimal state.

III. METHODS
In implantable ICD devices, a shock lead is inserted into the heart, which can receive and process the heart's EGM signal through the communication path that enters the heart. Figure 5 shows the defibrillator implanted inside the body [32]. The leads are inserted into the heart and connected to the end of the right ventricle and right atrium so that they can receive the electrophysiological signals of the heart and deliver a shock at the right time. The algorithms used to detect arrhythmias in ICD devices, in addition to being properly accurate, must have a good speed in the diagnostic process. Deep learning algorithms with a large number of parameters, even with a high accuracy percentage, cannot detect cardiac arrhythmias at the right time. In practice, these networks are not practical in emergency use. Also, the high number of parameters increases the battery consumption in portable devices.
Artificial intelligence can be used to design the signal processing part of ICD devices. Since in deep learning algorithms, the network itself extracts and learns the essential features of the samples, using deep learning algorithms in medical processing is helpful because some of the samples are in medical data for which no specific feature can be specified. And in cases where feature extraction and definition are difficult for artificial intelligence algorithms such as machine learning algorithms, deep learning algorithms can be used so that the network itself extracts and learns the essential features of the samples.
Given the importance of caring for patients who have recently undergone surgery and a defibrillator has been implanted in their body and are being cared for in a hospital, it is best to monitor the hearts of these patients using an intelligent electrocardiograph so that if any arrhythmia occurs for their heart, the device will start alerting. In this project, a one-dimensional CNN network is designed for use in intelligent electrocardiograph devices, which has the optimal accuracy percentage at the most optimal time and can evaluate the ECG signals of the heart and recognize abnormal signals. Intelligent detection of abnormal electrocardiogram signals can be used in hospital and portable smart electrocardiograph devices so that if the patient experiences abnormal arrhythmias, the device can give an alarm, which can also be used in holter devices, which can detect abnormal arrhythmias and save them in its memory. Figure 6 shows an example of the intelligent function of detecting normal or abnormal ECG signals in holter monitor device [33]. Detecting normal or abnormal ECG signals in holter monitor device [33].
A network was designed to classify normal and abnormal ECG signals by considering the appropriateness of the number of network parameters along with the accuracy of the network. For this purpose, CNN 1D neural network has been used in this research project. MIT-BIH database has been used to train and test this network.
This dataset was the first set of standard electrocardiograms to be made available to the public and has been used since 1980 to evaluate cardiac arrhythmia detectors and study the dynamic properties of the heart. to collect the database, Electrocardiograms were recorded from 25 men aged 32 to 89 years and 22 women aged 23 to 89 years, approximately 60% of whom were hospitalized. The database contains 48 half-hour electrocardiograms recorded in 24 hours from 47 people (data 201 and 202 were taken from one person). In this database, R peaks are marked, most beats are interpreted, and their type is specified. Figure 7 shows an example of the dataset signals used [34]. This research has used the Google colab environment to implement the 1D CNN network. After installing the required libraries and downloading and loading the data, according to the PhysioNet citation database, separated the data that is invalid and their label is also clear, and has been defined the data that is in the form of abnormal signals. Any signal not in the two categories is considered a normal signal. The signals are then classified according to their symbol. It then specifies the start and end locations of the beat based on a window that uses consecutive checks, and the program gives an empty array when it reaches an invalid beat or empty sequence. In this network, we will have the three elements (batch_size, sequence_size, number_of_features) because we have only one attribute in our model: (1,sequence_size, 1) The following will discuss the inputs related to the targets and the input map related to each patient. The idea to classify for training and accreditation is based on abnormal beats. In the following, subject_map is formed to separate the training data and guardian. The data are then divided into two groups: training and validation. In the following, the convolution network has been designed. The network consists of 6 layers of one-dimensional convolution, including 2 layers with 32 filters, 2 layers containing 16 filters and 2 layers containing 8 filters, as the activating function of each ReLU filter. Each layer also includes Dropout (0.2) and MaxpPool1D. Figure 8 shows the designed network flowchart.
The network also includes three layers of Dense10, two layers of Dense8, one layer of Dense6, two layers of Dense4, one layer of Dense2, and one layer of Dense1. Finally, the number of parameters of this network is 9305. Table 1 shows the architecture of the 1DCNN network used in this project. The final classification in this network is binary classification. In this network, the Total and Trainable parameters are 9,305, and the Non-trainable parameters are 0.
Since one-dimensional CNN network has been introduced for detecting abnormal ECG signals, its accuracy can be calculated through formula 2. In this formula, the number of correct detections of abnormal signals is divided by the total number of correct detections of abnormal signals and  abnormal signals.

Accuracy =
True abnormal True abnormal + False abnormal (2) In this project, to design the central processor part of the defibrillator device, a CNN network has been designed that can process EGM signals. One of the databases of this project has been prepared from the memory of programmer devices that record signals of ICD devices of Shahid Rajaei Hospital in Tehran, Iran. Patients with a defibrillator in their body go to the hospital for a check-up. The signal recorders receive and store the signals stored in the ICD devices using the leads that are placed on the patient's body. The target of this project is Boston brand ICD devices. In preparing the data set, 20 patients who had arrhythmias of VF and VT and 20 patients who did not have arrhythmias were used in the period of time between the check of patients ICDs. This period is either one month after surgery to insert a defibrillator into the patient's body or in periods of 8 months after the first checkup. EGM signals received from the heart can be converted to an image on an ICD device so that the output of this step is an image of the signal. The images were entered into CNN network for processing. The data used in the network includes three classes of VT, VF, VS. Finally, the image that will enter the network may be noisy, unclear and blurred, so the data was blurred a bit before use. The signal recording period for processing is 0.6 seconds. Figure 9 shows examples of the data for each class in the three measurement vectors are labelled A (left atrium), V (right ventricle) and shock.
In the third network, Spontaneous Ventricular Tachyarrhythmia Database was used. This resource comprises 135 pairs of RR interval time series obtained from 78 people with implantable cardioverter defibrillators (Medtronic Jewel PlusTM ICD 7218). The RR intervals in each series range from 986 to 1022 points. Each pair contains a sample of the intrinsic (usual sinus) rhythm and a sequence of spontaneous ventricular tachycardia (VT) or fibrillation (VF). Snapshots from the ICDs contain snippets of the high-resolution EGM. The data used in the network includes three classes of VT, VF, MR. Finally, the image that will enter the network may be noisy, unclear and blurred, so the data was blurred a bit before use. Figure 10 shows an example of the data for each class [35].
MATLAB software has been used to design the CNN networks, and also the GPU used in this project is NVIDIA GeForce GTX 1080 Ti. The important point in the network designed in this project is to consider the number of parameters in the minimum possible number because, with this approach, both the speed of networks detection increases and the battery consumption decreases. With the growing need for ''smart'' algorithms on mobile and wearable devices, processing power consumption has become a barrier to battery life. One way to alleviate this bottleneck is to limit the compute activity on such devices -one of the most common techniques utilizes sensor data to decide whether it is worthwhile to execute costly calculations or if there is an insufficient activity in the surrounding environment. This is referred to as event-driven computing [36]. Since the ICD device is implanted in the body and the amount of battery consumption is very important, the low number of network parameters can help reduce battery consumption in the ICD device. The designed neural network must have an acceptable percentage of accuracy and be optimal in terms of the number of parameters.
The second network designed in this project consists of 7 layers. The first layer is the convolution layer, which has 32 filters with 3 × 3 size. The third network designed in this project consists of 10 layers. The first layer is the convolution layer, which has 32 filters with 3 × 3 size. Followed by the ReLU section as the activator function. Formula 3 represents VOLUME 11, 2023 the ReLU formula.
There is a dropout level in this section. An entire row of the vector matrix is used instead of random weights in dropout. As a result, earlier (unspecified) assumptions about weak dilution and mean field theory are erroneous. Setting the weights to zero, ''removing the node,'' or any other method of bringing a node to zero does not affect the ultimate outcome. If a high-performance digital array multiplier processes the neural network, the value should be set to zero late in the process graph (HDAMM). Using a limited processor, such as an analog neuromorphic processor, may make it more energy efficient to set the value to zero early in the process graph.
In formula 4, P(c) is the probability to keep a row in the weight matrix, w j is real row in the weight matrix before dropout,ŵ j is the diluted row in the weight matrix. Three layers of dropout with a probability of 0.5 have been used in the second network. The next part of the second network is the Max Pooling layer. In a '' max pooling process,'' the biggest feature map element inside the filter's region is selected. Max-pooling creates a feature map that includes the most notable elements from a previous feature map. Three layers of dropout with a probability 0.7 have been used in the third network. The next part of this network is the Max Pooling layer.
In convolution networks, one of the ways to improve the accuracy percentage of the network is to increase the number of parameters, but in the intended application of this project, the number of fewer parameters is essential; therefore, so in the first convolution network, to reduce the number of parameters while achieving the accuracy percentage For the appropriate situation, the approach of increasing the convolutional and dense layers with a small number of parameters has been used, that is, in each step of increasing the number of layers, the number of parameters considered is less than the previous step. In the second convolution network, the use of the y=x linear activator function allows the outputs of the convolution layer to be transferred to the next part of the network unchanged; this approach has been helpful for this network and increased the accuracy percentage rate up to 100% in addition to the fact that the number of network parameters is also optimal. One of the ways to reduce the dimensions of feature maps in convolution networks is to use Max Pooling. In the third network, the proposed solution to reduce the required parameters of the network while having an acceptable accuracy percentage is to use three consecutive dropout stages. Each dropout section has a certain probability, creating a larger probability. The advantage of using this approach is to put several dropouts together and make a large probability, which prevents overfitting. Combining dropout with max-pooling can prevent overfitting. Figure 11 shows the difference between using dropout before the max pooling stage and not using dropout before the max pooling stage. FIGURE 11. Difference between using dropout before the max pooling stage and not using dropout before the max pooling stage.
As can be seen in Figure 11, a max-pooling stage is performed in part A, but in part B, before max-pooling, there is a dropout part with a probability of 0.5, in which case a series of pools are randomly removed. And after that, the max pooling part is done.
In the second and third networks, the following layer is a fully linked layer with three outputs. After multiplying the input by a weight matrix, a bias vector is added to the final result. After the convolutional (and down-sampling) layers, a fully connected layer is inserted. All neurons in a linked layer are connected to each other and interact with each other. Because CNNs capture a more accurate representation of data, we avoid the requirement for feature engineering. Classification: After feature extraction, we must categorize the data using a fully connected (FC) neural network.
The following section is about Softmax. In neural network models that forecast a multinomial probability distribution, the Softmax function is used as the activation function. Softmax is used as the activation function when more than two class labels are required for class participation.
In formula 5, σ is softmax, z i is the input vector, e z i is the standard exponential function for the input vector, k is the number of classes in the multi-class classifier, e z j is the standard exponential function for the output vector.   Figure 12 shows the structure of the second CNN network, and figure 13 shows the structure of the second CNN network designed for this project. As described, the network is designed in the simplest possible way so that in addition to having an acceptable percentage of accuracy in terms of the number of parameters, usability and speed are also in optimal condition. Figure 14 shows the solutions to control the number of parameters and the desired accuracy percentage. In setting the number of parameters and keeping the accuracy percentage, attention is paid to the overfit or underfit of the networks. In the one-dimensional CNN network, the solution is to reduce the number of parameters in each step of increasing the convolution and dense layers. In the two-dimensional CNN network, which is the second network, the use of the V(o)=V(i) function has been used as a solution so that the outputs of the convolve part can enter unchanged to the next part of the network. In the next CNN network, the third network, the use of several dropout stages, which together create a dropout with a higher probability than each dropout stage, is considered a solution.
Since the CNN networks designed in this article are designed to detect the signals of ventricular fibrillation, ventricular tachycardia, and another type that is not dangerous, the accuracy of these networks can be calculated through formula 6, as shown at the bottom of the next page.

IV. RESULTS
In this paper, three networks have been designed. The first is for use in ECG signal checking in smart electrocardiographs, and the second and third are for implantable defibrillator devices. In the first network, which is a one-dimensional CNN type, the low number of parameters has been emphasized to increase the detection speed. In contrast, it has been noticed that the network accuracy is in good condition. The number of Epochs of this network is 20; finally, this network has reached 91.3 accuracy.
As shown in Figure 15, the accuracy of the training data is 98.7%. Figure 16 and Figure 17 show CNN model accuracy and CNN model loss diagram.
Compared to other introduced networks, with a large difference in the number of parameters of the designed network, this network can operate faster in diagnostic work, and its algorithm can be used in hardware applications. Table 2 compares the networks introduced in this paper that divide ECG signals into normal and abnormal categories with the network designed in this paper.
As seen in Table 2, the designed one-dimensional convolution network has been able to have an acceptable accuracy percentage by significantly reducing the number of parameters. The most significant difference in the percentage of this network with other networks can be about 8.5%, but a network that can have this difference and have a higher rate of accuracy has a higher number of parameters, so the purpose of comparing the network designed and other networks is comparing applicability in diagnosing abnormal heart arrhythmia in a short time, which is achieved with a small number of parameters and an acceptable percentage of accuracy. Suppose a network has 8% more accuracy but   has a large number of parameters, at the time of practical application of the network. In that case, it is possible that the patient dies before the network wants to perform its diagnostic work, so the purpose of the comparison in Table 2 is that the network Introduced in this project, even though it has the lowest number of parameters in the comparison, its accuracy percentage is in an acceptable condition above 90%. In general, it can be used in sensitive applications of detecting abnormal cardiac arrhythmias with a suitable speed. The network designed in this paper has less number of parameters and less number of layers, so it has of higher detection speed and can be used in emergency situations; its accuracy percentage is also in good condition in an acceptable number of test data. One of its examples is the intelligent diagnosis of cardiac arrhythmias in electrocardiographs so that the device will give an alarm if the patient has any cardiac arrhythmia.
The network that processes ECG signals in this article has advantages over other networks introduced in this article Accuracy = True VF + True VT + True not dangerous True VF + True VT + True notdangerous + False VF + False VT + False not dangerous (6)  that process ECG signals and are not classified as normal or abnormal. For example, the advantage of the ECG signal processing network in this article is the higher accuracy percentage compared to [15] and the newer algorithm used. The advantage of this article's ECG signal processing network compared to [16] and [17] is less number of parameters and, as a result, more speed and more application in emergency applications.
The advantage of this article's ECG signal processing network compared to [18] is that this network uses a deep learning algorithm, but in [18], an older machine learning algorithm is used. The use of deep learning-based algorithms will make the neural network more accurate because deep learning-based algorithms extract and learn the essential features of the data themselves. Still, older machine learning algorithms are based on and dependent on the extraction of features of the algorithm designer, and The algorithm designer may not be able to extract all the important features of the data and introduce them to the machine, or he may make a mistake in extracting and precisely defining the features [37]. Table 3 shows the summary of these comparisons.
The main goal of this project's second and third networks was to design an artificial neural network for processing EGM signals. Since one of the best methods of learning artificial neural networks is to use deep learning, the design network in this project has also used deep learning. In this network, it has been tried that the accuracy of the network is in a favourable  condition and also the network is in an optimal state in terms of the number of parameters so that the network speed is in an VOLUME 11, 2023   optimal state during hardware implementation practical use of the network. Table 4 shows the comparison between the networks designed in this project and other networks. As seen in Table 4, the accuracy of the designed networks is in good condition. It is also noteworthy that the networks designed in this project are in the most optimal condition regarding the number of parameters. Also, considering that these networks are designed for an implant device, it is necessary to pay attention to the battery consumption and try to reduce it. Therefore, optimizing the number of network parameters is also important in this discussion. The networks designed in this article with less number of parameters and a number of layers can have higher detection speeds and save battery consumption. Since the number of test data can be effective in checking the performance of designed networks, as can be seen in Tables 2 and 4, the number of test data considered in this study is in a good condition compared to other studies. Tables 5 and 6 show the results of using the most popular networks for the data of the second and third CNN networks. At each stage, the accuracy percentage of the test data on the networks in the tables has been obtained using the data set in each network. As can be seen, the accuracy percentage of the networks designed in this project is higher. The networks designed in this project are more optimal than others in terms of simplicity, fewer parameters, and the number of layers. As a result, they have a much higher detection speed. Figure 18 shows the results of the second CNN network designed in this project; as can be seen, the accuracy is in good condition. Validation accuracy is 100%, and the training accuracy is 91%. Figure 19 shows the results of the third CNN network designed in this project; as can be seen, the accuracy is in good condition. Validation accuracy is 90%, and the training accuracy is 91%.   [37], [38], [39]. Figure 20 shows the flowchart of the entire process examined in this research. After surgery of defibrillator placement inside the body, the patient's heart should be checked through holter monitor devices or smart electrocardiographs. These images of these parts are presented in [38] and [39]. These devices check the patient's ECG signal, and if they detect a large number of abnormal ECG signals, it means that the implanted defibrillator device has disrupted the heart's function. The implanted defibrillator device also checks EGM signals with CNN networks, the image used is presented in [40]; if it detects ventricular fibrillation and ventricular tachycardia arrhythmias, it shocks the heart to the required extent.

V. CONCLUSION
Monitoring heart function and its timely treatment in case of dangerous cardiac arrhythmias are concerns of defibrillator device manufacturers. The implanted defibrillator monitors and protects the heart against dangerous arrhythmias such as VT and VF. In the ICD device, a lead is inserted into the heart to deliver a shock to the heart. In this way, the communication established with the heart can extract the EGM signal of the heart and process it. Still, in some ICD devices, in addition to processing the EGM signal, the ECG signal is also processed, which this approach causes Increases the battery consumption and the cost of making an ICD device. In some ICD devices, only the ECG signal is used for processing, which in this case increases the cost of manufacturing the device, and the most optimal way is to use the same way of communication with the heart to shock it, that EGM signal can be extracted with that way. Signal processing and detection of cardiac arrhythmias in the defibrillator are particularly important. In this section, artificial intelligence algorithms can be used. One of the optimal algorithms in this field is the Deep Learning algorithm. The accuracy and speed of the network designed in the arrhythmia diagnosis of the defibrillator device are essential points. Optimizing the number of designed network parameters can optimize network detection speed. Also, the optimal number of network parameters can help reduce the battery consumption of ICD defibrillators. This project presents two speedy intelligent detection methods of ventricular fibrillation and ventricular tachycardia arrhythmias for ICD devices. It also provides another quick smart diagnosis method for use in intelligent electrocardiograph devices to detect abnormal cardiac signals. One of the most important innovations of the project is the presentation of techniques based on the latest artificial intelligence algorithms with a suitable percentage of accuracy and very high speed for use in ICD devices and smart electrocardiograph devices.
In this project, three networks have been designed. The first is for use in ECG signal checking in smart electrocardiographs. An important innovation in this network is to reduce the number of parameters and increase the detection speed so that the network can be used in emergencies. This network is a 1D-CNN network designed with the aim of detecting the harmfulness of the implanted defibrillator device for the patient's heart and divides the signals into two categories, normal and abnormal. Since the detection speed is essential in this intended application, the innovation of this network is in controlling the number of parameters and the number of its layers so that the percentage of the network in a suitable condition is 91%, but compared to all ECG signal processing networks introduced in this article has a higher detection speed because it has fewer layers and parameters than them. The goal of network design is that its accuracy percentage is between 90-100%. Still, its speed is higher than other networks introduced in this article, and other ECG signal processing networks presented in this article are less useful in emergency applications.
The second and third networks are 2D-CNN networks for use in implantable defibrillator devices. The innovation of the second and third networks is in addition to having a suitable percentage of accuracy, the high speed of the networks, and the possibility of saving the battery consumption of defibrillator devices. Neural networks used in implantable defibrillator devices must have high detection speed and optimal energy consumption in addition to having good detection accuracy. EGM signal processing neural networks designed in this article have accuracy percentages between 90% and 100%. Compared to other similar networks introduced in this article, they have more optimal detection speed and energy consumption because of the number of parameters or fewer layers.
In the second network designed in this study, the training accuracy percentage is 91%, and the test accuracy percentage is 100%. The network parameters and architecture have been selected to increase the accuracy percentage of the test data. Also, by reducing and controlling the number of test data to the standard level, the accuracy of the test data has increased. Still, we paid attention to the fact that the difference between the accuracy of the test and training data should not exceed 9%.
Various algorithms are designed for ICD devices, which have different accuracies during software design. Still, their accuracy is determined in practice when tested on patients' bodies after hardware implementation. Therefore, there is no predetermined acceptable accuracy for VT/VF signal detection algorithms, and the higher the accuracy percentage of the designed algorithm in the software part, the better. In contrast, the designed algorithm should have optimal speed and energy consumption. In the design of the networks of this research for use in ICD devices, a quorum for accuracy has been considered, and the accuracy percentage is between 90% and 100%. Also, the number of parameters and the number of network layers are such that the speed and accuracy of the networks are in good condition.
In future works, research can deal with the hardware implementation methods of designed neural networks, for example, work on the hardware implementation of designed networks on zynq chips with parallel processing capabilities. Hardware implementation on zynq chips increases the processing speed, and in parallel processing, if the number of layers is less, the network speed will increase. Memory limitations in hardware implementation should be examined because complex networks have a large number of parameters and will create hardware limitations, and a lot of memory should be considered for them. Therefore, another future work is to reduce the number of parameters and the number of layers of networks designed in this article, along with controlling the accuracy percentage.
ALIREZA KEYANFAR is currently a Researcher in the field of electrical engineering. His current research interests include deep learning on-chip, neural networks, image processing, machine learning, and embedded systems.
REZA GHADERI was born in Iran. He received the Ph.D. degree from the University of Surrey, U.K. His employment experience included working as an Associate Professor at the Faculty of Electrical Engineering, Shahid Beheshti University. His current research interest includes intelligent control systems.
SOHEILA NAZARI received the M.Sc. and Ph.D. degrees in electronic engineering from the Amirkabir University of Technology, Tehran, Iran, in 2014 and 2018, respectively. She has been an Assistant Professor with the Department of Electrical Engineering, Shahid Beheshti University, since 2020. Her current research interests include digital circuit design, signal processing, image processing, neuromorphic engineering, artificial intelligence, and bio-inspired pattern recognition.
BEHZAD HAJIMORADI is currently an Associate Professor at the Shahid Beheshti University of Medical Sciences. His current research interest includes processing of heart electrophysiology signals.
LEILA KAMALZADEH is currently a Researcher at the Cardiac Electrophysiology Research Center and the Rajaie Cardiovascular, Medical & Research Center, Iran University of Medical Sciences. Her current research interest includes processing of heart electrophysiology signals.