# Real-Time Localization of Epileptogenic Foci EEG Signals: An FPGA-Based Implementation
## 3 Hardware Implementation and Computational Method
### Computation of the RT-EPI Algorithm
#### 3.4.1 Algorithm Description
All the feature extraction algorithms and classification models were implemented using Matlab R2018a and the \"Statistics and Machine Learning Toolbox.\"

The first goal was to find the classification procedure with the lowest computing cost, because of the real-time implementation aim. Thus, we had to be find (1) a set of features with the minimum number of features and minimum computing cost, using (2) the simplest classifier model, and (3) the optimum segment length. A minimum classification accuracy of 95% was required, a value above the average of related works in the bibliography. To do so, all considered features, Table 1, were ranked by discrimination capacity and by computational cost. Then, different classification procedures were checked in a loop. At each iteration of the loop, a combination of features were selected (taking into account the ranks); then, fed to 24 classification models, Table 3; and finally the classification accuracies for different segment lengths were calculated. The loop finished when the smallest set of features reached 95% of classification accuracy on at least one of the classification models. Once the classification procedure was defined, it was coded in C using Xilinx Vivado HLS and the Xilinx Vivado Design Suite 2016.2 [42]. These tools were also used to carry out synthesis, simulations and cosimulations. The Xilinx Virtex-7 XC7 VX1140T FPGA device was selected for synthesis and implementation, because it is a biggest Virtex-7 device that permits implement the application without resource restrictions. The coded design is parameterizable, and follows a pipelined and sequential architecture that computes (Algorithms 1 and 2) all the classification procedure from accepting the raw signal to the delivery of the classifier output. The reported analyses were conducted using two different arithmetic precisions: a 32-bit floating-point algorithm (\"single\" design), and 64-bit floating-point algorithm (\"double\" design). Both implementation designs used the IEEE 754 standard. ### Set of Features and Classification Model

The RelieF algorithm was used as feature extraction algorithm. RelieF returns a rank of features and its weights to represent the discrimination capacity of these features. These ranks and weights were used to select the relevant set of features, along with the computational cost criteria, optimizing the real-time implementation of the application. The number of selected features was defined as the minimum set of features that allowed us to obtain a minimum threshold of 95% classification accuracy on at least one of the classification models (Table 3). To determine the best classification model, 24 classification models were tested. Table 3 lists all these models along with their prediction speed and memory usage characteristics. Note that only those classification models with low or medium speed and memory usage were chosen, due to the importance of minimizing these parameters in the real-time implementation. All classification models were trained with several sets of features, seeking to determine the feature set and classification model at the same time. However, the evaluation of the classification models depends on a third parameter: the window length. Figure 2 shows the accuracy results for the selected sets of features (Table 2), for all the classification models and the variations of the window length from 1 to 10 s. Note that this figure only shows the best score for the neural network classification model. Figure 3 details the classification accuracy obtained using different numbers of neurons for the hidden layer. Thus, five features were finally selected, those in Table 2, to be used with a neural network as the classification model. As it can be seen, the computational cost of the five selected features is low (case of features derived from the temporal domain) or medium (in the case of frequency domain features, where it is necessary to compute the Fourier transform).