# Online EEG Seizure Detection and Localization
## 2 Materials and Methods
### Distance Network  
During the progression of a seizure, because of hypersynchronization, the similarity between the signals from neighboring EEG leads is expected to increase. We define a distance between two EEG leads, or channels, as the Euclidean distance between the FFT coefficients that correspond to the high gamma band. A matrix of size \(K\times N\) is generated where K is the number of channels and \(N\) is the number of FFT coefficients in the high gamma band. A \(K\times K\) distance matrix \(D\) is obtained by calculating the Euclidean distance between frequency components in a band for each pair of channels.  
Assuming these distances reflect the synchronicity between the neuronal areas observed by electrode pairs, we expect to observe a close relation (lower distance) and a sudden increase in the closeness of channels during the preictal to ictal transient period. We define a normalized distance (\(D_{N}\)) matrix  
\[D_{N}=\ \frac{D-D_{min}}{D_{max}-\ D_{min}}, \tag{5}\]  
where \(D_{max}\), and \(D_{min}\) are the maximum and minimum distances in the epoch, respectively. The normalized values lie between 0 and 1. A threshold of 0.1 is chosen to capture more than 90% similarity between a pair of electrodes. A pair of channels with a distance less than the threshold is assumed to be connected and an edge is created between the two nodes (EEG electrodes). Hypersynchronization during a seizure means that the number of connections in this network, which we call the distance network (DN), will increase as the seizure progresses. Therefore, a measure of hypersynchronization in a region of the brain is the number of possible connections which are activated. Letting \(R\) be the number of pairs of channels in a particular region with distance less than the threshold, and letting \(T\) be the total number of pairs of channels in the region, then we define the connection ratio CR as  
\[CR=\frac{R}{T}. \tag{6}\]  
If there are \(n\) channels in a region, the total number of possible connections in a region, \(T\), is \(\left(\begin{array}{c}n\\ 2\end{array}\right)\). The EEG channels are divided into eight regions: right and left hemispheres, frontal, temporal, parietal, and occipital lobes, in addition to the central region and the general region, which consists of all of the EEG channels.  
The connection ratio is evaluated after sensing an abnormality activity using the PBI method. To determine a transition from a preictal to ictal period, the DN is studied in the high gamma band. An example of this increase in the connection ratio during transition from preictal to ictal is shown in Figure 3. Figure 3a shows the DN at an epoch before a seizure start, and Figure 3b,c shows the increase in connections as the seizure progresses. The connection ratio in a region should be greater than 0.2 in order to declare a focal seizure in a region. A generalized seizure covers more than a focal seizure. Note that we only compute the connection ratio if the PBI measure indicates the possibility of a seizure. The background color of the DN schematic, displayed in Figure 3a-c, shows the relative power of the channels, with darker red regions indicating higher brain activity.  
The DNs indicate the increase in closeness and model a spreading seizure in the brain. However, this approach is not capable of locating the origin of a seizure. For locating the focus of a seizure, the CN is generated.