# Power spectral analysis

**URL:** <https://mne.discourse.group/t/power-spectral-analysis/3663>\
**Category:** Support & Discussions\
**Tags:** time-frequency, eeg\
**Created:** [September 7, 2021, 1:41am UTC](https://mne.discourse.group/t/power-spectral-analysis/3663 "2021-09-07T01:41:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kkaya](https://avatars.discourse-cdn.com/v4/letter/k/ba8739/32.png) [@kkaya](https://mne.discourse.group/u/kkaya)\
**Post date:** [September 7, 2021, 1:41am UTC](https://mne.discourse.group/t/power-spectral-analysis/3663/1 "2021-09-07T01:41:39Z")

</div>

Dear MNE experts,

I’m trying analyze a clinical EEG data. The goal is to indicate reduction of the 8-15 Hz activity (maybe delta waves as well).

First, the bandpass filter is set at 0.1-70 Hz. Then, 2 seconds EEG data from each channels are detrended as one series by using mne.Evoked.detrend function.

Here, I have two questions.

1. How can I apply a Hanning window to reduce the effect of spectral leakage and then transform each series into a frequency domain by FFT, from which the power spectrum at 8–15 Hz bandwidth can obtain?

2. How can I smooth the 2 seconds power spectra with Welch’s method through averaging 10 series?

I would be grateful if anyone can help me how properly perform this analysis with MNE.

Thank you!!

Kutlu Kaya

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [September 8, 2021, 8:27pm UTC](https://mne.discourse.group/t/power-spectral-analysis/3663/2 "2021-09-08T20:27:48Z")

</div>

Hello @kkaya and welcome to the forum!

I’m not very knowledgable re filters and FFT, but I suspect @larsoner might be able to help!

Best wishes,  
Richard

---

<div class="post-metadata">

**Author:** ![larsoner](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/larsoner/32/3_2.png) [@larsoner](https://mne.discourse.group/u/larsoner)\
**Post date:** [September 13, 2021, 1:55pm UTC](https://mne.discourse.group/t/power-spectral-analysis/3663/3 "2021-09-13T13:55:42Z")

</div>

> How can I apply a Hanning window to reduce the effect of spectral leakage and then transform each series into a frequency domain by FFT, from which the power spectrum at 8–15 Hz bandwidth can obtain?

You can always get the data yourself using `epochs.get_data()`, then multiply by `numpy.hanning(data.shape[-1])`, then call `scipy.fft.rfft` and use `scipy.fft.rfftfreq` to get the frequencies associated with the FFT.

However, for a simpler approach (and also more robust via using multitaper estimation rather than just a Hanning window) you could use [https://mne.tools/dev/generated/mne.time\_frequency.psd\_multitaper.html](https://mne.tools/dev/generated/mne.time_frequency.psd_multitaper.html). Either way, after this, you could average over the 8-15 Hz band.

> How can I smooth the 2 seconds power spectra with Welch’s method through averaging 10 series?

I would use `psd_multitaper` as above to get single-epoch multitaper estimates, then average across epochs (which makes it Welch-like), then average over the frequencies in the 8-15 Hz range. At least I think this will get you what you’re looking for…

---

<div class="post-metadata">

**Author:** ![kkaya](https://avatars.discourse-cdn.com/v4/letter/k/ba8739/32.png) [@kkaya](https://mne.discourse.group/u/kkaya)\
**Post date:** [September 20, 2021, 2:17am UTC](https://mne.discourse.group/t/power-spectral-analysis/3663/4 "2021-09-20T02:17:53Z")

</div>

Thank you so much Richard and Eric for your responses.

Eric, I will work on your suggestions. All is very useful. Much appreciated!

Kutlu
