# A Low-Power ECG Processor ASIC Based on an Artificial Neural Network for Arrhythmia Detection
## 3 System Modules
### Classification Engine
On one hand, the size of the hidden layer is an important parameter of ANN, which has a critical impact on the classification accuracy. On the other hand, by reducing hidden layer neurons while ensuring acceptable accuracy, the computation complexity and memory overhead can be reduced, resulting in less computing time and low energy consumption. We used grid search to try different hidden layers; as shown in Figure 7a, the computing time is estimated by the number of processing clock cycles required by PU. A hidden layer with eight neurons is selected because the model achieves a good trade-off, with \(\mathrm{R^{2}}\) scores of 0.935 for training and 0.932 for testing. The loss curve for the proposed NN is shown in Figure 7b. The confusion matrix containing the prediction results is shown in Figure 8, and the overall classification accuracy is 96.69%. The sensitivity and positive predictive value (PPV) of each type are summarized, as shown in Table 2.  
Figure 8: The normalized confusion matrix. Figure 7: (a) Accuracy and computing time of models with different hidden layers. (b) The loss curves. The proposed classification ANN model is described in Verilog HDL for hardware implementation. Note that the hardware computing time of the ANN should be within a reasonable range, which determines the minimum clock frequency. According to the work process of this design, once an R-peak is detected, a classification of the heartbeat centered at the previous R-peak is performed subsequently. Considering that the maximum heart rate in extreme cases is 220 bpm, the minimum time interval between the two R-peaks is 272 ms. To obtain the results report of each heartbeat, it is necessary to leave a time margin for other processing and UART data transmission; thus, the time for each inference in this design should not exceed 100 ms.  
Due to the fact that the storage and computation of fixed-point values require fewer hardware resources compared to floating-point values, the weights and biases obtained from training are converted into a 16-bit fixed-point format with a 1-bit sign, a 7-bit integer, and 8-bit decimals. PU is the basic computing unit in the classification engine; Figure 9 shows its schematic structure. It has two functions that can be switched through the Add_sel signal: (1) Multiply-Add: \(\rm I\times W+B=O\); (2) Multiply-Accumulate: \(\rm I\times W+O(i-1)=O(i)\). The first function is to add the product of the input feature values and weights with the bias values. And the second function is to accumulate the current product with the output value generated by the last operation, which is used to process the accumulation of the products. The partial sum register can be initialized to 0 through the Clear signal. The feed-forward inference computation of ANN is completed by reusing the PU to serially process neurons, which is controlled by an FSM, as shown in \[\rm{f(H_{Nk})}=max\ (0,\ H_{Nk}), \tag{7}\]0 When the transmission from the data handler to the input feature buffer is finished, the startup signal is set to high to activate the FSM. In the DATA_REQ state, the ecg_req and param_req signals are set to one to require input feature values and NN parameters. The computation of each neural network layer is divided into four steps. Taking the hidden layer as an example: (1) In the BIAS_UPDATE1 state, the bias register is updated to the corresponding bias value of the currently processed neuron; (2) The computing of input feature values and weights is completed in the HIDE_COMPU state. The input_cnt signal is responsible for counting the number of input values; when input_cnt is equal to the length of the input feature, indicating that all input values of one neuron have been calculated, then the state jumps to HIDE_STORE; (3) The ReLU operation is performed in the HIDE_STORE state, which is implemented by comparing the signed bit of the previous output values of the PU.