# Automating Stimulation Frequency Selection for SSVEP-Based Brain-Computer Interfaces
## 4 BCI Frequency Selection Coefficients  
To quantitatively assess the characteristics of the user's reaction to the photostimulus that we have described and to obtain a list of recommended frequencies, we introduce a set of coefficients:  
1. Reaction speed coefficient \(K_{sp}\);
2. Threshold overcoming coefficient \(K_{o}\);
3. Frequency applicability coefficient \(K_{fa}\);
4. Discomfort coefficient \(K_{d}\). As mentioned above, when presenting a photostimulus with the frequency \(f\), we analyze the user's reaction, not only at the fundamental frequency but also at the second harmonic frequency. We will denote these frequencies as \(f_{st}\) and \(f_{nd}\) for the fundamental and second harmonic frequencies, respectively. Thus, coefficients 1 to 3 will be calculated in two instances for each photostimulus. The first three coefficients are calculated for occipital EEG leads O1, O2, and Oz, since these are the leads in which the SSVEP potential appears in response to the presented photostimulus. To obtain these coefficients, it is necessary to calculate the SNR and the threshold values for both \(f_{st}\) and \(f_{nd}\) frequencies. The SNR of the EEG signal at frequency \(f\) is calculated by the following expression [31]:  
\[SNR(f)=\frac{K*M(f)}{\sum_{n=1}^{K/2}\{M(f+n\Delta f)+M(f-n\Delta f)\}} \tag{1}\]  
where \(M(f)\) is the signal magnitude at frequency \(f\), obtained as a result of the calculation of a single-sided FFT, \(K\) = 4 is the total number of harmonics around \(f\) in the signal spectrum considered as noise, and \(\Delta f\) is the frequency resolution. During the presentation of each 60 s photostimulus, we record a fragment of the EEG signal and then divide it into a set of windows of 3 s durations and 50% overlap between the windows. For each obtained window, we compute the SNR at frequencies of \(f_{st}\) and \(f_{nd}\) using Equation (1), thus obtaining two vectors to demonstrate how the SNR for frequencies \(f_{st}\) and \(f_{nd}\) changed during the photostimulation. To compute the threshold value, we take a fragment of the EEG signal, where no photostimuli or any other stimuli or artifacts are presented. As in the previous example, this fragment is divided into 3 s windows set with 50% overlap between the windows. For each obtained window, the SNR vectors for frequencies \(f_{st}\) and \(f_{nd}\) are calculated using Equation (1). Then, to obtain the threshold values for \(f_{st}\) and \(f_{nd}\) frequencies, we use the following expression:  
\[SNR_{t}(f)=SNR_{m}(f)+k*SNR_{sd}(f) \tag{2}\]  
where \(SNR_{m}\) is the mean value of SNR for the obtained windows at frequency \(f\), \(SNR_{sd}\) is the standard deviation of SNR at frequency \(f\), and the coefficient \(k\) is equal to 3. Thus, if we consider the value of the SNR at a given frequency outside the stimulation period as a random variable, and then apply the three-sigma rule to it, we will obtain a threshold value. Exceeding this threshold with a probability of 99.7% would not occur under normal conditions (without the presentation of photo stimuli). After computing these parameters, the coefficients we proposed can be computed. The response speed coefficient \(K_{sp}\) represents how fast the SSVEP potential's \(SNR\) value at frequency \(f\) reaches the \(SNR_{t}\) threshold value, where it can be recognized in the BCI. This coefficient is computed by Equation (3) for frequencies \(f_{st}\) and \(f_{nd}\), and takes values from 0 to 1, where values close to 1 mean the fastest responses and values close to 0 mean the slowest responses. Coefficient values equal to 0 indicate a complete absence of reaction.