# Classification of Sleep Stage with Biosignal Images Using Convolutional Neural Networks
## 4 Sleep-Stage Classification Using CNN
### Preprocessing and Input Data  
The Sleep-EDfx includes EEG, EOG, EMG, snoring, and other physiological signals generated by body and brain activities. EEG, which is recorded neuronal activity evaluation during sleep, is widely adopted for sleep-stage classification. However, the biosignals are distorted by several artifacts such as electrode movements and power line noise. The attenuation or removal of unwanted and noisy signals is a prerequisite for most signal processing applications. The artifacts can be affected by misinterpretation and accuracy and the experimental results are also distorted. Therefore, preprocessing is necessary to remove artifacts and normalize the information contained in the biosignals. In the preprocessing step, data pruning and normalization are executed after extracting EEG and EOG signals from the Sleep-EDFx dataset. In the Sleep-EDFx, artifacts or missing data were found in the beginning or at the end of recordings and in the middle of the recordings. In these cases, data loss could affect sleep-stage classification for the specific epochs. An epoch is a time unit for classifying sleep stages and has a duration of 30 s, so EEG and EOG biosignals are divided equally in the 30-s units. After removing the corrupted epochs in the recorded EEG and EOG signals, corresponding epochs are removed from the hypnogram to synchronize the signals. After that, the signals are normalized based on the maximum and minimum values of the signals over time. Since the biosignals are very weak with low voltage, they are greatly affected by body contact or the surrounding environment, so normalization is required to improve the performance of the sleep-stage classification. The signals are scaled to a fixed range of [0 1]. Normalized signals are divided into each epoch. In the proposed method, 2D images instead of conventional 1D signals are used as an input to the CNN for sleep-stage classification. Many researchers have tried to find dominant features to improve their accuracy. Therefore, several feature-extraction and selection methods have been proposed to improve the accuracy of classification. However,the proposed method eliminates the need for manual feature-extraction and selection, while taking advantage of the advancements in image classification using deep learning. The signal data in the time and frequency domain in each epoch were converted to 2D binary images. The converted images were intuitive and interpretable for somnologists. These images were fed to a CNN for training and testing. The preprocessed EEG and EOG data were converted into graph images in the time domain and the frequency domain. The sampling frequency of each signal was 100 Hz. The images in the time domain were made with EEG or EOG values according to the sampling order. To extract the frequency information for the EEG and EOG signal in each epoch, the signal was transformed to the frequency domain using Fast Fourier Transform (FFT). Since the signal was sampled at 100 Hz, one 30-s epoch had 3000 value points. After the FFT, only 1000 coefficients at low frequencies of the 3000 coefficients were used to exclude the effects of high frequencies. The amplitude spectrum is an image in the frequency domain. The images in the time domain and the frequency domain were converted to 2D binary images whose resolutions were 432 \(\times\) 288. To minimize the computation cost, the final image resolution was set to 216 \(\times\) 144, which is the size of the CNN input after resizing the image. Figure 2 shows typical sample images of the time domain and the frequency domain for each stage. The images of the EEG are in Figure 1(a) and the images of the EOG are in Figure 1(b). Figure 2: Images of time domain and frequency domain for each sleep stage: (**a**) EEG; (**b**) EOG. For the EEG images in the time domain, the image of S1 has a smaller amplitude than that of S2, and SWS shows a waveform with a larger amplitude. In the frequency domain, the EEG image of S2 shows various frequency waveforms with irregular periods.