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:

enter image description here

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!

  • $\begingroup$ 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. $\endgroup$
    – Noam Peled
    Commented Mar 30, 2018 at 18:18
  • $\begingroup$ where is the dataset link address? $\endgroup$ Commented Apr 28, 2018 at 18:37
  • $\begingroup$ @hasanshovon - can't post the data i used because of third party regulations! $\endgroup$ Commented May 14, 2018 at 9:48

1 Answer 1


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

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

You can also check this other link:


  • $\begingroup$ 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! $\endgroup$ Commented Nov 17, 2017 at 14:52
  • $\begingroup$ 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). $\endgroup$ Commented Nov 18, 2017 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.