I think you are already on the right track. If I am right you can simply add another loop that goes through the channel list and calculates frequency bands for each channel. This is for sure not the most efficient way to do it but it works. Happy to hear more efficient solutions.
event_id, tmin, tmax = 1, -1., 3.
baseline = None
# get the header to extract events
raw = mne.io.read_raw_fif(raw_fname)
events = mne.find_events(raw, stim_channel='STI 014')
channel_list = raw.pick_types(meg='grad').ch_names
channel_frequency_list = list()
frequency_map = list()
for ch in channel_list:
for band, fmin, fmax in iter_freqs:
# (re)load the data to save memory
raw = mne.io.read_raw_fif(raw_fname)
raw.pick_types(meg='grad', eog=True) # we just look at gradiometers
raw.load_data()
# bandpass filter
raw.filter(fmin, fmax, n_jobs=15, # use more jobs to speed up.
l_trans_bandwidth=1, # make sure filter params are the same
h_trans_bandwidth=1) # in each band and skip "auto" option.
# epoch
epochs = mne.Epochs(raw, events, event_id, tmin, tmax,
baseline=baseline,
reject=dict(grad=4000e-13, eog=350e-6),
preload=True)
epochs.pick_channels([ch])
# remove evoked response
epochs.subtract_evoked()
# get analytic signal (envelope)
epochs.apply_hilbert(envelope=True)
frequency_map.append(((band, fmin, fmax), epochs.average()))
channel_frequency_list.append(frequency_map)
If you only need features I wouln’t plot all of that, but store it in a numpy array or csv file.
Thanks will try it out, but first I have my data set in .csv and when I converted it into .fif I’m only able to access the eeg channels, not able to access the events column.
The link to that problem is below, if have any ideas let me know.
Is the data you are showing in the .csv already preprocessed and ready for prediction? If so, I am not sure why you would want to convert the data to a .fif file? The machine learning pipeline in mne follows the sci-kit learn API and therefore the data is extracted from the raw or epoched .fif file anyways, as you can see in this tutorial:
The dataset contains recording of 14 channels and their event/class. There are totally 4 classes among which listening and resting are two.
I want to predict the 4 classes based on the 14 EEG channels and see which frequency band influence the result more.
And also mne.find_events only detects two classes and not sure which two classes they represent.
I want to perform classification / prediction on the 4 classes that’s present w.r.t the 14 EEG channels and and see which frequency band or features influence the result more.
Is there a way to do this?
You could band-pass filter the data to retain only the frequency range(s) of interest and then feed the filtered data into one of our MVPA methods. @CarinaFo posted a link to a tutorial a bit farther up.
This is all advice I can give you at this point. I cannot help you perform an entire analysis; I can only help resolve specific technical questions.
look at your y-axis limits. The scale is about 0-5 × 10⁻¹¹. Compare to the tutorial you linked to: the scale is 10⁻²¹. So your theta is really big compared to what is seen in the tutorial. if you change the y-axis limits for the other plots you’ll probably see something more informative. A quick way would be to remove sharey=True from this line of the tutorial:
Thanks a lot now it’s visible.
But why are the frequency bands getting plotted between -200 ms to 500 ms?
Is there something that I have to change from the link to get the frequency band for the entire duration.
Could you please let me know?
The time limits on the plot axis are set in the code by set_xlim, which may not match the time limits of your epochs. I’m guessing your epochs start at -200ms and end at +500ms.