# Multi-Class Sleep Stage Analysis and Adaptive Pattern Recognition
## 2 Methods
### Pattern Matrix Construction  
The classification of sleep stages was based on time segments 30 s long with the corresponding target classes specified by the neurologist during the learning process after the preceded signal preprocessing stage. This initial process included digital filtering for noise rejection and artefact removal [41; 42]. Common preprocessing methods include the rejection of noise components present in each individual channel. Denoting a channel signal by \(\{x(n)\}_{n=0}^{N-1}\), it is possible to use a selected digital filter with specified cutoff frequencies to define a new sequence \(\{y(n)\}_{n=0}^{N-1}\). Finite impulse response (FIR) band pass filters of the 30 th order were used in this case. Their cutoff frequencies corresponded \begin{table}
\begin{tabular}{c c c c c} \hline \hline  & \multicolumn{3}{c}{**M-Male**} \\ \cline{3-5}  & \multirow{2}{*}{**Diagnosis**} & \multicolumn{2}{c}{**Number**} & \multicolumn{2}{c}{**Mean Age (Year)**} & \multicolumn{1}{c}{**STD**} \\ \hline
1 & Healthy individuals & 36 & 40.0 & 15.9 \\
2 & Sleep Apnea (SA) & 48 & 50.3 & 14.2 \\
3 & Restless Leg (RL) Syndrome & 8 & 59.9 & 9.1 \\
4 & SA and RL Syndrome & 19 & 58.3 & 9.0 \\ \hline \hline \multicolumn{5}{c}{**F: Females**} \\ \cline{3-5}  & \multirow{2}{*}{**Diagnosis**} & \multicolumn{2}{c}{**Number**} & \multicolumn{2}{c}{**Mean Age (Year)**} & \multicolumn{1}{c}{**STD**} \\ \hline
1 & Healthy individuals & 27 & 40.8 & 14.7 \\
2 & Sleep Apnea (SA) & 29 & 54.7 & 14.4 \\
3 & RL Syndrome & 8 & 48.9 & 12.6 \\
4 & RL Syndrome and SA & 9 & 52.7 & 20.4 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Specification of the set of 184 individuals under study (M: number of males, F: number of females) with their age distribution, including (i) healthy individuals; (ii) individuals with sleep apnea (SA); (iii) individuals with the restless leg (RL) syndrome; and (iv) individuals with RL syndrome and sleep apnea syndrome  
Figure 3: Two-hour long analysis presenting (**a**) EEG signal segmented into 5 classes and (**b**) features standing for the mean power in selected frequency ranges (1–4 Hz, 4–8 Hz) in subsequent 30 s long windows forming neural network pattern values; (**c**) target sleep classes forming desired neural network output; (**d**) probabilities of evaluated classes by the two layer neural network; and (**e**) resulting classes with the highest classification probability. with the frequency ranges of specific PSG channels used for classification. The selection of these frequencies was related to the physiological background of these signals and it included frequency ranges \(\langle 0.5,30\rangle\) Hz for EEG channels, \(\langle 0.05,0.8\rangle\) Hz for the flow channel, and \(\langle 4,40\rangle\) Hz for the EOG channel. A selected spectral feature \(FS\) of a signal segment was evaluated by the discrete Fourier transform as a relative power in the specified frequency band \(\langle f_{c1},f_{c2}\rangle\) by relation  
\[FS\!=\!\frac{\sum_{k\in\Phi}|Y(k)|^{2}}{\sum_{k=0}^{N/2}|Y(k)|^{2}},\quad Y(k )\!=\!\sum_{n=0}^{N-1}y(n)\ e^{-jkn\frac{2\pi}{N}} \tag{1}\]  
where \(\Phi\) is the set of indices for which frequency values \(f_{k}=\frac{k}{N}f_{s}\in\langle f_{c1},f_{c2}\rangle\). The construction of the pattern matrix \(\mathbf{P}_{R,Q}\) presented in Figure 1b assumes the evaluation of \(R\) features for each signal segment for \(k=1,2,\cdots,Q\), forming \(Q\) column vectors \(\mathbf{p}(:,k)\) of \(R\) values. As the length of each PSG segment is 30 s, the whole overnight record about 8 h (480 min) long includes on average \(Q=960\) segments for each individual. Each segment is described by \(R\) features that represent characteristics evaluated mostly in the time or frequency domains for one or more observed variables. Figure 3b presents an example of a distribution of EEG features evaluated from one EEG channel only, specifying the average power in selected frequency bands (1-4 and 4-8 Hz).