# Calculate absolute power using mne

**URL:** https://mne.discourse.group/t/calculate-absolute-power-using-mne/2592
**Category:** Support & Discussions
**Tags:** eeg
**Created:** [January 26, 2021, 4:04pm UTC](https://mne.discourse.group/t/calculate-absolute-power-using-mne/2592 "2021-01-26T16:04:47Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![balandongiv](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/balandongiv/32/104_2.png) [@balandongiv](https://mne.discourse.group/u/balandongiv)
#### Post date: [January 26, 2021, 4:04pm UTC](https://mne.discourse.group/t/calculate-absolute-power-using-mne/2592/1 "2021-01-26T16:04:47Z")

</div>

I know the PSD can be computed using either [psd\_welch](https://mne.tools/stable/generated/mne.time_frequency.psd_welch.html) or [psd\_multitaper](https://mne.tools/stable/generated/mne.time_frequency.psd_multitaper.html#mne.time_frequency.psd_multitaper).

And the average band power power, which equal to an area under certain region, [can be calculated](https://raphaelvallat.com/bandpower.html) using the module simps of the scipy.

```python
from scipy.integrate import simps

# Frequency resolution
freq_res = freqs[1] - freqs[0] # = 1 / 4 = 0.25

# Compute the absolute power by approximating the area under the curve
delta_power = simps(psd[idx_delta], dx=freq_res)

```

But, I am wondering whether there is any build module to compute the absolute or relative band power of a signal. This question is especially of great interest since I would like to get the absolute power per channel and per epoch

Appreciate if someone can point me to the appropriate material/link

---

<div class="post-metadata">

### Author: ![balandongiv](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/balandongiv/32/104_2.png) [@balandongiv](https://mne.discourse.group/u/balandongiv)
#### Post date: [January 27, 2021, 8:10am UTC](https://mne.discourse.group/t/calculate-absolute-power-using-mne/2592/2 "2021-01-27T08:10:53Z")

</div>

Based on the tutorial [sleep stage classification](https://mne.tools/stable/auto_tutorials/sample-datasets/plot_sleep.html#sphx-glr-auto-tutorials-sample-datasets-plot-sleep-py),  
absolute and relative power can calculated as below

```python
from mne.time_frequency import psd_welch
# specific frequency bands
FREQ_BANDS = {"delta": [0.5, 4.5],
                  "theta": [4.5, 8.5],
                  "alpha": [8.5, 11.5],
                  "sigma": [11.5, 15.5],
                  "beta": [15.5, 30]}
 
psds, freqs = psd_welch(epochs, picks='eeg', fmin=0.5, fmax=30.)

 # Normalize the PSDs
    psds /= np.sum(psds, axis=-1, keepdims=True)

    X = []
    for fmin, fmax in FREQ_BANDS.values():
        psds_band = psds[:, :, (freqs >= fmin) & (freqs < fmax)].mean(axis=-1)
        X.append(psds_band.reshape(len(psds), -1))

```

---

<div class="post-metadata">

### Author: ![agramfort](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@agramfort](https://mne.discourse.group/u/agramfort)
#### Post date: [January 27, 2021, 9:26am UTC](https://mne.discourse.group/t/calculate-absolute-power-using-mne/2592/3 "2021-01-27T09:26:35Z")

</div>

yes or have a look at [https://github.com/mne-tools/mne-features/](https://github.com/mne-tools/mne-features/)

Alex
