Sleep spindles (SS) generated from complex interactions between thalamic, limbic and cortical areas are the hallmarks of the non-REM stage 2 sleep (N2). They are sinusoidal spindle-like waveforms which have the characteristic of progressively increasing, then gradually decreasing lasting 0.5~3s with a frequency profile at 11 - 16 Hz. The figure characteristic of the waveforms is obvious .
Apart from being the characteristic wave of the sleep stage, sleep spindles also have great relationships with human activities. Studies  have founded that during sleep, the more sleep spindles exist, noises can be more tolerated and the deep sleep can be more easily kept. Moreover, they are known to play a fundamental role in memory consolidation during sleep , as well as being related to the secretion of melatonin that helps in maintaining the body’s circadian rhythms . Therefore, detecting the sleep spindles rapidly and efficiently has a great value in physiological, pathological and pharmacological studies during sleep.
Detecting sleep spindles by man is a time-consuming and laborious work with many uncertainty factors and prone to human error. The study  has indicated the inter-rater variability in scoring them to be around 80%.
Since the EEG was first detected, scholars have applied various signal analysis methods to the EEG analysis. Time-domain method is one of the earliest methods to study EEG, which has the irreplaceable advantages. With the continuous development of the EEG study, analysis method has turned from the time-domain into the time of frequency-domain, time and frequency-domain and other nonlinear method. Gorur  used Short time Fourier transform for feature extraction. Both multilayer perceptron and support vector machine are utilized in detection of the spindles achieving a sensitivity of 88.7% and 95.4%.  used amplitude-frequency normal modelling and reported a sensitivity of 75.1%.  used bandpass filtering with thresholding, relative power and autoregressive modelling to achieve sensitivity and specificity values of 84.6% and 95.3%.
In this paper, the merging algorithm based on the principle of the visual organization was applied to process the rare sleep EEG and then according to the time-domain feature of sleep spindles to detect the sleep spindles, which can be automatically marked. The rest of paper is organized as follows: Section 2 and section 3 introduce the detection method and result, Section 4 shows the conclusion.
2. Detection Method
2.1. Definition of Increasing and Decreasing Sequences
Define the as the th sample point in the sequence. In, , and then is an increasing sequence. If, , and, then is a decreasing sequence. The local maximum point is and the local minimum point are and. A new sequence is defined to mark these local minimum and maximum points, and let, ,.
2.2. Merging Algorithm Based on the Principle of the Visual Organization
The concept of visual organization originates from cognitive psychology. The main research contents include: Gestalt perceptual organization principles   , visual closure  and non-contingency principle  et al. visual organization algorithm is the method to make the basic image elements form an overall subject according to the quantitative model of Gestalt principle in a narrow sense. In a broad sense, algorithms that can achieve segmentation and clustering can be classified as the visual organization algorithm . Visual organization method can solve the computer visual problem such as: contour extraction, image segmentation and object detection et al.
The merging algorithm based on the visual organization consists two parts. One of them is to merger the clutter waves. The amplitude of EEG for an adult is 10 uv - 50 uv. The merging clutters algorithm is to remove the EEG with amplitude below 10uv is meaningless. The other part of the merging algorithm is to merger incomplete waves. After merging, the render shape of EEG becomes more in line with the standards of human vision. According to the study of , 11 kinds of merging situation are presented in the Figure 1.
(a) Merging clutters
Set and represents sampling period. If, then drop the point, change the order of the remaining points. In this case is neither the local maximum nor the local minimum point. So the local maximum point should be recalculated, and if, set, , ,……, the new sequence containing alternating local maximum and minimum points is formed. The results before and after merger are shown in Figure 2.
(b) Merging incomplete waves
The definition of complete waves and incomplete waves were proposed by Zhang  . Set, , , , , and. If these points satisfy one or more following conditions, start the merging procedure in Section 2.2.1.
Figure 1. Merger result: (a) the left and right waves both are incomplete, and they are merged; (b) the left and right waves both are incomplete, and they are merged; (c) the left and right waves both are incomplete, and they are merged; (d) the left is incomplete, the right is complete, and they can’t be merged; (e) the left is complete, the right is incomplete, and they can’t be merged; (f) the left and right are both incomplete, and they can’t be merged; (g) the left and right both are complete, and they can’t be merged; (h) the left is complete, the right is incomplete, when , they can be merged; (i) the left and right are both complete, when , they can’t be merged; (j) the left is incomplete, the right is complete, when, they can be merged; (k) the left and right are both completes, when , they can’t be merged.
Figure 2. Merger examples, the left is the wave before, the right is after.
(d) and and and;
(e) and and and;
(f) or and or.
It can be seen that r impacts the merging result directly. Zhang   have compared the results when r was changed from 0.2 to 0.7, and found that r = 0.5 can be more adaptive to waves of different rhythm and different amplitude. So r = 0.5 is chosen in this experiment.
The Figure 4 shows the single wave merger and the picture below presents a sample merger. The blue represents the rare EEG and the green represents the EEG after merger.
2.3. Detection of Sleep Spindles
The core idea of this paper is to merger the rare EEG using the merger algorithm based on the principle of visual organization so that the time-domain feature of the waves can be more obvious. According to these features, the waves which meet the period condition of sleep spindles can be marked, and then combine these waves with same features, and last judge whether the duration time of the marked waves is meet the duration feature of sleep spindles.
(1) Detect the single wave that meets the period condition
The frequency range of sleep spindle is 11 - 16 Hz, so the period of the single wave is 0.07 - 0.085 s. In this paper, we take the period of 0.06 - 0.10 s as the period condition to detect sleep spindles. The wave that meets the condition is marked in red in the dashed box.
In the Figure 4, represents the location of the merger point in the waveform. The period (T) of the single wave after merger is calculated following the equation below:
In the Equation (1), represents sample frequency. Here the value of is 100 Hz or 200 Hz. The wave with period in the range of was marked in red. Shown in the Figure 4, “” is not in the range of period, so it
Figure 3. Merger result in matlab.
Figure 4. Wave meets the period condition
keeps it as it is. “” meets the period condition and the wave was marked in red.
(2) Merge the marked waves
After the filter of the period, the single waves meet condition would be marked in red. If the interval distance between two adjacent marked waves meets the threshold conditions, the two adjacent marked waves can be combined, which means the waves between two adjacent marked waves would be marked in red in the dashed box.
Shown as the Figure 5, the waves in red in dashed box represent the waves that meet the period condition, and represent the interval distance between the marked waves. Set as the interval distance, new sequence to record the location of the end point in an unmarked waveform and to record the location of the front point in the unmarked waveform, and represents the th unmarked wave:
In the Equation (2), represents sample frequency. Here the value of is 100 Hz or 200 Hz. and record the end point and front point of the unmarked waves in the sample waveform. When meets the condition:, the waves would be marked in red.
The experimental results prove that should equal 0.05. Shown in the Figure 5, meets the condition was marked in red, while does not meet the condition, shown as it was.
(3) Remove the marked waves that do not meet the duration time condition
By definition sleep spindles last 0.5 s - 3 s. The marked waves should meet the duration time condition. If so, the marked waves are sleep spindles or
Figure 5. Merge of adjacent waves.
they are not sleep spindles.
The EEG waves were processed by the above two steps, and the marked waves are shown in the Figure 6. and represent the duration time of the marked waves. Set as duration time of marked waves, new sequence to record the location of the end point in an marked waveform and to record the location of the front point in the marked waveform, and represents the th unmarked wave:
In the Equation (3), represents sample frequency. Here the value of is 100 Hz or 200 Hz. and record the end point and front point of the marked waves in the sample waveform. When meets the condition:, the marked wave is not sleep spindle, and it should be removed the mark. Through calculation, keeps it was and remove the mark.
The data used in this experiment is from 6 subjects’ whole-nights recording. Two of them are collected from the laboratory, the sampling frequency of which is 200 Hz and the other four is downloaded from MIT , the frequency of which is 100 Hz. A segment of 30 minutes was extracted from each night from the central EEG channel for spindles scoring. And set a sample length of 20 sec. In Figure 7, the fragment of the detection result is shown in the dashed box:
The blue is the rare EEG signal, the green is the wave after merger and the red is the marked sleep spindles.
According to the assessment method of detecting sleep spindle proposed by , the number of false positive (FP), true positive (TP) and false negative (FN) is recorded. Taking the duration time of sleep spindles 2sec, we calculate the sensitivity and specificity according to the equations below and the results are shown in the Table 1:
Figure 6. Waves meet the duration time condition.
Figure 7. The detection result.
Table 1. Detection result of sleep spindle.
Seen from Table 1, the FP and FN exist. The main cause for FP is that the interval length between the marked waves whose duration time is less than 0.5secis lower than the threshold. They can’t form a wave whose duration time longer than 0.5 sec. In addition, the period of sleep spindle is about 0.06~0.10sec, so is the detection condition of sleep spindles. Some FPs’ period is just 0.06sec or 0.10sec.When the period condition changes into, the FP can be changed into TP. However, if to do so, the FNs would become more. Finally, we take the condition:. The main cause for FN is that some waves whose period is not in the range 0.06~0.1 would be meet the period condition because of the process of merger algorithm. Meanwhile, the interval duration time is less than the set threshold, and they would become a waveform longer than 0.5sec. We can’t remove them using duration time condition.
4. Concluding Remarks
This paper mainly introduces that the sleep spindles are detected by the time- domain feature in the EEG processed by the merger algorithm based on the principle of visual organization. Experiment results show that after the introduction of merging algorithm, it is feasible to combine the single wave into a spindle through the organizational rules, and are close to the visual result. To detect the spindles using time-domain features is simple, efficient and very intuitive. The detection result is also good. Of course, this method also has some limitations. When the experimental object is the patient, there will be more leakage. By analysis, the threshold for the experiments is fixed value for the training set of normal sleep data. When the data is from patients’ night sleep, the threshold is not the optimal value, and the waveform cannot be combined into the waveform with the duration of more than 0.5 sec. It does not meet the conditions of duration time. Therefore, the next stage of work is the optimization of the threshold parameters, so that the detection method can be used in different subjects.
 De, G.L. and Errara, M.F. (2003) Sleep Spindles: An Overview. Sleep Medicine Reviews, 7, 423-440. http://dx.doi.org/10.1053/smrv.2002.0252.
 Vu, D.T.T., Mckinney, S.M, Buxton, O.M., et al. (2010) Spontaneous Brain Rhythms Predict Sleep Stability in the Face of Noise. Current Biology Cb, 20, 626-627. http://dx.doi.org/10.1016/j.cub.2010.06.032
 Fogel, S.M. and Smith, C.T. (2010) The function of the Sleep Spindle: A Physio-logical Index of Intelligence and a Mechanism for Sleep-Dependent Memory Consolidation. Neuroscience and Biobehavioral Reviews, 35, 1154-1165. http://dx.doi.org/10.1016/j.neubiorev.2010.12.003
 Forest, G., Poulin, J., Daoust, A.M., etal. (2007) Attention and non-REM sleep in Neuroleptic-Naive Persons with Schizophrenia and Control Participants. Psychiatry Research, 149, 33-40. http://dx.doi.org/10.1016/j.psychres.2005.11.005
 Campbell, K. and Hofman W. (1980) Human and Automatic Validation of a Phase-Locked Loop Spindle Detection System. Electroencephalography & Clinical Neurophysiolgy, 48, 671-674. http://dx.doi.org/10.1016/0013-4694(80)90296-5
 Gorur, D., Halici, U., Aydin, H., et al. (2002) Sleep Spindles Detection Using Short Time Fourier Transform and Neural Networks. Neural Networks, IJCNN '02. Proceedings of the 2002 International Joint Conference on. IEEE, 1631-1636. http://dx.doi.org/10.1109/IJCNN.2002.1007762
 Nonclercq, A., Urbain, C., Verheulpen, D., etal. (2013) Sleep Spindle Detection through Amplitude–Frequency Normal Modelling. Journal of Neuroscience Methods, 214, 192-203. http://dx.doi.org/10.1016/j.jneumeth.2013.01.015
 Wendt, S.L., Christensen, J., Kempfner, J., etal. (2012) Validation of a Novel Automatic Sleep Spindle Detector with High Performance during Sleep in Middle Aged Subjects. International Conference of the IEEE Engineering in Medicine & Biology Society. Conference Proceedings IEEE EngMedBiolSoc, 4250-4253. http://dx.doi.org/10.1109/EMBC.2012.6346905
 Ben-Av, M.B. and Sagi, D. (1995) Perceptual Grouping by Similarity and Proximity: Expe-rimental Results Can Be Predicted by Intensity Autocorrelations. Vision Research, 35, 853-866. http://dx.doi.org/10.1016/0042-6989(94)00173-J.
 Mack, A., Tang, B., Tuma, R., etal. (1992) Perceptual organization and atten-tion..Cognitive Psychology, 24, 475-501. http://dx.doi.org/10.1016/0010-0285(92)90016-U
 Ffytche, D. (1999) Review of High-level vision: Object recognition and Visual Cognition. Optical Engineering, 20, 231-256. http://dx.doi.org/10.1027//0269-8803.13.3.200
 Han, S., Song, Y., Ding, Y., et al. (2001) Neural Substrates for Visual Perceptual Grouping in Humans. Psychophysiology, 38, 926-35. http://dx.doi.org/10.1111/1469-8986.3860926
 Zhang, J., Zou, J., Wang, M., et al. (2013) Automatic Detection of Interictal Epileptiform Discharges Based on Time-Series Sequence Merging Method. Neurocomputing, 110, 35-43. http://dx.doi.org/10.1016/j.neucom.2012.11.017
 Wei, Z., Zou, J. and Zhang, J. (2016) Automatic Recognition of Chewing Noises in Epileptic EEG Based on Period Segmentation.Neurocomputing, 190, 107-116. http://dx.doi.org/10.1016/j.neucom.2016.01.029
 Kemp, B., Zwinderman, A.H., Tuk, B., etal. (2000) Analysis of a Sleep-Dependent Neuronal Feedback Loop: The Slow-wave Microcontinuity of the EEG.IEEE Transactions on Biomedical Engi-neering, 47, 1185-119. http://dx.doi.org/10.1109/10.867928
 Devuyst, S., Dutoit, T., Stenuit, P., etal. (2011) Automatic sleep spindles detec-tion--overview and development of a standard proposal assessment method. Conference: International Conference of the IEEE Engi-neering in Medicine & Biology Society IEEE Engineering in Medicine & Biology Society Conference. Conference Proceedings IEEE Eng Med BiolSoc, 1713-1716. http://dx.doi.org/10.1109/IEMBS.2011.6090491