# Extracting alpha, beta, gamma, theta , delta frequency band from EEG data

**URL:** <https://mne.discourse.group/t/extracting-alpha-beta-gamma-theta-delta-frequency-band-from-eeg-data/8801>\
**Category:** Support & Discussions\
**Created:** [May 13, 2024, 3:14pm UTC](https://mne.discourse.group/t/extracting-alpha-beta-gamma-theta-delta-frequency-band-from-eeg-data/8801 "2024-05-13T15:14:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sayuksh](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/sayuksh/32/3661_2.png) [@Sayuksh](https://mne.discourse.group/u/Sayuksh)\
**Post date:** [May 13, 2024, 3:14pm UTC](https://mne.discourse.group/t/extracting-alpha-beta-gamma-theta-delta-frequency-band-from-eeg-data/8801/1 "2024-05-13T15:14:43Z")

</div>

- MNE version: 1.6.1
- Platform - Kaggle  
i tried extracting the bands result values are coming zero

```python
import matplotlib.pyplot as plt
import numpy as np
import mne
from mne.baseline import rescale
from mne.datasets import somato
from mne.stats import bootstrap_confidence_interval
iter_freqs = [("Theta", 4, 7), ("Alpha", 8, 12), ("Beta", 13, 25), ("Gamma", 30, 45)]

# set epoching parameters
event_id, tmin, tmax = 7, -1.0, 3.0
baseline = None
raw_fname="/kaggle/input/deap-datasetraw-data/s01.bdf"
# get the header to extract events
raw1 = mne.io.read_raw_bdf(raw_fname)
del_channels =['EXG1', 'EXG2', 'EXG3', 'EXG4', 'EXG5', 'EXG6', 'EXG7', 'EXG8', 'GSR1', 'GSR2', 'Erg1', 'Erg2', 'Resp', 'Plet', 'Temp']
raw = raw1.drop_channels(del_channels)
print(raw.info['ch_names'])
events = mne.find_events(raw)
print(events)

print(events,"apple")
frequency_map = list()

for band, fmin, fmax in iter_freqs:
    # (re)load the data to save memory
    raw = mne.io.read_raw_bdf(raw_fname)# we just look at gradiometers
    raw.load_data()

    # bandpass filter
    raw.filter(
        fmin,
        fmax,
        n_jobs=None, # use more jobs to speed up.
        l_trans_bandwidth=1, # make sure filter params are the same
        h_trans_bandwidth=1,
    ) # in each band and skip "auto" option.

    # epoch
    epochs = mne.Epochs(
        raw,
        events,
        event_id,
        tmin,
        tmax,
        baseline=baseline,
        reject=None,
        preload=True,
    )
    # remove evoked response
    epochs.subtract_evoked()

    # get analytic signal (envelope)
    epochs.apply_hilbert(envelope=True)
    frequency_map.append(((band, fmin, fmax), epochs.average()))
    del epochs
del raw
# Helper function for plotting spread
def stat_fun(x):
    """Return sum of squares."""
    return np.sum(x**2, axis=0)

# Plot
fig, axes = plt.subplots(4, 1, figsize=(10, 7), sharex=True, sharey=True)
colors = plt.colormaps["winter_r"](np.linspace(0, 1, 4))
for ((freq_name, fmin, fmax), average), color, ax in zip(
    frequency_map, colors, axes.ravel()[::-1]
):
    times = average.times * 1e3
    gfp = np.sum(average.data**2, axis=0)
    gfp = mne.baseline.rescale(gfp, times, baseline=(None, 0))
    ax.plot(times, gfp, label=freq_name, color=color, linewidth=2.5)
    print(gfp)
    ax.axhline(0, linestyle="--", color="grey", linewidth=2)
    ci_low, ci_up = bootstrap_confidence_interval(
        average.data, random_state=0, stat_fun=stat_fun
    )
    ci_low = rescale(ci_low, average.times, baseline=(None, 0))
    ci_up = rescale(ci_up, average.times, baseline=(None, 0))
    ax.fill_between(times, gfp + ci_up, gfp - ci_low, color=color, alpha=0.3)
    ax.grid(True)
    ax.set_ylabel("GFP")
    ax.annotate(
        "%s (%d-%dHz)" % (freq_name, fmin, fmax),
        xy=(0.95, 0.8),
        horizontalalignment="right",
        xycoords="axes fraction",
    )
    ax.set_xlim(-1000, 3000)

axes.ravel()[-1].set_xlabel("Time [ms]")

```

output

 ![image](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/d/d3598898fbc82793e2dd908920bd3c3fe3ffbc15.png)

---

<div class="post-metadata">

**Author:** ![CarinaFo](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/carinafo/32/746_2.png) [@CarinaFo](https://mne.discourse.group/u/CarinaFo)\
**Post date:** [May 14, 2024, 9:15am UTC](https://mne.discourse.group/t/extracting-alpha-beta-gamma-theta-delta-frequency-band-from-eeg-data/8801/2 "2024-05-14T09:15:30Z")

</div>

Hello Ayush,

It might be a scaling issue. Did you check the values in the frequency map? Are they all zero or just really small values? Power is usually very small, if you change the y-axis limits according to the power values you should see the band power modulations.

Hope that helps.

Best,

Carina
