# Spectral Analysis of Electroencephalographic Data in Serious Games
## 3 Materials and Methods
### Signal Processing  
In a wide range of applications, e.g., epileptic seizure detection or prediction, sleep state classification, motor imagery classification, emotion recognition, and mental task classification, digital signal processing of EEG plays an important role [62]. Most valuable  
Figure 4: Unipolar electrode configuration for measurement of brain activity.  
Figure 3: Arrangement of the eight-channeled EEG system.  
knowledge about the functional stale of human brain information is encoded within six major brain waves, differentiated by their frequency bands. Thus, EEG signal is usually analyzed in the time-frequency domain utilizing the Short-Time Fourier Transform or a Wavelet Transform. We can decompose the EEG signal into different frequency components; delta (1-4 Hz), theta (4-8 Hz), alpha (8-12 Hz), beta (13-30 Hz), gamma (30-80 Hz), and high-frequency gamma waves (\(>\)80 Hz). [63] However, the exact frequency ranges associated with these terms differ across studies.  
The Power Spectral Density (PSD) refers to the distribution of the signal power over the frequency. The PSD estimation \(P\) of the random process is defined as follows  
\[P=\frac{1}{N}|X[k]|^{2}, \tag{1}\]  
where \(N\) is the number of signal samples and \(X[k]\) is a Discrete Fourier Transform (DFT) of the discrete input signal \(x[n]\)  
\[X[k]=\sum_{n=0}^{N-1}x[n]e^{\frac{-2\pi}{N}kn}, \tag{2}\]  
where \(k\) is the frequency bin number and \(n\) is the discrete time. The \(k\) index in Equations (1) and (2) can be recalculated to frequency \(f\) by using the following formula  
\[f=k\frac{f_{s}}{N}[Hz], \tag{3}\]  
where \(f\)s is the sampling frequency.  
The Equation (1) is known as a periodogram (Schuster method), which computes PSD for the entire signal. Ref. [64] The Welch method is an improvement on the periodogram--the signal is split up into \(K\) overlapping segments, which are then windowed. After that, the partial periodograms \(P_{i}\) are calculated by using Equation (1) for each segment. The partial periodograms are then averaged, which reduces the variance of the individual power measurements.  
\[\text{PSD}=\frac{1}{K}\sum_{i=0}^{K-1}P_{i}(k). \tag{4}\]  
The short-time Fourier transform (STFT) is used to analyze non-stationary signals (EEG, ECG, speech, etc.) when the statistical parameters are change over time. The use of DFT does not allow the investigation of spectrum changes over time. The STFT is able to determine the frequency spectrum of the signal as it changes over time. The STFT can be defined with the help of DFT as follows  
\[X[m,k]=\sum_{n=0}^{N-1}x[n+mR]w[n]e^{-j\frac{2\pi}{N}kn}, \tag{5}\]  
where \(x[n]\) is the discrete input signal amplitude at discrete time n,  
\(N\) is the number of discrete-time samples,  
\([n]\) is the window function with a length of \(N\),  
\(X(m,k)\) is the spectrum of windowed signal \(x\) at a discrete frequency \(k\),  
\(R\) is the hop size (in samples) between successive DFTs,  
\(m\) is the index of a window from 0 to \(M-1\), where \(M\) is a number of windows.  
The \(k\) index in Equation (5) can be recalculated to frequency \(f\) using the Equation (3). Similarly, the \(m\) index can be changed to time \(t\) in seconds  
\[t=m\frac{N}{f_{s}}[s]. \tag{6}\]The spectrogram is a graphical interpretation of STFT. The spectrogram can be defined as  
\[\text{spectrogram}=10\;log_{10}|\text{STFT}|^{2}[\text{dB}]. \tag{7}\]  
The spectrogram presents the power spectrum of the signal as a function of time. The decadic logarithm is used to decrease the dynamic range of values; therefore, the resulting spectrogram is in decibel (dB) units.  
A group of signal features was derived from the power spectra estimates during the resting phase and gameplay. The subjects have been classified by utilizing the k-means clustering algorithm into three groups based on those extracted features. The k-means algorithm iteratively allocates all observations to the nearest cluster while reducing the intra-cluster dimension (e.g., squared Euclidean distance) [65].