[FieldTrip] Issue with visualising EEG Spectrogram

Schoffelen, J.M. (Jan Mathijs) jan.schoffelen at donders.ru.nl
Wed Jun 19 15:39:48 CEST 2019


Daniel, it looks as if the baseline correction is not applied. You’d need to specify cfg.baseline = ‘yes’ in order to achieve this.
Note also, that I again recommend to do the baseline correction in a separate step, not asking the plotting function to do it.
Recursive baseline corrections with a ‘relchange’ may be problematic, since at some point you start dividing by 0.
Best,
JanMathijs


On 19 Jun 2019, at 14:15, Daniel Campoy (CMP - Student) <D.Campoy at uea.ac.uk<mailto:D.Campoy at uea.ac.uk>> wrote:

Hi Jan-Mathijs,

Thank you for replying back to me.  I made the suggested changes and I’m seeing better results as the majority of the area is not as blue and on some of the channels I’m seeing a more defined shaped.  In case you are interested I attached the new results.  Overall I’m satisfied with the results and see in come trials a more clearer response.

I added a couple questions to two of your suggestions below.

This is the new block of code as well.

cfg              = [];
                    cfg.output       = 'pow'; %return power spectra
                    cfg.channel      = 'all';
                    cfg.method       = 'wltconvol';
                    %cfg.trials       = trigger_idx; %specify index location to find event in EEG_Data_Trial.trial
                    cfg.width        = 1; % 3 has shown some promise for results
                    cfg.gwidth       = 4; %decreasing this has shown to fill out are of the figure
                    cfg.pad          = 20; %increases resolution as the value goes up
                    cfg.foilim       = [1 30]; %1 to 30 Hz range
                    %cfg.toi          = -.10:0.0001:.35; %produced a full image time window from -100 ms to 350ms in 0.1ms steps
                    cfg.toi          = -.05:0.00001:.250; %time window from -50 ms to 250ms in 0.01ms steps

                    TFRwavelet = ft_freqanalysis(cfg, EEG_Data_Trial);
                    fprintf('\n Time-Freq wavelet for trigger index %u channel %s and processed %u trigger(s)\n',trigger_idx(i),channels{z},i)
                    %Create Image of EEG Spectrogram to output cdat matrix
                    cfg = [];
                    %cfg.baselinetype = 'relchange';
                    cfg.maskstyle = 'saturation';
                    cfg.zlim         =  'maxmin';
                    cfg.layout       = 'ordered';
                    cfg.showlabels   = 'yes';
                    cfg.showoutline      = 'yes';
                    %subplot(2,4,z)%used to create figures of plotted channels
                    [EEG_Spec] = ft_multiplotTFR(cfg, TFRwavelet);





1 a). You can run ft_freqanalysis for all channels at once (without the for-loop)

From my understanding if I supply all channels for ft_freqanalysis and use ft_singleplotTFR then this will show one plot for a trial  with an average across all the channels (in my case 8).

1 b). You may want to use cfg.method = ‘wltconvol’ for ft_freqanalysis, rather than ‘wavelet’ , since it’s much faster with equivalent results.

2). Next, you can call ft_freqbaseline (again: only once, and perhaps use ‘relchange’ as a method) to ‘baseline correct' the spectrograms.

What are the consequences of  running this more than once?

3). Next, you can use ft_multiplotTFR on the baseline corrected variable, using a cfg.layout = ‘ordered’, and don’t specify any baseline correction options here.


If I use ft_singleplotTFR again would you recommend I omit the baseline parameter too?


I also want to add that when performing ft_freqanalysis I’m seeing these messages “Warning: output time-bins are different from input time-bins, multiples of the sametrial” for all my trails processing. When I’m looking at the trial cell data type and looking at the maxtrix defined inside their numbers are not same.  I was not able to find much information as to exactly how this is triggered. I did find the line of code the produces this but not entirely sure why it is triggered.  Is this message typically ignored?


Kind Regards,

Daniel C.

Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10

________________________________
From: fieldtrip <fieldtrip-bounces at science.ru.nl<mailto:fieldtrip-bounces at science.ru.nl>> on behalf of Schoffelen, J.M. (Jan Mathijs) <jan.schoffelen at donders.ru.nl<mailto:jan.schoffelen at donders.ru.nl>>
Sent: Wednesday, June 19, 2019 10:24:23 AM
To: FieldTrip discussion list
Subject: Re: [FieldTrip] Issue with visualising EEG Spectrogram

Hi Daniel,

May I suggest you to do 4 things, rather than trying to really understand why no apparent baselining seems to have been applied.

1 a). You can run ft_freqanalysis for all channels at once (without the for-loop)
1 b). You may want to use cfg.method = ‘wltconvol’ for ft_freqanalysis, rather than ‘wavelet’ , since it’s much faster with equivalent results.
2). Next, you can call ft_freqbaseline (again: only once, and perhaps use ‘relchange’ as a method) to ‘baseline correct' the spectrograms.
3). Next, you can use ft_multiplotTFR on the baseline corrected variable, using a cfg.layout = ‘ordered’, and don’t specify any baseline correction options here.

