## 2 Algorithm Overview  
The proposed system consists of three main stages: ECG R-peak detection, feature extraction, and ECG arrhythmia detection, as shown in Figure 1.  
In the first stage, the ECG R-peak detection stage is responsible for signal preprocessing and R-peak detection. ECG signals are often contaminated by various types of noise in realistic environments, such as power line interference, electrode contact noise, motion artifacts, muscle contraction, and baseline drift [33]. Hence, the first step is to apply a bandpass filter with 1-40 Hz cutoff frequencies based on empirical results to the raw ECG signal, which isolates the predominant QRS energy centered at 10 Hz. For the R-peak detection, unlike other works [34; 35] that adopt the PAT (Pan and Tompkins) algorithm [36] as a way to detect R-peaks, the R-peak in this paper is detected by a Hilbert-based R-peak detection algorithm based on the algorithm in [37]. The overall algorithmic flow is shown in Figure 2.  
In order to reduce computational complexity and enhance energy efficiency, the following adjustments were implemented: the Shannon energy envelope was substituted  
Figure 1: Overall schematic representation of the proposed heartbeat arrhythmia detection flow. Figure 2: Block diagram of R-peak detection. by the energy envelope for forming a single-sided threshold mechanism and amplifying the QRS complexes; the zero-phase filter was replaced by the triangular wave filter for the smoothing of the extracted envelope; and the Hilbert transform was swapped by the Hilbert filter for converting peaks to positive zero-crossing points. The detailed explanation of the reasons for the modification and the corresponding proof (formula analysis, simulation results) are shown as follows:  
First, the Shannon energy envelope was substituted by the energy envelope. The energy value and the Shannon energy value of the differenced ECG signal are computed using the following equations: \(d[n]\) represents the differentiated ECG data, \(e[n]\) denotes the energy envelope, and \(s[n]\) represents the Shannon energy envelope. \[e[n]=d^{2}[n], \tag{1}\]  
\[s[n]=-d^{2}[n]\text{log}\,d^{2}[n] \tag{2}\]  
For hardware implementation, it is very difficult to calculate the log function in the Shannon energy envelope. Therefore, we chose the energy envelope, although this would sacrifice some performance. Second, the method of zero-phase filtering mentioned in the literature [37] was substituted by triangular window filters, which can make the envelope smoother and sharper. The specific method are to perform two forward and backward rectangular window filters on the data. The original data \(s\) is convolved with the rectangular window to obtain \(s^{\prime}\). The data of \(s^{\prime}\) is reversed to obtain \(s^{\prime}\), and then \(s^{\prime}\) is convolved again to obtain \(s^{\prime\prime}\). The filtered result is obtained by reversing \(s^{\prime\prime}\), as shown in the following equation. \[conv(s,h)\to s^{\prime}\to sr^{\prime}\to conv\big{(}s^{\prime},h\big{)}\to s ^{\prime\prime}\to y \tag{3}\]  
But the operation requires forward and backward filtering of the waveform data twice. In hardware implementation, a large amount of memory is needed to store the data to be reversed, which consumes a lot of hardware resources and affects the real-time performance of the algorithm. The time-domain calculation formula of the zero-phase filtering method is shown in the following equations. \[y_{1}(n)=x(n)*h(n), \tag{4}\]  
\[y_{2}(n)=y_{1}(N-n-1), \tag{5}\]  
\[y_{1}(n)=x(n)*h(n), \tag{6}\]  
Figure 2.0  
And the frequency domain response function is shown in the following equations. Figure 2.1  
Figure 2.2  
Figure 2.3  
Figure 2.4  
The final frequency domain transform can be obtained in the following equation. Figure 2.5  
The above equation shows that the unit-impulse response of the entire system is shown in the following equations. Figure 2.6The h(n) is a triangular window, and the h(\(-\)n) is also a triangular window.