Proceedings of the 6th WSEAS Int. Conf. on EVOLUTIONARY COMPUTING, Lisbon, Portugal, June 16-18, 2005 (pp10-14) Wavelet Based CAP Detector with GA Tuning ROGÉ RIO LARGO1, CRISTIAN MUNTEANU2, AGOSTINHO ROSA2 (1)- Escola Superior de Tecnologia Instituto Politécnico de Setúbal Campus do IPS, Estefanilha, 2910-761 Setúbal PORTUGAL (2)- LaSEEB-ISR, Instituto Superior Técnico Universidade Técnica de Lisboa Av. Rovisco Pais, 1-Torre Norte 6.21, 1049-001 Lisboa PORTUGAL http://laseeb.isr.ist.utl.pt Abstract: - The EEG is an affordable and non-invasive technique to study the brain and very useful in sleep analysis. The organization of the sleep in stages (global view) was widely used. The sleep EEG microstructure (local view) gives attention to the short duration EEG events. The CAPS (Cyclic Alternating Pattern Sequences) is a periodic EEG activity of sleep, and provides important information on EEG synchrony modulation in the sleep process and is closely related with the dynamic organization of sleep. It is characterized by repeated spontaneous EEG activations, at intervals up to one minute, from the background activity. The objective of this work is the automatic detection and classification of CAPS in sleep EEG. We use wavelet transforms as a tool to analyze the sleep EEG signal in the time-frequency domain, to separate the signal power in frequency bands. The CAP activation period (A phases) characteristics are used to build a detector and a state machine determines the CAP sequences periods. A group of sleep registers are tested and results compared with visual classification. A genetic algorithm is used to make the tuning of the detector. Key-Words: - EEG, CAPS, Automatic Detection, Wavelets, Genetic Algorithms. 1. Introduction In sleep analysis, the Electroencephalographic signal (EEG) plays an important role. This is a non-invasive technique, and nowadays with the electronic miniaturization, there is mobile equipment that make possible to acquire the signals in the patient home. As a diagnostic tool, the EEG is very affordable when compared with others techniques that are not so easy to use and cost a lot more. The amount of data collected in a normal eight hours sleep night is very high, and techniques to make their automatic analysis are of great importance. The macrostructural organization of sleep is commonly expressed as a succession of sleep stages of two types - 4 NREM stages: S1, S2, S3, S4 related with the sleep depth and a special stage REM associated with rapid eye movements. They are classified by standardized criteria [1]. Scoring epochs of several seconds of signal (20s to 30s) are classified at a time. The large use of these criteria for long time has established a good base of experience to distinguish between normal and pathologic situations; however this is a static approach to the sleep process. In recent time, more attention has been given to the sleep microstructure, which shows that a more dynamic perspective needs to be adopted [2]. In effect, the changes in the sleep process are smooth and gradual, which is not compatible with the abrupt transitions between the sleep stages in sleep histograms. The macrostructure analysis could be seen as a global view of the sleep process. By the other side the microstructure analysis is a local view. The sleep EEG microstructure analysis gives attention to the short duration EEG phenomena events lasting less than the scoring epoch of sleep stages. These are commonly designated as arousalrelated phasic events (ARPE) and are generally associated with a transient lightening of sleep depth. They appear superimposed on the background rhythms of sleep EEG and could be seen as a homeostatic reaction of the organism to make an adjustment to the environment or internal changes in order to preserve the sleep. The ARPE could be of short duration (e.g., vertex sharp waves, isolated Kcomplexes) or long duration such as alpha rhythms in S1, sequences of K-complexes in S2, delta burst in S3 and S4 and micro-arousals [3, 4]. The last group usually is accompanied by increase in muscle tone and heart rate. A definition of arousals was proposed by ASDA [5], which basically are sudden frequency shift toward faster rhythms. Many sleep Proceedings of the 6th WSEAS Int. Conf. on EVOLUTIONARY COMPUTING, Lisbon, Portugal, June 16-18, 2005 (pp10-14) disturbances are associated with their increase in number. The Cyclic Alternating Pattern Sequences (CAPS) are closely related with the arousals. Both are related with the dynamic organization of sleep. The CAPS represents a sustained oscillatory condition between a greater arousal level (recurring EEG transient or A phase) and a lesser arousal level (interval between the successive clusters of EEG transients or B phase) [6, 7]. In NREM sleep, the A phases are formed by the arousal-related phasic events characteristic of each sleep stage, and the B phases by the intervals of background theta– delta activity. Existence of CAPS implies a sequence of alternating A and B states with time duration conditions (2-60 sec) [7]. Situations of arousal stability coincide with absence of CAP. Phase A can be divided in 3 subtypes A1, A2, A3 as a balance between synchronized EEG patterns and desynchronized patterns preceded or mixed with high voltage waves [7]. From A1 to A3 there is a progressive desynchronization. The objective of this work is the automatic classification of CAPS in one channel of sleep EEG signal during all night. This classification has been mainly made visually [8]. Some preliminary work was made in the automatic detection [9,10,11]. These works made comparisons between visual and automatic classification of CAPS in wealthy subjects with good results [10], and in patients with less good results [9]. The present work applies wavelet transforms to make the filtering of the EEG signal. This way the features extracted have good time discrimination. To select the parameters to make the tuning of the detector we use a genetic algorithm [12]. 2. Material and Methods 2.1. Wavelets to Time-frequency Analysis The events presented in the introduction can be described in frequency but have short duration. The classical Fourier analysis is not well adapted to this situation. Because the wavelet transform conjugates good discrimination in frequency and in time, it is adequate to process the sleep EEG signal in order to detect and separate those events. The main goal of this work is the detection and identification of the CAP activation phase A. Wavelet transforms are closely related with filter banks. The idea of multiresolution is basic to wavelet analysis and divides the frequencies in octave bands: the compression in time by a factor of two means expansion in frequency by the same factor. [ f (t ) → 1 w f (2t )] ⇔ F ( w) → F ( ) 2 2 (1) A fast discrete wavelet transform (DWT) computes coefficients, applying recursively a pair of half-band mirror filters (approximation and detail) [13]. Multiresolution analysis decomposes the sleep EEG signal in a dyadic time-frequency space. Following the wavelet packet scheme we gain flexibility to choose the frequency sub bands adequate to characterise the events. In the wavelet theory, time-scale is the most natural one, but as scale and frequency are closely related we could talk about time-frequency. The relevant EEG signal activity bands are: delta (0.5-4 Hz); theta (4-8); alpha (8-12); sigma (12-16); and beta (16-32). Additionally we separate the delta band in three sub bands (0.5-1; 1-2; 2-4 Hz). In order to separate them, we make a wavelet packet analysis to decompose the sleep EEG signal. 2.2. EEG Features Extraction For each band the signal power is evaluated. To discriminate between the background activity and the phasic activity, two moving average with short (SMA) and long duration (LMA) are calculated. The relation between the short (SMA) and the long moving average (LMA) is used as a measure of the presence of activity in the EEG bands. MAr = SMA , LMA MAr: Moving average ratio. (2) To make the detection of these activities, the MAr for each band is compared with thresholds with hysteresis to mark their beginning and ending. The characteristics of A phases in CAP periods are: •Intermittent alpha rhythms and sequences of vertex sharp waves, in sleep stage 1. •Sequences of two or more k-complexes with or without alpha-like components and beta rhythms, in sleep stage 2. •Delta bursts showing an increase in amplitude of at least 1/3 compared to background activities, in stages 3 and 4 •Transient activation or arousals [5] in all the sleep stages. [7] 2.3. Detection of Phase A The beginning of phase A is detected if the activity index (MAr) of the delta, theta or alpha bands is higher than the upper level of the threshold. The ending of phase A is detected if the delta, theta, alpha and beta bands are all below the lower level of the threshold (figure 1). This algorithm detects candidates to be phase A (pre-A). Their duration and the time interval between them are tested later to find the CAP sequences (CAPS). Proceedings of the 6th WSEAS Int. Conf. on EVOLUTIONARY COMPUTING, Lisbon, Portugal, June 16-18, 2005 (pp10-14) Instead of using alpha band directly, we use an index between alpha and sigma to separate them better. Fig.1 Detection of phase A in 60s of EEG. Aut: Automatic Detection, Vis: Visual Classification. The power of delta could be used to adjust dynamically the level of the threshold, and the value of the hysteresis. Other parameters are used as indications of the macrostructure of the sleep: [alpha / (delta+theta)] as an indication of wake state and [delta / (alpha+beta)] as indication of slow wave sleep. population can be mutated, depending on the probability of mutation. In ARGA, the mutations are restricted to a subpopulation of chromosomes, called reservoir. The reservoir has its individuals mapped onto a fixed population. The number of chromosomes in the mutant subpopulation (reservoir) is called diameter and is adapted during run. If there is no improvement in the best solution found during a certain number of generations, the diameter of the reservoir grows, in order to obtain a larger diversity in the population and to recast the search in a better niche of the search space. When this event occurs (i.e. an improvement beyond a certain threshold) the diameter of the reservoir is reset to the initial value. 2.6. Comparing Automatic and Visual CAPS Classification We used one channel of EEG to make the automatic classification of the CAPS for each sleep record. Fig. 2 presents the output of one classification automatic (Caps-Aut) and visual (Caps-Ref). Trace 1 is the hipnogram (R&K staging [1], 30s epoch) representing the sequence of sleep stages (Wake, REM and non-REM: 1, 2, 3, 4). The CAPS is represented with sequences of A, B phases separated by intervals of absence of CAPS (non-CAPS). 2.4. CAP Sequences (CAPS) The time intervals between the phases A are the phases B. The duration of the A and B phases must be greater than 2 seconds and less than 60 seconds. This means that if two pre-A are not separated by at least 2 s, they must be put together and if the interval between them is greater than 60 s, the second pre-A must be eliminated. Using these rules and the fact that to start one CAP sequence, we must have at least 3 consecutive A phases (2 CAP cycles), and the end of the sequence is in the beginning of a valid A phase, a state machine, implement these rules, is used. The output of the state machine separates the sleep EEG in periods of CAPS and periods of non-CAPS (N). Each CAPS interval is marked as a sequence of phases A and B. 2.5. Genetic Algorithm Tuning In order to choose the best parameters for the detector, we use an Adaptive Reservoir Genetic Algorithm (ARGA), adapted to this situation, where the exploration/exploitation is directly controlled during evolution, using a Bayesian decision process [12]. In a standard GA each chromosome in the Fig. 2 Automatic and visual CAPS classification for a sleep record (8h). The top figure is the hipnogram representing a sequence of sleep stages. The other represents the CAPS from automatic (middle) and visual classification (Ref.). Based on amount of time for each situation, the auto and visual classifications where compared, Assuming the visual as a reference. The kind of errors and agreements that can occur are shown in table 1. Four global indices are calculated [10]: • Corr: Correctness. The ratio of all true events (T, TB and TN) by total events. Global performance of automatic classification. • %True: It is the ratio of correct A phase (T) by total visual A phase in (T+M+MA) - first column. Proceedings of the 6th WSEAS Int. Conf. on EVOLUTIONARY COMPUTING, Lisbon, Portugal, June 16-18, 2005 (pp10-14) • False/Ref.: It is the ratio of false A phases (F+FA) – first line, by total visual A phase in (T+M+MA) first column. Table 1. Auto-Visual CAPS Classification Visual Visual Visual Comparisons A B NCAP T F FA Auto A true A false false A M TB FB Auto B miss true B false B MA MB TN Auto NCAP miss A miss B True N 3. Results A group of parameters from the detector is tuned with the genetic algorithm (ARGA). Fig. 3 shows the dynamic of the ARGA after 20 generation. A line connecting the top points could be interpreted as a ROC. The value marked as the best point was selected by the GA as the best tuning for this example. The comparison results for 6 patients are shown in table 2. Miss=1-True. In present work the results obtained with the group of patients are concentrated around the mean values and similar with the human inter-rate scorer [9]. Table 2. Results for 6 patients %True %Miss Subjects 68 Pat. 1 32 67 Pat. 2 33 63 Pat. 3 37 61 Pat. 4 39 75 Pat. 5 25 70 Pat. 6 30 Mean 67 33 False/Ref. 43 65 25 30 62 36 44 4. Conclusion Fig. 3 Dynamic of ARGA for 20 generation. The total output obtained in the tuning process is shown in fig.4. It represents the %True versus the ratio of False/Ref. Each point is a run of the GA with one set of parameters. Fig.4 – Results of the tuning with ARGA. The %True is represented in function of the False/Ref. The line represents a curve similar to a ROC. CAP studies by visual analysis are a heavy task. The spreading of this paradigm in sleep study will need the existence of reliable automatic detection systems. This work presents an approach to this task using wavelets to extract features from the sleep EEG signal. The wavelets have a good timefrequency characteristic allowing good time discrimination. The present study used time discrimination of 0.25s. The agreement between automatic and visual score is comparable with the agreement between different human scorers [9]. Some improvements are being prepared in order to have better detection and to include the separation of the different phases A. References: [1] A. Rechtschaffen, A. Kales, A manual of standardized terminology, techniques and scoring system for sleep stages of human subjects. U.S. Government Printing Office, Washington DC, 1968. [2] M. Terzano, L. Parrino, Functional Relationship between Micro and Macrostructure of Sleep, Phasic Events and Dynamic Organization of Sleep, Eds: M. Terzano, P. Há lasz, and A. Declerck, (Raven Press. 1991), pp.101-120. [3] P. Halàsz, Hierarchy of Micro-arousal and the Microstructure of Sleep, Neurophysiol. Clin., Vol.28, 1998, pp. 461-475 [4] P. Halàsz, O. Kundra, and others, Microarausals During Nocturnal Sleep, Acta Physiol. Acad. Sci. Hung., Vol.54, 1979, pp. 1-12. [5] ASDA (American Sleep Disorder Association). EEG arousals: scoring rules and exemples. A Proceedings of the 6th WSEAS Int. Conf. on EVOLUTIONARY COMPUTING, Lisbon, Portugal, June 16-18, 2005 (pp10-14) perliminaire report from the sleep disorder atlas task force of the American Sleep Disorder Association, Sleep, Vol. 15, 1992, pp. 174-184. [6] M. Terzano, L. Parrino, Origin and Significance of the Cyclic Alternating Pattern (CAP). Sleep Med. Rev., Vol. 4, 2000, pp. 101-123. [7] M. Terzano, L. Parrino, A Smerieri, R. Chervin, S. Chocroverty, C. Guilleminault, M. Hishkowitz, M. Mahowald, H. Moldofsky, A. Rosa, R. Thomas, A. Walters, Atlas, rules, and recording techniques for the scoring of cyclic alternating pattern (CAP) in human sleep, Sleep Medicine, Vol. 3, 2002, pp. 187-199. [8] A. Rosa, A. Smerieri, Visual classification of CAPS power and macrostructure R&K on EDF files, Internal report-Laseeb 99.9, ISR– Lisbon, 1999, (http://laseeb.isr.ist.utl.pt). [9] Automatic classification of CAPS by adaptive filtering, Internal report 97.2, ISR– Lisbon, 1997, (http://laseeb.isr.ist.utl.pt). [10] Automatic Detection of Cyclic Alternating Pattern (CAP) Sequences in Sleep: Preliminary Results, Clinical Neurophisiolog, Vol. 110, 1999 pp. 585-592. [11] R. Largo, A. Rosa, M. Terzano, L. Parrino, A. Smerieri, CAPS Detection and Vlassification Using Wavelets, J. of Sleep Research, Vol. 11 (S1), 2002, pp. 266. [12] Cristian Munteanu, Agostinho Rosa, Adaptive Reservoir Genetic Algorithm: Convergence Analysis, Advances in Intelligent Systems, Fuzzy Systems, Evolutionary Computation, A Grmela, N Mastorkis (edt), WSEAS Press, 2002, pp. 235238. [13] S. Malat, A Theory of Multiresolution Signal Decomposition: the Wavelet Representation. IEEE Trans. PAMI, Vol. 11, 1989, pp. 674-643.