# Online EEG Seizure Detection and Localization
## 2 Materials and Methods
### Correlation Network  
The PBI and DN measures are used to detect the presence of a seizure. On the basis of the neuronal hypersynchronization during the ictal period [5; 6], another network of EEG channels similar to DN is generated for locating the origin of a seizure. In this network, we use correlation between the channels to determine connectivity. While correlation between EEG channels is not restricted to the ictal period, assuming that the correlation of a pair of channels reflects their synchronization, we expect to observe a higher correlation among synchronized electrodes in a seizure region (and neighboring regions) during an ictal period. After pre-processing and filtering an epoch of an EEG signal into a frequency band, a \(K\times K\) (\(K\) = number of electrodes) matrix of Pearson correlations is generated by calculating correlation coefficients of pairs of channels. The Pearson correlation between channel A and B can be calculated by Equation (7). \[\rho(A,B)=\frac{1}{N-1}\sum_{i=1}^{N}\left(\frac{A_{i}-\mu_{A}}{\sigma_{A}} \right)\left(\frac{B_{i}-\mu_{B}}{\sigma_{B}}\right), \tag{7}\]  
where \(N\), represents the number of FFT frequency components, \(\mu_{\rm A}\) and \(\mu_{\rm B}\) represent the averages of FFT components in channels \(A\) and \(B\), and \(\sigma_{\rm A}\) and \(\sigma_{\rm B}\) represent the standard deviations of the spectral components in channels \(A\) and \(B\). The closeness (C) factor of channels A and B is defined by Equation (8). \[C_{A,B}(t)=\sqrt{\rho(A,B)^{2}+\left(\frac{P_{E,N}(t,A)+P_{E,N}(t,B)}{2} \right)^{3}}, \tag{8}\]  
where \(P_{E,N}(t,A)\) and \(P_{E,N}(t,B)\) are the normalized power obtained using Equation (1) normalized by the maximum power of a channel in that epoch. Therefore, \(P_{E,N}(t,A)\) and \(P_{E,N}(t,B)\) are in the range of [0, 1]. Channel synchronization should have more impact on their closeness (C). A high correlation coefficient of a pair of channels indicates a possible hypersynchronization of channels. In this formula, the correlation coefficient is raised to the second power while the average channel power (\(P_{E,N}(t,A)\) +\(P_{E,N}(t,B)\))/2 is raised to the third power. As each of these terms has a value less than one, this accentuates the effect of the correlation coefficient with respect to the average power in Equation (8). To define a connection in a correlation network, a threshold of 0.85 is used: Two electrodes are connected if their closeness (C) factor is greater than 0.85. Connected electrodes generate a CN. The edges of the CN are normalized by the maximum edge (with maximum closeness (C)) of the same network. The normalized edges determine the relative degree of closeness of two channels. Figure 3: The transition of the distance network (DN) from preictal to ictal. DN networks of (**a**) an epoch before the seizure, (**b**) beginning of the seizure, and (**c**) an epoch after the seizure start. Figure 4 demonstrates a CN generated at the beginning epoch of a seizure. The higher the closeness of electrodes, the darker and thicker the connections. The strength of connections in a brain region is defined as the average of the two strongest (closest) connections in the corresponding region. The type and the focus of the seizure can be identified by the CNs. If a seizure spread rapidly in brain regions and covers most of the brain at the beginning of the seizure, it is considered to be a generalized seizure; otherwise, it is most likely to be a focal seizure. The rapid spreading of the seizure at the beginning is captured by the number of connected edges. If more than half (60%) of the electrode pairs are connected at the beginning of a seizure, the seizure is determined to be a generalized seizure; otherwise, it is considered a focal seizure. To locate the origin of a seizure, the 10-second epoch in which the seizure is determined to have begun--which has been determined by the PBI and DN methods--is divided into 2-second sub-epochs with a 1 s overlap between sub-epochs, resulting in nine 2-second sub-epochs.