1

I've a set of data from an EEG device from which I want to find the strength of different brain waves in Matlab. I tried to use EEGLAB but I wasn't really sure how, so at this point I'm simply using the dsp toolbox in Matlab.

For background: I've 15 epochs, 4 seconds in length. The device sampled at 256 Hz, and there are 264 sensors, so there are 1024 data points for each sensor for each epoch, i.e. my raw data is 264 x 1024 x 15. The baseline is removed. The data in each epoch is going to be used to train a classifier eventually, so I'm dealing with each epoch individually. I'll come up with more data samples later.

Anyways, what I've done so far is apply a Hann filter to the data and then run fft on the filtered data. So now I have the information in frequency domain. However, I'm not quite sure how to go from the power of the fft buckets to the power of certain frequency bands (e.g. alpha 8-13), to get the values I seek.

I know the answer should be straightforward but I can't seem to get find the answer I want online, and then there's further confusion by certain sources recommending using a wavelet transform? Here's the little bit of code I have so far, the input "data" is one epoch, i.e. 264 x 1024.

% apply a hann window
siz = size(data);
hann_window = hann(siz(2));
hann_window = repmat(hann_window.', siz(1), 1);
hann_data = data.' * hann_window; 

% run fft
X = fft(hann_data, [], 2);
X_mag = abs(X);
X_mag = X_mag.';

Thanks for the assistance!

anon
  • 407
  • 2
  • 12

1 Answers1

0

If I'm understanding your question correctly, you are wanting to scale the FFT output to get the correct power. To do this you need to divide by the number of samples used for the FFT.

X_mag = abs(X)/length(hann_data); % This gives the correct power.

See this question for more info.

Once the content is scaled correctly, you can find the power in a band (e.g. 8 - 13 Hz) by integrating the content from the start to the stop of the band. Since you are dealing with discrete values it is a discrete integration. For perspective, this is equivalent to changing the resolution bandwidth of a spectrum analyzer.

Community
  • 1
  • 1
nalyd88
  • 4,940
  • 8
  • 35
  • 51
  • Thanks for the response. That is something I needed to do, but that's not quite what I meant in my original post. Right now I have all the information stored in frequency bins. I want to get the combined power of a certain band (say, 8 Hz-13 Hz). How do I go from the former to the latter? Part of me wants to say to simply add up the values in the bins corresponding to the range; I'm just not 100% sure if that's the right thing to do. – anon Jul 08 '15 at 16:53
  • @anon You are mostly correct, just integrate the content in the bands (sum and multiply by the width of the bins). I'll update my answer. – nalyd88 Jul 09 '15 at 15:16
  • Ah, thanks for the response. Since all the bins have the same width, I think summing them is pretty much equivalent (I'm feeding them into a NN so any scaling from the width of the bins will be ignored come pre-processing). Thanks once again! – anon Jul 09 '15 at 22:04