Best wishes,
Jan-Mathijs




On 18 Jun 2019, at 20:12, Daniel Campoy (CMP - Student) <D.Campoy at uea.ac.uk<mailto:D.Campoy at uea.ac.uk>> wrote:

Hello,

I have been stuck trying to understand the results I’m seeing so please forgive me as my background is not in neuroscience. I’m a Masters student working with EEG data for a classification project using Matlab 2017b.

I have been successful at visualising the data of a test subject for a specific trigger and plot all channels (dataset has 8 channels) from the trigger (image stimuli) using ft_singleplotTFR. Thus creating a 2x4 plot of images for all 8 channels.  However I’m stuck trying understand my results when I plot an EEG spectrogram using ft_singleplotTFR for each channel across all triggers (T=1 in my dataset) the data does not show what I’ve seen for separate channels. It displays a plot of 8 images filled blue and a fine yellow/green bar across the bottom.  The only thing I’ve changed is supplying all the trials instead of one at a time using a for loop to iterate through each trial for 8 channels. I’ve removed the for loop outside of the for loop of channels since I’m supplying all trials. Below is my code and process. Any insight would be much appreciated and if you need further information please let me know.  I’ve attached an image of the results of each channel across all triggers.


My first step is to load the .mat file I’ve saved containing all the defined trials. After this is complete, the below code is used to extract all the trigger events where the value in cfg.events is T=1.  I run the ft_preprocessingagain but for the defined trials I’m looking for T=1.

trigger = extractfield(cfg.event,'value');
channels = EEG_Data.cfg.channel;
trigger_idx = find(startsWith(trigger,'T=1'));
cfg.trials       = trigger_idx; %index location for all T=1 stimuli triggers
EEG_Data_Trial = ft_preprocessing(cfg,EEG_Data);


After completion the next block of code is ran for each channel. You may have noticed the cdat variable is in the output, this is me modifying the ft_singleplotTFR function to return the EEG spectrogram matrix I use for later analysis.


figure %used to create a figure of EEG Spectrograms

for z = 1:length(channels) %Collect the measurements from each channel for a given trigger
                    Img_idx = 1 + Img_idx;
                    cfg              = [];
                    cfg.output       = 'pow'; %return power spectra
                    cfg.channel      = channels{z};
                    cfg.method       = 'wavelet'; %use wavelet function
                    %cfg.trials       = trigger_idx; %specify index location to find event in EEG_Data_Trial.trial
                    cfg.width        = 1; % 3 has shown some promise for results
                    cfg.gwidth       = 4; %decreasing this has shown to fill out are of the figure
                    cfg.pad          = 20; %increases resolution as the value goes up
                    cfg.foilim       = [1 30]; %1 to 30 Hz range
                    %cfg.toi          = -.10:0.0001:.35; %produced a full image time window from -100 ms to 350ms in 0.1ms steps
                    cfg.toi          = -.05:0.00001:.250; %time window from -50 ms to 250ms in 0.01ms steps

                    TFRwavelet = ft_freqanalysis(cfg, EEG_Data_Trial);
                    fprintf('\n Time-Freq wavelet for trigger index %u channel %s and processed %u trigger(s)\n',trigger_idx(i),channels{z},i)
                    %Create Image of EEG Spectrogram to output cdat matrix
                    cfg = [];
                    cfg.baselinetype = 'absolute';
                    cfg.maskstyle = 'saturation';
                    cfg.zlim         =  'maxmin';
                    subplot(2,4,z)%used to create figures of plotted channels
                    [EEG_Spec,cdat] = ft_singleplotTFR(cfg, TFRwavelet);
                    subplot(2,4,z)%used to create figures of plotted channels
end

Thank you and kind regards,

Daniel C.
<OneSub_acrossTrails_T1.png>_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmailman.science.ru.nl%2Fmailman%2Flistinfo%2Ffieldtrip&data=02%7C01%7CD.Campoy%40uea.ac.uk%7C0d621a78d97846b0dc3508d6f4983ae3%7Cc65f8795ba3d43518a070865e5d8f090%7C0%7C0%7C636965332006247409&sdata=4UGJMnGMb2swnfBUuhyzfLOzEU09VmONTG98868xfmE%3D&reserved=0>
https://doi.org/10.1371/journal.pcbi.1002202<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdoi.org%2F10.1371%2Fjournal.pcbi.1002202&data=02%7C01%7CD.Campoy%40uea.ac.uk%7C0d621a78d97846b0dc3508d6f4983ae3%7Cc65f8795ba3d43518a070865e5d8f090%7C0%7C0%7C636965332006247409&sdata=KuDpLZP51plE5ifAuPvM5xD8WiHQyvMWKuPJBLZOagM%3D&reserved=0>

<10HzSub02a_T1_All_Trials.png>_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://doi.org/10.1371/journal.pcbi.1002202

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20190619/3eaa0f31/attachment-0002.html>
-------------- next part --------------
_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://doi.org/10.1371/journal.pcbi.1002202


More information about the fieldtrip mailing list