Plotting Frequency band for each Channels to extract Information

Hello,

  • operating system: Windows 10
    Currently plot looks like this:
    image

Is there a way to plot each channel with each frequency bands. Like for F3 channel - plotted like this:

For every channels.
So that I can extract features from them (bands).

I was looking at this link: Explore event-related dynamics for specific frequency bands — MNE 1.1.dev0 documentation

Is there anything that can help me with that.

Thanks

Hi Arjun,

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.

Hope that helps.

Best,

Carina

3 Likes

Hi @CarinaFo ,

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.

Thanks

Hi Arjun,

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:

https://mne.tools/stable/auto_tutorials/machine-learning/50_decoding.html

Best,

Carina

1 Like

Hi,

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.

Is there a way to do this?

Thanks

Hi @CarinaFo and @richard,

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?

Thanks all.

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.

Best wishes,
Richard

1 Like

Hi @CarinaFo & Richard,

Have followed the method suggested by you and plotted the frequency band.

In the plot gamma, beta and alpha signal seem to not exist.
Theta also not that strong. For plotting have followed along this link Explore event-related dynamics for specific frequency bands — MNE 1.1.0 documentation
Is there a way to get the frequency bands clear?

Thanks

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:

fig, axes = plt.subplots(4, 1, figsize=(10, 7), sharex=True, sharey=True)
3 Likes

Hi Dan,

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?

Thanks

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.

1 Like

Thanks. Is there an ideal time limit for epochs with eeg signals? Does it depend on the dataset?

There is no ideal, it is determined by your research question.

1 Like