# FFT to extract psd features

**URL:** <https://mne.discourse.group/t/fft-to-extract-psd-features/1784>\
**Category:** Mailing List Archive (read-only)\
**Tags:** list-archive\
**Created:** [March 13, 2019, 6:02pm UTC](https://mne.discourse.group/t/fft-to-extract-psd-features/1784 "2019-03-13T18:02:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [March 13, 2019, 6:02pm UTC](https://mne.discourse.group/t/fft-to-extract-psd-features/1784/1 "2019-03-13T18:02:29Z")

</div>

External Email - Use Caution

Hi all,  
I'm trying to use  
[https://github.com/pbashivan/EEGLearn/tree/master/Sample%20data](https://github.com/pbashivan/EEGLearn/tree/master/Sample%20data) to classify  
my epoched data. Everything is all right but I'm still not able to extract  
the frequency features to be like as mentioned the example:

FeatureMat\_timeWin:  
FFT power values extracted for three frequency bands (theta, alpha,  
beta). Features are arranged in band and electrodes order (theta\_1,  
theta\_2..., theta\_64, alpha\_1, alpha\_2, ..., beta\_64). There are seven  
time windows, features for each time window are aggregated  
sequentially (i.e. 0:191 --\> time window 1, 192:383 --\> time windw 2  
and so on. Last column contains the class labels (load levels).

Each of my epochs have 250 frames. I want to have 10 time windows for each  
epochs. I can add the las "labels" column. this is not a problem.  
Since I have 32 electrodes, I get using (mne.time\_frequency.psd\_welch) a  
tuple of (number of samples, 96). 96 corresponds to 3\*32. 32 electrodes \* 3  
frequency bands. That's all right but I need it to be windowed. So instead  
of having tuple of (number of samples, 93) I want to have a tuple of:  
(number of samples, 96\*number of time windows). I'm using the following  
code:

def eeg\_power\_band(epochs):  
&nbsp;&nbsp;&nbsp;FREQ\_BANDS = {"theta": [4.5, 8.5], "alpha": [8.5, 11.5], "beta": [15.5,  
30]}  
&nbsp;&nbsp;&nbsp;epochs = epochs.load\_data().pick\_channels(EEG\_CHANNELS).get\_data()  
&nbsp;&nbsp;&nbsp;psds, freqs = mne.time\_frequency.psd\_welch(epochs, n\_per\_seg=10,  
fmin=0.5, fmax=30.,n\_fft=250, n\_overlap=0)  
&nbsp;&nbsp;&nbsp;&nbsp;# Normalize the PSDs  
&nbsp;&nbsp;&nbsp;&nbsp;psds /= np.sum(psds, axis=-1, keepdims=True)

&nbsp;&nbsp;&nbsp;&nbsp;X = []  
&nbsp;&nbsp;&nbsp;&nbsp;for \_, (fmin, fmax) in FREQ\_BANDS.items():  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;psds\_band = psds[:, :, (freqs \>= fmin) & (freqs \<  
fmax)].mean(axis=-1)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#X.append(psds\_band.reshape(len(psds), -1))  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;X.append(psds\_band)

&nbsp;&nbsp;&nbsp;&nbsp;return np.concatenate(X, axis=1)

Many Thanks for any help  
-------------- next part --------------  
An HTML attachment was scrubbed...  
URL: [http://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/attachments/20190313/9de54e21/attachment.html](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20190313/9de54e21/attachment.html)
