## Introduction

The sleep-wake cycle is a critical physiological process and one of the most preserved biological rhythms through evolution1. This cycle is composed of different states, commonly distinguished by their electro-physiological signatures and behavioral characteristics. These states correspond to wakefulness (W), non-rapid eye movement (NREM) sleep, and rapid eye movement (REM) sleep. W and sleep are associated to different brain functional states, which can be captured by electroencephalographic (EEG) signals containing a broad frequency spectrum. Accompanying the electrocortical differences among the states, the cognitive capacities drastically change during the cycle. Fundamentally, consciousness is lost during deep NREM sleep, emerging in an altered fashion during REM sleep. Altered states of consciousness can also arise during special normal states, such as during lucid-dreams2, or under toxic or pathological conditions, such as the states induced by psychedelic drugs or psychosis3,4.

Cognitive states are mostly determined by the function of the thalamo-cortical system1. Part of this neuronal processing can be accurately measured by intra-cranial elecroencephalogram (EEG), known as electrocorticogram (ECoG). Due to the complex nature of the standard EEG and ECoG signals, traditional methods employed in neuroscience have divided the complex spectrum of the signal into frequency bands3,5,6,7,8,9, and analyzed its changes during different cognitive functions4,7, and sleep states5,6,8. These methods only describe particular characteristics of the recorded signals and do not account for the complex nature of the cortical electric potentials. In contrast, the field of non-linear dynamics has developed measures and models that account for the complexity of the systems and their emerging interactions10,11,12,13. These properties are fundamental for the characterization of the thalamo-cortical function and for the emergence of consciousness14.

A general approach to study time-signals is the characterization of their randomness; for example, by means of the Shannon entropy (SE)15, which measures the average unpredictability of a signal. However, SE requires a random source and an invariant probability distribution (which is typically unknown), also is affected by noise, by measurement precision, and by data length. All these elements are relevant when dealing with real-world signals. In order to find a similar non-linear measure to quantify unpredictability from real-world data, Bandt and Pompe10 introduced the Ordinal Pattern (OP) analysis, allowing to encode any signal into OPs and approximate its SE. This approximation is known as Permutation Entropy (PeEn). In contrast to other methods, PeEn is a time-series complexity measure that is simple to implement, is robust to noise and short time-series, and works for arbitrary data sets13,16,17,18,19,20,21,22,23,24. In particular, it has been shown that PeEn applied to EEG signals captures different states associated with the level of consciousness, both during anesthesia24,25,26,27 and sleep28,29. Hence, in order to study the thalamo-cortical function during W and sleep, PeEn is a practical and reliable method, where results can be understood from primary principles, and can be related to the signal characteristics.

Previous works have analyzed PeEn in standard EEG recordings25,26,27,28,29. However, EEG signals have frequency limitations due to scalp-filtering, are often recorded with low sampling rates, and pre-acquisition filters are commonly applied. In addition, as the recording electrodes are placed above the scalp’s skin, other sources can interfere with the cortical neural activity (e.g., muscular activity)30. These limitations exclude the possibility of considering high-frequency oscillations; for example, $$\gamma$$ frequency band ($$30-100\,Hz$$), which is known to vary substantially during the sleep-wake cycle and is an active field of research in Neuroscience3,5,6,7,8,9,31,32. Thus, PeEn analysis of standard EEG signals is technically limited and is unable to assess the significance of the broad frequency spectrum in relation with the thalamo-cortical function and its cognitive counterpart. Consequently, it is still uncertain whether previous results hold when considering ECoG measurements and whether these results would depend on cortical location, frequency content, or PeEn parameters.

In the present study, we characterized the PeEn of recordings from freely moving rats during W and sleep. We found that ECoG’s PeEn is maximal during W and decreases during both sleep states. Moreover, we noted that these results are independent of the cortical location (namely, the electrodes placement), pointing towards a global cortical pattern for each sleep-wake state that is captured by the PeEn analysis but is missed by classical methods.

## Results

### Permutation entropy during wakefulness and sleep

