# How to compute the power bands of an eeg signal using python?

so I have an eeg signal (edf format) that has 25 channels and 248832 entries, sampling frequency of 512Hz. I have to compute the frequency bands: – Delta: 0.1-4Hz – Theta: 4-8Hz – Alpha: 8-12Hz – Sigma: 12-16Hz – Beta: 16-36Hz – Gamma: >36Hz and plot them accordingly. I am using Python for this with scipy, numpy, etc. and I should get to something like this:

Does anyone have any point-outs/ideeas/tutorials that could help me compute the bands and then get such a plot(probably a histogram)? Thanks!

• I would take a look at mne-python (martinos.org/mne/stable/index.html). Here is an example of frequency and time-frequency sensors analysis (for MEG sensors): martinos.org/mne/stable/auto_tutorials/… You can easily run it also on the EEG sensors. – Noam Peled Mar 30 '18 at 18:18
• where is the dataset link address? – HasanShovon Apr 28 '18 at 18:37
• @hasanshovon - can't post the data i used because of third party regulations! – user3640476 May 14 '18 at 9:48

Here is some code that may solve your problem:

from scipy.io import loadmat
import scipy
import numpy as np
from pylab import *
import matplotlib.pyplot as plt

eeg1=eeg['eeg1'][0]
fs = eeg['fs'][0][0]
fft1 = scipy.fft(eeg1)
f = np.linspace (0,fs,len(eeg1), endpoint=False)
plt.figure(1)
plt.plot (f, abs (fft1))
plt.title ('Magnitude spectrum of the signal')
plt.xlabel ('Frequency (Hz)')
show()


You can also check this other link:

http://forrestbao.blogspot.pt/2009/10/eeg-signal-processing-in-python-and.html

• thanks for the answer! and for the link, I already saw it but I kinda got stuck.. I don't really get what you are doing with eeg1 and fs? should eeg1 be a copy of the eeg channels? and fs the sampling frequencies of the signals? :D I'm gonna edit the post and add the code if this works! – user3640476 Nov 17 '17 at 14:52
• In the first part you can calculate the spectrum and observe it (I think this is not clear on the link). Then, on the link, you have the code to calculate the filters. The approach to design the bandpass filters is based on the "window method", the author calculates the impulse response (a sinc() function) for ideal filters (rectangular windows). – Filipe Pinto Nov 18 '17 at 15:39