Mar 16, 2026
  • M. Natalie Davis1
  • 1University of Alabama at Birmingham
Icon indicating open access to content
QR code linking to this content
Protocol CitationM. Natalie Davis 2026. EEG Analysis. protocols.io https://dx.doi.org/10.17504/protocols.io.bp2l6dzbzvqe/v1
License: This is an open access protocol distributed under the terms of the Creative Commons Attribution License,  which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited
Protocol status: Working
We use this protocol and it's working
Created: February 10, 2025
Last Modified: March 16, 2026
Protocol Integer ID: 119896
Keywords: eeg analysis, eeg analysis this protocol, downstream analysis of spectral analysis, sleep scoring, spike detection, sleep script, spectral analysis, downstream analysis
Abstract
This protocol outlines the EEG analysis used for the paper. It covers preprocessing, downstream analysis of spectral analysis, sleep scoring, and spike detection. Protocol adapted from Jorge Palop's lab at the Gladstone Institutes, modified by Natalie Davis in Erik Roberson's lab at the University of Alabama at Birmingham. Sleep scripts written by Anthoni Goodman.
Troubleshooting
Initial EEG Processing
Export EEG data as EDF (European Data Format) files in 24-hour blocks, starting at the beginning of the light phase and ending at the end of the dark phase.
Open 'DSI_Analysis_fromEDF.m' script in Matlab and adjust necessary parameters: Download DSI_Analysis_fromEDF.mDSI_Analysis_fromEDF.m27KB

(lines 15-26) Ensure all toggles are set to 1
(line 30) Change 'inputFolder' variable to the path to your folder containing EDF files
(line 33) Change 'outputFolder' name or path if desired
(line 49) Change 'days_to_analyze' variable to the number of days of recording you have
All other parameters should run as is, but adjustable depending on needs
Run Script. (This will probably take a few hours depending on the number of days of recording and the number of mice you have)
Output should give you a folder with:
  • output file for each mouse containing 1-minute binned data for Temperature, Activity, Each frequency band (raw signal and normalized), and Modulation Index (raw and normalized) for Theta/Gamma coupling
  • 'Figures' folder for each mouse containing 1-minute binned Temperature and Activity data, and example graphs for raw EEG, cleaned EEG, Spectrograms of Lights On/Off, Power Spectral Graphs of movement/rest for lights off/on, and MI for lights on/off
Power Data Processing
Run 'PowerDataCompiled.m' script in Matlab for further processing.
Download PowerDataCompiled_forSharing.mPowerDataCompiled_forSharing.m32KB
Change file paths to appropriate locations.
This script will:
1. Normalize raw power to the 10th percentile of total power for each frequency band
2. Extract and group data by power band
3. Group spectral activity
4. Bin spectral data by activity levels. This allows us to see how activity affects each power band. We use this for exclusion criteria, as noisy recordings show increases in activity in every frequency band. We use delta (which should decrease with activity) as a check and exclusion criteria.
5. Calculate hourly and ZT averages for the data.
6. Get Activity Averages
Further Downstream Analysis
There are many, many ways to analyze EEG data. The above methods allow us to examine each frequency band when normalized to total power for each mouse. This data was used for examining how EEG power varies across the 24-hour circadian cycle, how EEG power varies across activity states, and snippets of EEG spectra during periods of rest and activity. These data can be used in a variety of other ways as well.
Sleep Analysis
Sleep stages were scored using Sirenia Pro software. Sleep stages and power during sleep stages were exported to excel files. The following scripts were used to analyze time and power in each stage, as well as sleep bouts.
Sleep stage duration: Download SleepStage.mSleepStage.m4KB

Percent occupancy by hour: Download HourlyStageOccupancy_updated.mHourlyStageOccupancy_updated.m4KB

Sleep bouts: Download SleepBout.mSleepBout.m9KB

Spike Analysis
Spike2 Software (RRID:SCR_000903) was used to analyze spiking activity.
Apply a high pass FIR digital filter to EEG channel to remove low frequency noise below 6.3 Hz.
Find the standard deviation (SD) of the baseline of the new high pass filtered channel
Add 2 cursors 2 minutes apart, where EMG is active but EEG is spike-free.
Use 'Cursor Regions' tool to measure the SD between the set cursors and record this value.
Repeat this step two more time, finding three separate 2-minute sections of recording. Try to pull samples from the beginning, middle, and end of the recording.
Take the average of the 3 SD values to get baseline value.
Set spike detection threshold and multiply SD by this number (for example, spikes are generally detected at 7–10x the SD of baseline).
Create spike templates
Create 'New WaveMark' analysis
Select channel and apply the appropriate Template Settings. Example settings shown below:
Template settings for new spike templates

Adjust X and Y axes to appropriate windows for recording (I set x-axis at -50 to 80 ms wide and y-axis to ~-1 to 1).
Set horizontal cursors to +/- spike detection limit (e.g., 10x SD calculated).
Check 'Make templates', 'Track Cursor 0', and 'Jump to Start'.
Build templates by scrolling through the recording and combining spikes when appropriate.
Once you are satisfied with spike templates, manually sort through spikes
'Create New Channel'
Copy this channel as a memory channel and manually sort through spikes by adding or deleting detected datapoints from memory channel.
Once you are satisfied with your spike count, export events into a text file.
Calculate spikes/hour by summing your total spike count and dividing by the length of time analyzed. This can be for small sections, day vs night, or for the entire recording.