Figure 1a shows examples of polysomnographic recordings obtained from electrodes placed directly above the cortex of a representative rat. Electrode locations are shown on the left panel and the intra-cranial polysomnographic recordings for W (blue), NREM (green), and REM sleep (red) states are shown on the right panels, which have been distinguished by means of the standard sleep scoring criteria (see Methods). In Fig. 1b we show, for the same animal, the hypnogram (top), as well as the spectrogram (middle) and PeEn values (bottom) processed from the ECoG recorded with the V2r electrode (with a sampling rate of $$1024\ Hz$$ and $$D=3$$ embedding dimension for the PeEn analysis; see Methods for details). The hypnogram shows the standard sleep scoring, the spectrogram shows the ECoG frequency content, and the PeEn quantifies its complexity; namely, its randomness or unpredictability. Maximal PeEn values were achieved during W, PeEN values decreased during NREM sleep and reached minimum values during REM sleep. This result states that the ECoG becomes more predictable – less random – during sleep, especially during REM sleep. More importantly, we found that PeEn is able to detect transitions between behavioral states, which are typically difficult to be noticed from raw data or from the spectrogram. For example, the power spectrum in Fig. 1b (middle panel) shows similarities between W and REM sleep, but PeEn values are drastically different between these states (W epoch at 11 to 13 minutes and REM sleep epoch at 22 to 24 minutes). The average PeEn values for all rats, behavioral states, and cortical locations are shown in Fig. 1c and Table 1, there are significant differences among behavioral states for all recorded neocortical regions; in the Olfactory Bulb (OBr, archicortex) there was a tendency to decrease $$(p=0.056)$$ when REM was compared to NREM sleep (first row in Table 1). Consequently, the PeEn of the ECoG characterizes and follows the state transitions regardless of the electrode’s location.

### Permutation entropy dependence on the embedding dimension

We characterized how PeEn reflects the ECoG temporal complexity during W and sleep. In order to do this characterization, we modified the embedding dimension $$D$$, which is the parameter that sets the ordinal pattern (OP) length encoding the ECoG signal. Specifically, each OP captures the relationship between the relative amplitudes (ranking its values) inside a $$D$$-sized non-overlapping time-window of the signal (see Methods for details on the encoding procedure). Hence, changing $$D$$ modifies the time scale of the ECoG being analyzed and the resultant PeEn calculation. The larger the OP, the more details are obtained from the signal; thus, the less random the signal becomes and the smaller its PeEn value. For example, Fig. 2 shows that the PeEn values consistently decrease as we increased the embedding dimension from $$D=2$$ to $$D=4$$, either for W or sleep. Overall, averaged PeEn values during W were larger than during sleep for all $$D$$s. Also, the fact that PeEn variability is minimal for $$D=2$$ is because this dimension has the greatest sensitivity to random fluctuations: i.e., it mainly captures noise.

### Permutation entropy relationship with the frequency spectrum

As our results show that REM sleep had the lowest temporal complexity out of all states considered, we examined whether the frequency content could be influencing our PeEn assessment. In order to associate the PeEn values with the different frequency bands, we performed successive down-samples to the ECoG signals. This process allows for the ordinal patterns to capture lower frequency components of the ECoG signal, while keeping constant the embedding dimension, $$D$$.

We down-sampled the ECoG from a sampling rate of $$1024\ Hz$$, halving it down to $$64\ Hz$$; thus, changing the maximum frequency resolution from $$512\ Hz$$ to $$32\ Hz$$. By doing this, the PeEn value changed, revealing its relationship to the frequency spectrum. Fig. 3a shows averaged PeEn using $$D=3$$ for all rats and electrode locations, for W (blue), NREM (green) and REM sleep (red). The shaded areas indicate the mean $$\pm$$ standard error of these averages, showing that the states differentiate in average significantly (the exact statistics are exhibited in Table S1 at the Supplementary Material). Average PeEn values for the ECoGs during REM sleep are larger than NREM sleep until the maximum frequency resolution increases beyond $$128\ Hz$$, remaining lower than W values for all frequencies. Although Fig. 3a shows only the PeEn values for $$D=3$$, we obtained similar results for larger embedding dimensions (data not shown). The relationship between the PeEn values and the sampling frequency can be further understood by comparing these results with the power spectral density (PSD) analysis shown in Fig. 3b. In general, the PSD of a signal is the probability distribution function of its frequency content; namely, the degree of presence that each frequency component has in the signal. As we down-sampled the ECoG signals, as in Fig. 3a, the higher frequencies are cut-off from the PSD [Fig. 3b]. For the higher frequencies, i.e., $$> 200\ Hz$$, there is a large difference in the PSD value between W and sleep. However, when lower frequencies are considered, REMs PSD increased above NREMs. Note that below $$200\ Hz$$ REMs lower frequencies become more relevant (Fig. 3b) and PeEn (Fig. 3a) values are larger than NREM sleep and closer to W.

