# 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
\(\mathbf{W}_{h}{}_{\left({{}_{1\times{}}{\rm{IN}}}\right)}\rightarrow\) Hidden layer weights matrix. \(\mathbf{b}_{h}{}_{\left({{}_{1\times{}}{\rm{IN}}}\right)}\rightarrow\) Hidden layer bias. \(\mathbf{W}_{o}{}_{\left({{}_{1\times{}}{\rm{IN}}}\right)}\rightarrow\) Output weights matrix. \(\mathbf{b}_{o}{}_{\left({{}_{1\times{}}{\rm{ON}}}\right)}\rightarrow\) Output layer bias. \(\mathbf{x}_{\left({{}_{1\times{}}{\rm{ON}}}\right)},\ \mathbf{x}_{\left({{}_{1\times{}}{\rm{ON}}}\right)}\rightarrow\) Output denormalization vectors. ```
0:\(\mathbf{y}_{\left({{}_{1\times{}}{\rm{ON}}}\right)}\). 1:\(\mathbf{x}_{\left({{}_{1\times{}}{\rm{IN}}}\right)}=\dfrac{\left(y_{max}-y_{ min}\right)\cdot\left(\mathbf{x}^{\prime}-\mathbf{x}_{\left({{}_{1\times{}}{\rm{IN}}} \right)}\right)}{\mathbf{x}_{\left({{}_{1\times{}}{\rm{IN}}}\right)}-\mathbf{ x}_{\left({{}_{1\times{}}{\rm{IN}}}\right)}}+y_{\left({{}_{1\times{}}{\rm{IN}}}\right)}\). 2:\(\mathbf{tmp1}_{\left({{}_{1\times{}}{\rm{IN}}}\right)}=\mathit{Tansig}(\ \mathbf{x}_{\left({{}_{1\times{}}{\rm{IN}}}\right)}\mathbf{y}_{\left({{}_{1 \times{}}{\rm{IN}}}\right)})\). 3:\(\mathbf{tmp2}_{\left({{}_{1\times{}}{\rm{ON}}}\right)}=\mathit{Tansig}( \ \mathbf{tmp1}\cdot\mathbf{W}_{o}+b_{o}\ ).\)
4:\(\mathbf{y}_{\left({{}_{1\times{}}{\rm{ON}}}\right)}=\dfrac{\left(\mathbf{tmp1}-y_{ min}\right)\cdot\left(\mathbf{x}_{\left({{}_{1\times{}}{\rm{IN}}}\right)}\right)}{y_{ max}-y_{\left({{}_{1\times{}}{\rm{IN}}}\right)}}+\mathbf{x}_{\left({{}_{1 \times{}}{\rm{IN}}}\right)}\). ```

**Algorithm 2** Classification of an input pattern. pseudocode

#### 3.4.2 Design Considerations

The proposed design allows the definition of IEEE 754 floating point units using single or double data type precision. This selection together with the parametric definition of the SLFN neural network permits one to test the design in different conditions with few code modifications. The activation function implemented in this design was the hyperbolic tangent sigmoid. On the other hand, the proposed design uses pipelining. The main reasons for that is that pipelining alleviates the great latency involving the use of floating point operations, and the suitability of the algorithm for its use, since most of the steps of Algorithms 1 and 2 can be implemented with _for_ loops or nested _for_ loops. The pipelining technique helps to optimize the initiation interval, defined as the number of clock cycles that must occur before a new input can be applied. Thus, the initiation interval becomes the parameter to optimize, and the effort must focus on approximating it to one as much closely as possible. To carry this out, we used the PIPELINE optimization pragma directive in each step of the computational procedure implemented using _for_ loops. This generates a pipeline design with an initiation interval as low as possible, which dramatically reduces the total latency of the loop implementation. In addition, the clock period target was set to 4 ns. This forces the compiler to obtain the fastest hardware implementation. Take into account that both the above design considerations and the computational procedure described in Algorithms 1 and 2 must be followed to replicate the implementation results in this work. ## 4 Results

The analysis described in this work was carried out using the Bern-Barcelona dataset (Section 2.1). The first 50 focal and non-focal register pairs of the dataset were used. As all considered features are univariate, and 40 s of EEG signals are available in each register pair (20 s \(\times\) 2), a total of 4000 s of EEG signals were considered in this study. In order to better compare our results with the results provided by previous works, we used five-fold cross validation in our experimental procedure. In this approach, the EEG signals are divided randomly into five equal portions. Four out five portions were considered for training and the rest, half for validation and half for testing.