# Automating Stimulation Frequency Selection for SSVEP-Based Brain-Computer Interfaces
## 4 BCI Frequency Selection Coefficients
\[K_{sp}(f)=1-\frac{T_{SNR}(f)}{t} \tag{3}\]  
where \(T_{SNR}(f)\) is the time in seconds from the start of the photostimulus presentation to the first overshoot of \(SNR_{t}(f)\), and t is the total duration of the stimulation, which, in our case, is equal to 60 s.  
The threshold overcoming coefficient \(K_{o}\) represents how stable during the presentation of the photostimulus the SSVEP potential exceeds the threshold value \(SNR_{t}\) at the given frequency. This coefficient is computed by Equation (4) for frequencies \(f_{st}\) and \(f_{nd}\), and takes values from 0 to 1, where values close to 1 mean the most stable responses and values close to 0 mean the most unstable responses. Coefficient values equal to 0 indicate a complete absence of reaction. \[K_{o}(f)=\frac{N_{o}(f)}{N} \tag{4}\]  
where \(N_{o}(f)\) is the number of windows at which \(SNR\) at frequency \(f\) exceeds the threshold value \(SNR_{t}(f)\), and \(N\) is the total number of windows during stimulation. The windows were selected in the same manner as for Equation (1). The frequency applicability coefficient \(K_{fa}\) is introduced to combine the coefficients \(K_{sp}\) and \(K_{o}\) into a single coefficient. The coefficient \(K_{fa}\) shows how generally suitable the selected frequency is for the fast and stable recognition of the photostimulus frequency \(f\) in BCIs. This coefficient is calculated for frequencies \(f_{st}\) and \(f_{nd}\) by Equation (5) and takes values from 0 to 1. Coefficient values close to 1 mean the most optimal in terms of speed and stability of frequency response, and values close to 0 mean the most suboptimal. \[K_{fa}(f)=K_{sp}(f)*K_{o}(f) \tag{5}\]  
where \(K_{sp}(f)\) denotes the response speed coefficient at frequency \(f\), and \(K_{o}(f)\) is the threshold overcoming coefficient for frequency \(f\). The average frequency applicability coefficient \(K_{fa}\) is calculated by taking the average of the two \(K_{fa}\) coefficients obtained for the photostimulation at frequency \(f\) using Equation (6). This coefficient takes values from 0 to 1 and represents how capable the photostimulus is to evoke a high-quality SSVEP response at both the fundamental and second harmonic frequencies simultaneously. Values close to 1 mean the stimulation frequencies with the highest quality SSVEP response in terms of the speed and stability of the frequency response at the first two harmonics. \[K_{fa}(f)=\frac{K_{fa}(f_{st})+K_{fa}(f_{nd})}{2} \tag{6}\]  
where \(K_{fa}(f_{st})\) represents the applicability coefficient of frequency \(f\) at the fundamental harmonic, and \(K_{fa}(f_{nd})\) represents the applicability coefficient of frequency \(f\) at the second harmonic. The discomfort index was defined as a ratio of absolute theta power (4-8 Hz) divided by absolute beta power (13-30 Hz) averaged over F3 and F4 frontal electrodes, capturing the neural signals coming from the left and right hemispheres, respectively (Equation (7)). To extract EEG powers in the above-mentioned frequency bands, fast Fourier transform (FFT) was applied (Hanning window length 10) in the MNE Python. \[DI(f)=\left(\frac{\sum_{n=4}^{8}(M_{F3}(n,f))^{2}}{\sum_{n=13}^{30}(M_{F3}(n,f)) ^{2}}+\frac{\sum_{n=4}^{8}(M_{F4}(n,f))^{2}}{\sum_{n=13}^{30}(M_{F4}(n,f))^{2}} \right)*0.5 \tag{7}\]  
where \(DI(f)\) denotes the discomfort index for the frequency of photostimulation \(f\), \(M_{F3}(n,f)\) and \(M_{F4}(n,f)\) are the signal magnitudes at frequency \(n\) from electrodes F3 and F4, respectively, during light stimulations at frequency \(f\). The discomfort coefficient \(K_{d}\) is introduced in order to normalize the discomfort index \(DI\) in the range of 0 to 1 and is intended to standardize this indicator for different subjects when using our developed application for selecting recommended frequencies. This coefficient is calculated using the min-max normalization formula and takes values from 0 to 1, where values close to 1 indicate the highest level of discomfort, and values close to 0 indicate the lowest level of discomfort.