### Ordinal pattern probability distributions

In addition to the Entropy quantification, we considered the qualitative differences and variations appearing in the OP probability distributions during W and sleep. The OP distributions shown in Figs. 4 and 5 quantify the relative frequency of appearance that each OP has in the encoded ECoG signal; namely, the OP probability. Figure 4a shows the $$6$$ possible OPs when the embedding dimension is $$D=3$$ (top panel), and the resultant OP probability distribution we found from the ECoGs in each sleep-wake state (bottom panel). Similarly, Fig. 4b shows the OPs and OP distribution for $$D=4$$. It is readily observed from both panels that the increasing or decreasing OPs (i.e., labels $$1$$ and $$6$$ in Fig. 4a and labels $$1$$ and $$24$$ in Fig. 4b) have a larger probability of occurrence, irrespective of the sleep-wake state or the embedding dimension (results hold for larger $$D$$ – not shown). We note that, in spite of having qualitatively similar distributions for $$D=4$$, other OPs start to emerge, such as labels $$7$$ and $$18$$, which are modified versions of labels $$1$$ and $$24$$, respectively. Nevertheless, these OPs are not statistically significant, since they fall within the null hypothesis confidence interval (signaled by the shaded grey areas in both panels). On the contrary, the OP distribution in Fig. 4a for $$D=3$$ during sleep (red and green) significantly departs from the null hypothesis, which corresponds to the uniform distribution (shaded grey area).

### Comparison with classical amplitude encoding

Classical analysis of time-series uses the probability distribution function of the signal; namely, the signal is encoded using a histogram of its amplitudes. This process discards the information coming from the signal’s time stamps; in other words, the amplitude time-dependence. We compared the entropy values using histograms with $$18$$ bins of the ECoG, where the results are shown in Fig. 5. As can be directly observed, there were some differences among the sleep states (either NREM or REM), but there were no consistent global pattern and no single electrode was able to differentiate between all sleep-wake states (see Table S2). Moreover, these results remain practically invariant when using larger number of bins (data not shown).

## Discussion

In this work, we described that the collective cortical activity measured by ECoG in male adult rats fluctuates between periods of high temporal complexity during W, and periods of low temporal complexity during sleep (see Fig. 1b,c). These ECoG complexity variations reflect the differences in the thalamo-cortical function between sleep-wake states. Consequently, our results strongly support and extend studies in human that carried out PeEn analyses and other complexity measures in standard EEG recordings25,26,27,28,29,33.

We also showed that PeEn profile during W and sleep did not change according to the cortical recording site, reflecting a common micro-structure motif and a dynamical behavior which are independent from the origin of the cortical signal. The average randomness of these micro-structure patterns distinguished sleep from W, regardless of the changes in the embedding dimensions employed in PeEn analysis (Fig. 2) and the sampling frequencies considered (Fig. 3a). These results suggest the use of PeEn as a quantitative tool for understanding thalamo-cortical dynamics during various physiological conditions, the influence of psychoactive drugs, or pathological conditions.

A strong benefit from PeEn analyses is that PeEn variations across states can be explained by dynamical systems theory10,16,34; conversely, with other techniques the tractability is lost (such as, machine-learning approaches). During NREM sleep, the neuro-modulation coming from the activating systems drastically decreases, which favors the occurrence of slow $$\delta$$ waves ($$1-4\ Hz$$) and sleep spindles ($$9-12\ Hz$$) in the thalamus and cortex1. This means that, as the animal transits from W to sleep, the higher-frequency cortical patterns (complex signals) decrease, while lower-frequency oscillations (less complex signals) rise (Fig. 3b). As a consequence, the OPs probability distribution becomes less uniform (in other words more predictable). Specifically, we found that strictly increasing or decreasing OP motifs are strongly favored in all ECoG signals, particularly during sleep (Fig. 4), making the remaining OP motifs to appear less frequently.

