# PSD Welch function average argument for Epochs

**URL:** https://mne.discourse.group/t/psd-welch-function-average-argument-for-epochs/5144
**Category:** Support & Discussions
**Tags:** time-frequency, eeg, epochs
**Created:** [June 22, 2022, 10:47pm UTC](https://mne.discourse.group/t/psd-welch-function-average-argument-for-epochs/5144 "2022-06-22T22:47:25Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![teanijarv](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/teanijarv/32/1412_2.png) [@teanijarv](https://mne.discourse.group/u/teanijarv)
#### Post date: [June 22, 2022, 10:47pm UTC](https://mne.discourse.group/t/psd-welch-function-average-argument-for-epochs/5144/1 "2022-06-22T22:47:25Z")

</div>

Regarding mne.time\_frequency.psd\_welch function, I cannot seem to understand how the average argument is affecting the Welch’s power spectra estimate - the results are the same for me with ‘mean’ and ‘median’ passed as averaging methods. I was hoping that using median would be more effective in case some epoch still has artefacts in them and maybe these artefacts wouldn’t affect the final PSD for that epoch that much.

And in overall, is this the correct way to estimate PSD for epochs in EEG or do you recommend any other ways?

```python
sfreq = epochs.info['sfreq'] # sampling frequency in my case is 1024
epoch_duration = 2 # each epoch is 2s long
psds, freqs = mne.time_frequency.psd_welch(epochs,n_fft=int(sfreq*epoch_duration),fmin=1,fmax=100,average='mean')

```

---

<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: [June 23, 2022, 7:56am UTC](https://mne.discourse.group/t/psd-welch-function-average-argument-for-epochs/5144/2 "2022-06-23T07:56:39Z")

</div>

I would check that the epochs are long enough such that there are least 2 windows in the welch periodogram computation

Alex

---

<div class="post-metadata">

### Author: ![teanijarv](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/teanijarv/32/1412_2.png) [@teanijarv](https://mne.discourse.group/u/teanijarv)
#### Post date: [June 23, 2022, 1:00pm UTC](https://mne.discourse.group/t/psd-welch-function-average-argument-for-epochs/5144/3 "2022-06-23T13:00:02Z")

</div>

Thanks for the quick answer and thank you for creating this immersive library!  
So you mean for example to have the epoch duration 4 seconds (4096 samples) and in psd\_welch function argument n\_fft 2 seconds (2048 samples)? Is there a specific rationale for this which you could explain me?

---

<div class="post-metadata">

### Author: ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)
#### Post date: [June 24, 2022, 8:08pm UTC](https://mne.discourse.group/t/psd-welch-function-average-argument-for-epochs/5144/4 "2022-06-24T20:08:55Z")

</div>

if the epochs are short enough that only 1 welch window is used, then there is no averaging to be done, so both `mean` and `median` will return the same thing, e.g., the estimate from the one single welch window.
