so I am trying to compute the EEG(25 channels, 512 sampling rate, 248832/channel) bands (alpha, beta, gamma, etc.) with Python. I managed to do so by: firstly filtering the signal with a butterworth filter that looks like this:
def butter_bandpass_filter(data, lowcut, highcut, fs, order=2):
nyq = 0.5 * fs
low = lowcut /nyq
high = highcut/nyq
b, a = butter(order, [low, high], btype='band')
#print(b,a)
y = lfilter(b, a, data)
return y
I used the filter with the low set on 0.1 and high on 80. Than I compute the fft of the signal and store it in fft1, on which I use again the butterwort filter to extract the frequencies of each band and it looks like this:
for i in np.arange(n):
alpha1 = butter_bandpass_filter(fft1[i, :], 8.1, 12.0, 256)
beta1 = butter_bandpass_filter(fft1[i, :], 16.0, 36.0, 256)
gamma1 = butter_bandpass_filter(fft1[i, :], 36.1, 80, 256)
delta1 = butter_bandpass_filter(fft1[i, :], 0.0, 4.0, 256)
sigma1 = butter_bandpass_filter(fft1[i, :], 12.1, 16.0, 256)
theta1 = butter_bandpass_filter(fft1[i, :], 4.1, 8.0, 256)
sumalpha1 = sum(abs(alpha1))
sumbeta1 = sum(abs(beta1))
sumgamma1 = sum(abs(gamma1))
sumdelta1 = sum(abs(delta1))
sumsigma1 = sum(abs(sigma1))
sumtheta1 = sum(abs(theta1))
objects = [sumalpha1, sumbeta1, sumgamma1, sumdelta1, sumsigma1, sumtheta1]
N = len(objects)
ra = range(N)
plt.title(signal_labels[i])
plt.autoscale
somestuffneeded = np.arange(6)
ticks = ['alpha','beta','gamma','delta','sigma','theta']
plt.xticks(somestuffneeded, ticks)
plt.bar(ra, objects)
plt.show()
The problem is that I get a high value for gamma( which represents a high cognitive activity, which the person clearly didn't have). The result for the first channel is:
Can anyone point out a better solution/ has any ideas about what is wrong/ can tell me what is wrong? Am I using the filter incorect? Thanks!