Surprisingly, we found that NREM’s PeEn is larger than REM’s PeEn, which contradicts previously reported results28,29. However, we showed that as the frequency content of the ECoG varies, the PeEn changes its value. For example, Fig. 3a exhibits that as we down-sampled the ECoG, REM sleep PeEn becomes larger than NREM’s PeEn; these low sampling rates are similar to those used in previous studies28,29. Moreover, we analyzed the results from the PeEn as a function of the maximum frequency resolution (Fig. 3a) in conjunction with those from the power spectral density (PSD) of the ECoG (Fig. 3b). We observed that the rise in REM’s PeEn as the frequency content decreased follows the variations in the PSD. Specifically, REM sleep presents larger power than NREM sleep around and below $$120\ Hz$$ corresponding to the high frequency oscillations and gamma band oscillations5,6. This means that when higher frequencies are cut-off, the PSD slope significantly increases approaching a more uniform frequency distribution, which corresponds to a more complex time-series. These analyses reveal that PeEn results depends on the frequency content of the signal. In particular, REMs temporal complexity resembles W when gamma oscillations are captured by the PeEn.

One of the main differences between W and sleep, is that muscle tone and movements are mainly absent during sleep (specially during REM sleep). In this regard, the power of the higher frequencies of the spectrum is significantly higher during W than during sleep. It is possible that exists a contribution of muscular activity on the ECoG (by volume conduction) on the high frequency bands ($$> 100\ Hz$$), as supported by experimental evidence30. Hence, the high values of PeEn during W could be determined by the muscle electrical activity (produced mainly by the muscle tone, because epochs with movement artifacts were discarded from the analysis) that inevitably pollutes the ECoG. Nevertheless, the PeEn values remained constant during W following downsampling, in spite of the fact that higher frequencies were bypassed and the contribution from muscle tone became less relevant. Still, more research is needed in order to quantify the weight of the muscle artifact in the PeEn results.

As a final remark, sleep classification is usually performed by visual analysis, or automated spectral methods usually in research contexts. For instance, in rodents methods which employ spectral ratios (such as the theta/delta ratio) obtained from hippocampal or intra-craneal recordings in rodents, are able to distinguish sleep-wake states35,36. Thus, these methodologies rely heavily upon the use of narrow band characteristics of the EEG signal. In contrast, our data suggest that the sleep-wake states differ globally in their time-series complexity as assessed by PeEn. Hence, we suggest that cheap, robust, and reliable sleep monitoring could be achieved by means of PeEn analysis of a single ECoG channel.

## Methods

### Experimental animals

All experimental procedures were conducted in agreement with the National Animal Care Law (No. 18611) and with the “Guide to the care and use of laboratory animals” (8th edition, National Academy Press, Washington DC, 2010). Furthermore, the Institutional Animal Care Committee (ComisiÃşn de Etica en el Uso de Animales) approved the experiments (Exp. No 070153-000332-16), where $$12$$ Wistar adult rats were maintained on a $$12-h$$ light/dark cycle (lights on at $$07:00h$$) with food and water freely available. The animals were determined to be in good health by veterinarians of the institution. We took adequate measures to minimise pain, discomfort, and stress in the animals, and all efforts were made to use the minimal number of animals necessary to obtain reliable scientific data.

### Surgical procedures

The animals were chronically implanted with electrodes to monitor the states of sleep and W. We employed similar surgical procedures as in previous studies5,6. Anaesthesia was induced with a mixture of ketamine-xylazine ($$90\ mg/kg$$; $$5\ mg/kg$$ i.p., respectively). The rat was positioned in a stereotaxic frame and the skull was exposed. To record the ECoG, stainless steel screw electrodes were placed on the skull above motor, somatosensory, visual cortices (bilateral), the right olfactory bulb, and cerebellum, which was the reference electrode (see Fig. 1a and Table 2). In order to record the EMG, two electrodes were inserted into the neck muscle. The electrodes were soldered into a $$12$$-pin socket and fixed onto the skull with acrylic cement. At the end of the surgical procedures, an analgesic (Ketoprofen, $$1\ mg/kg$$, s.c.) was administered. After the animals had recovered from these surgical procedures, they were left to adapt in the recording chamber for $$1$$ week.

### Experimental sessions and sleep scoring

Animals were housed individually in transparent cages ($$40\times 30\times 20\ cm$$) containing wood shaving material in a temperature-controlled ($$21\,-\,2{4}^{\circ }$$C) room, with water and food ad libitum. Experimental sessions were conducted during the light period, between 10 AM and 4 PM in a sound-attenuated chamber with Faraday shield. The recordings were performed through a rotating connector, to allow the rats to move freely within the recording box. Polysomnographic data were amplified ($$X1000$$), acquired and stored in a computer using Dasy Lab Software employing $$1024\ Hz$$ as a sampling frequency and a $$16$$ bits AD converter. The states of sleep and W were determined in 10 s epochs. W was defined as low voltage fast waves in the motor cortex, a strong theta rhythm ($$4\,-\,7\ Hz$$) in the visual cortices, and relatively high EMG activity. NREM sleep was determined by the presence of high voltage slow cortical waves together with sleep spindles in motor, somatosensory, and visual cortices associated with a reduced EMG amplitude; while REM sleep as low voltage fast frontal waves, a regular theta rhythm in the visual cortex, and a silent EMG except for occasional twitches. An aditional visual scoring was performed to discard artifacts and transitional states.

### Ordinal pattern encoding

In order to quantify the EEGs’ randomness, we encoded the time-series into ordinal patterns (OPs) following Bandt and Pompe method10. The encoding involves dividing a time-series, $$\{x(t),\ t=1,\ldots ,T\}$$, into $$\lfloor (T-D)/D\rfloor$$ non-overlapping vectors, where $$\lfloor y\rfloor$$ denotes the largest integer less than or equal to $$y$$ and $$D$$ is the vector’s length, which is much shorter than the time-series length ($$D\ll T$$). Then, each vector is classified according to the relative magnitude of its $$D$$ elements. The classification was done by determining how many permutations are needed to order its elements increasingly; namely, an OP is associated to represent the vector’s permutations. For example, for $$D=2$$, the time-series would be divided into vectors containing two consecutive values, such as {$$x({t}_{i}),x({t}_{i+1})$$}, that are non-overlapping (the next vector to {$$x({t}_{i}),x({t}_{i+1})$$} is the {$$x({t}_{i+2}),x({t}_{i+3})$$} vector, where $${t}_{i}$$ is the $$i$$-th time stamp). These vectors have only two possible OPs for any time $${t}_{i}$$: either $$x({t}_{i}) < x({t}_{i+1})$$ or $$x({t}_{i}) > x({t}_{i+1})$$, which correspond to making $$0$$ permutation or $$1$$ permutation, respectively. It is worth noting that the number of possible permutations increases factorially with increasing vector length; i.e, for vectors of length $$D$$ there are $$D!$$ possible OPs. In particular, we labeled the OPs as the number of permutations plus one; hence, our OPs are labeled by means of integers, $$\alpha$$, that range from $$\alpha =1$$ to $$\alpha =D!$$. For $$D=2$$, $$\alpha =1$$ or $$2$$. Similarly, for $$D=3$$, the OPs $$\alpha =1$$ and $$\alpha =2$$ correspond to having a vector from the time-series with $$3$$ values ordered as $$x({t}_{i}) < x({t}_{i+1}) < x({t}_{i+2})$$ and $$x({t}_{i}) < x({t}_{i+2}) < x({t}_{i+1})$$, respectively, but there are $$4$$ more possibilities (for $$D=3$$, $$\alpha =1,\ldots ,3!=1,\ldots ,6$$). Small noise fluctuations were always introduced into the time-series in order to remove degeneracies; i.e., avoid the cases where, for example, $$x({t}_{i})=x({t}_{i+1})$$.

### Randomness quantification

Shannon entropy (SE) is a quantity used in Information theory to quantify the average randomness (information content) of a signal. It is defined as15 $$H(S)=-{\sum }_{\alpha \in S}p(\alpha )\ {\rm{\log }}\left[p(\alpha )\right]$$, where $$p(\alpha )$$ is the probability of finding symbol $$\alpha$$ in the signal (among the set of symbols $$S$$) and the summation is carried over all possible symbols. In other words, SE shows that $$H(S)$$ is the average value of $${\rm{\log }}(1/p)$$ with respect to an alphabet $$S$$. Hence, in order to find $$H$$ for any real-valued time-series, we need to transform the time-series into a symbolic sequence. When using OPs, the resultant symbolic sequence has a finite number of symbols; i.e., the alphabet, which is given by the OP’s length $$D$$ and holds $$D!=\#\{S\}$$ possible symbols. For bin histograms, the number of possible symbols depends on the number of bins, $${N}_{b}$$, used to create the time-series histogram, which is another way of encoding any bounded time-series into a finite set of values. In order to compare entropy values coming from OPs or bins, we need to set both quantities such that the probabilities involved in the summation of $$H(S)$$ are found with identical statistics. For example, when using non-overlapping OPs with $$D=3$$, there are $$D!=6$$ possibly different symbols in an encoded time-series of length $$T$$, which accounts to $$\sim T/D$$ total encoded symbols.

We highlight that the number of bins we chose corresponds to making an amplitude encoding that has the same statistical average as the OP encoding with dimension, $$D$$. Namely, a signal with $$T$$ time-stamps, is encoded by non-overlapping OPs into a symbolic sequence of length $$S=\lfloor (T-D)/D\rfloor \simeq T/D$$, where $$\lfloor \cdot \rfloor$$ indicates the smaller integer closer to the argument. The resultant range for the symbolic sequence distribution is $$D!$$, which is the different OP possibilities. This means that a length $$T$$ time series has an OP statistical average of $$S/D!\simeq T/D\times D!$$. On the other hand, the statistical average for histograms with $${N}_{b}$$ bins of the same time-series is $$T/{N}_{b}$$. Consequently, in order to have the same statistical average per bin and be able to compare the results, we need to set $${N}_{b}=D\times D!$$, which for $$D=3$$ corresponds to having $${N}_{b}=3\times 6=18$$ bins.

### Power spectral density and statistical analysis

The power spectral densities were performed using the pwelch function on MATLAB by employing the following parameters: $$\,{\rm{window}}=30s,{\rm{noverlap}}\,=[],\,$$$${\rm{fs}}=1024,{\rm{nfft}}\,=1024$$. These parameters correspond to $$30$$ second sliding windows with half windows overlap, a $${f}_{s}=1024\ Hz$$ sampling frequency and a frequency resolution of $$1Hz$$.

On the other hand, the statistics for each ECoG PeEn calculations were based on non-overlapping windows of size $$D\times D!\times {N}_{S}$$, where $${N}_{S}=200$$ is the statistical average we use for our null-hypothesis. Namely, our null-hypothesis is a Bernoulli process where each ordinal pattern of size $$D$$ has an equal probability of appearance, $${p}_{NH}=1/D!$$, and a standard error of the mean $${\sigma }_{NH}=\sqrt{{p}_{NH}\ (1-{p}_{NH})/{N}_{S}}$$. For example, for ordinal patterns with $$D=3$$, the non-overlapping windows contained $$3\times 6\times 200=3600$$ data points, which accounts to approximately $$3.5$$ seconds at a $${f}_{s}=1024\ Hz$$ sampling frequency. The null-hypothesis in this case has an average probability $${p}_{NH}=1/3!=1/6\simeq 0.167$$ and a standard error of the mean $${\sigma }_{NH}=\sqrt{{p}_{NH}\ (1-{p}_{NH})/{N}_{S}}$$$$\simeq 2.64\times 1{0}^{-2}$$, which makes its confidence interval $${p}_{NH}\pm 2{\sigma }_{NH}$$ narrow and the statistical significance of the PE results robust. In general, given an embedding dimension $$D$$, any time-series with $$T$$ data points is analysed using non-overlapping windows with $$D\times D!\times {N}_{S}$$ data points. OP probabilities – as well as the corresponding PeEn value – are found for each of the $$T/D\times D!\times {N}_{S}$$ data windows and then averaged (namely, results are time-averaged).

For the state comparisons, we verified that PeEn distributes normally through Lilliefors test, and then applied a repeated measures ANOVA together with the Bonferroni post-hoc test and $$p < 0.05$$ in order for the result to be considered significant.