L9: MNE tutorial part #2 - EEG/ERP Visualization and Time-Frequency Analysis
By Berdakh Abibullaev (EEG, BCI & Machine learning)
Summary
Topics Covered
- Average ERPs to Reveal P300
- Topo Maps Pinpoint P300 Peak
- Contrast Maps Highlight Differences
- ROI Analysis Isolates Hemisphere Effects
- Morlet Wavelets Capture Time-Frequency
Full Transcript
hello students today i will continue the tutorial on using the mne toolbox for analyzing eeg or mg data so in the previous class we have seen how we can load the
data into many environment how we can perform some basic pre-processing such as removing the iblink related artifact using ica or performing some segmentation
i will show you different ways that we can use mne to visualize the data this will be very helpful to reproduce all those figures the graphs that we have covered in the
lecture it is also important to gain some insight in the data for exploratory data analysis visual inspection of the eeg data and
possibly using or generating high quality figures for real reports today i will be using
the jupiter lab ide for demonstrating all those visualization let me first load the data that we have segmented from the previous
class right so first import mne and matplotlib and the file name is as follows so oddball dash epo dot fifth
is our segmented erp data set we're going to be using the mne read epocs method to load this data
so like let's take a look how it looks like let me create epoch
okay info this is information field and just epochs from the previous class
and it's consisted of standard and then target erps so the standard is non-target erp target erp where total number of trials are equal to 106
after equalizing and we have the following duration segmented 200 milliseconds pre-stimulus and 500 milliseconds after the stimulus
or after the stimuli we can take a look at epochs get data some of the examples of number a
okay so this is our data set by array so after performing segmentation what is the next step okay what we can because we have
two different conditions the first step in the analysis of the rps to visualize the visual in spec so for that we can first perform averaging
across target and then non-target erps so the mne has the method called averaging okay which performs as everything across all
target examples and let's call the non-target as standard the next step would be to visualize this average target and non-territory
standard erps let's first quickly compare the numpy array dimensionality before and after averaging so
here target and standard correspond to the averaged erps from 106 trials each
epochs get data shape this is the dimensionality of the all data including target and
standard erp's let's get epochs target get data shaped this is our numpy array shape so with 106 trials 63 channels plus stimulus channel and
then 71 time points now let's take a look at the average target dimensionality so the dimensionality of the average target erp is as follows 63 channel
and time points across 106 trials all right so target info should provide us information about this object so all these easy channels 63
channels okay and if you want to see all the names of these channels you can target that info then type channel names which will show all the channel names now next step is to explore the
visualization capabilities of mne so for that we call our deer function and then target just to check what kind of plot function we have here
we usually look for these functions so plot plot field plot image plot joint topo map sensors topo and some other
points so we're interested in these methods okay
so let's pick some of them okay and then explore let me just copy paste for reference now okay
now first step is let's try to see the plot method okay and then yeah just try to plot the
average erp this is averaged erp from 106 trials target erp you can see here some we can see a prominent evolution of the
p300 waveform from 0.2 seconds it is 200 milliseconds and up to
400 milliseconds we can also check other methods and functions
for example target plot topo map allows us to visualize this topographic map of this erp across the following time points okay so we can
consult the documentation to show what kind of parameters we can set here times channel type layout and some other information
so let's try to set these times from not from auto but times is it the following so we can indicate we want to see the
top of my at 100 millisecond 200 second 300 millisecond 400 millisecond
or 500 millisecond all right so we can analyze it in this way and we have other function called plot joint so plot joint
shows us join plot as the name implies of the original time series visualization plus topo map
here also we can define these times let's just copy and paste here and then see yes
so 100 millisecond template values of erp 200 milliseconds 300 milliseconds 400 milliseconds and 500 milliseconds so for example if you delete some peak here located
so if you want to see if you want if you want to see where in the brain this peak or is happening we can just try to find this time point and set here
so let's instead of four hundred millisecond try to set 370
milliseconds okay so almost peak so by just looking at this right top them up we see
increase amplitude of the erp in the occipital engine of the arp we also have
some method that we can show the difference or the contrast between target and non-target erps for example we can get the difference
between target and then standard erps and try to visualize the joint topographic plot
right so what does mne combine invoked does is that we can simply subtract target non-target amplitudes and get some
contrast on the difference between two or apply some weighting of for each above dataset
so here let's say this point okay so the first of all what's shown here is the difference between target and non-target
and topographic image here so we can for example copy and see more details of this visualization
as follows okay so here again across five different time points what we see is spatial and temporal distribution or spatial temporal feature of
eeg further we can try to plot the difference difference between target and non-target as a color-coded heat map let's call it as heat map
or some image these are channel indexes time point micro volt amplitude values so we see the difference between two conditions target and non-target around
this sample this is very clear and i would say beautiful visualization that shows the difference between target and on target further we can define the regions of
interest for example here we see all 63 channels but we can split all those sensors according to left or right hemisphere or midline so for that we utilize one of the method
called as make 10 to any channel selection based on the mid line okay and then select three regions of regions of interest the left hemisphere
all these channels midline all those channels located in the midline center and right hemisphere here all the channels from the first region of interest second region of
interest and third region of interest as you can see here all these odd numbers coupled with these characters represent the channels on the left hemisphere of the brain we see some interesting activity
happening here the plot image again allows us to group all the channels by the region of interest that you define left midline or right so midline
channels here some of the midline channels those are areas where central cz all those located also interesting
difference between target and montana these channels right hemisphere 20 channels all right we can also use the following function
called plot compare evoked which allows us to compare multiple conditions two conditions in our case
time evolution look this is okay after calling this function let me just type it okay we pass standard and then target and we
select one of the channel 13 is the location of cz channel and we can compare this is target and the blue line
non-target for single channel here we have onset of the stimuli so visually we can observe there is a significant difference between target and non-target europe at this channel
what about channel 17 cp1 okay what about channel 3 on this channel so fc well here the amplitude of target is going down and location
is here we don't see much difference between two conditions what about two two is f seven which is looking at here what about nine
fc2 okay we don't see much difference between target and non-target yes so this kind of analysis helps you to visually confirm the difference between target and non-target of course
how many provide statistical methods statistical tests also to that you can utilize for significance tests or when it comes to difference within target and
non-target erps let's take a look at some other plotting function we mentioned about this target and non-target eminent object okay let me zoom back and then
go back here okay we mentioned we said that these are the plot functions that our objects are
let me just put it here another row now target plot okay let's take a look at sensors send
sensors okay if you do that yeah these are the locations of the eeg sensors
that the data were collected using so if i'm show names let me try this if i'm okay yeah so we can show the names of the channels
well this again another helpful plotting function that allows you to quickly visualize
the location of channels okay and the data that were collected what else do you have plot
topo topo map topo double map let's try
plot topper topography of evoked responses so plot top allows you to
plot time series representation of erp on the space look these are the location of channels this one is cz
most likely and we can define what we are seeing here is erp data on these locations on eeg channel locations erb data
all right we have seen some of the capabilities of the mne visualization functions or methods useful for target or non-target drp or general for
many eeg objects eg data now the question is can we visualize the eeg can we visualize these using the matplotlib so first yes the answer is so first
let's get the data out as a numpy this is our target average from e-box let's just buy and then
and then the import matplotlib yeah so can we visualize this using the matplotlib with
that we may need to define the channel names we just kept from target in for channel names
okay if you run this all right so these are the channels available enable scrolling next step
is let's try to write down a piece of code that will allow us to map from index to these following channel names
channel for example c4 okay let's write down this to map from channel labels to
numpy indices and then basically we can plot it using matplotlib x okay zero
and then all plot title channel y label is simply toot is time samples
let's try okay here we have the example data from c4 channel okay if you want c z
okay here data from cz let's say f1 f1 is it changing yeah it is so
basically you can get the numpy layout from the mne object and then use matplotlib's visualization tool to visualize yeah or let's visualize all data
superimposed okay here so all the data in our numpy array now let's take a look at the time frequency analysis
methods of the mne for example power spectral density right we have seen that as visualizing the power spectral density of eeg so we first read the data that we have
segmented with a longer duration so oddball long epoch this is epoch and then um just like we did before plot power spectral density call it those and parameters this function allows us to
perform particle density and then visualize f mean f max so frequency minimum maximum frequency range from which time spirit mean max and some other
okay information plot the power spectral density across all channels okay now let's define the minimum and maximum frequency range
to be from 2 hertz and 20 hertz from 2 to 20 hertz and then try to
visualize this part y axis show the decimal okay and x shows a hertz frequency these are the channels from all 63 channels okay
the parse metal channel specific power spectral density data most of the useful information is in eg is located between
let's say 0 and 40 hertz yes so here we can see from 0 to 40.
okay so this is a typical pulse spectral density of eeg channels why do we see this line here and why
the parseval density goes to down after this 20 hertz one of the reasons that we did bandpass we applied bandpass filter for our
data let me type here so that pre-processing related information is stored in the epochs and then that info here
high pass low pass we did perform high pass and low pass therefore in the power speculations we can see those okay cut off frequency and effects of the
band pass filter what about the time and frequency change of the it's the oddball effect the power spectral then sort of fourier
transform underlying these doesn't have doesn't show us the time information we only have frequency and then the power right so there is a method called
wavelet transformation that allows us to decompose a signal into time and then frequency evaluation frequency time frequency decomposition the time frequency
module of mne contains many methods that allows you to perform time frequency analysis on eeg and imaging for example we can
try to see take a look so this is method for the air more lit multitaper for your marlin so different methods as you can see
the inverse free transform more lit welsh method multi-taper pulse spectral density and time frequency array more led different versions okay so this is our
more or less time frequency modulate that we want to use which computes the time frequency representation is a more lit wave wavelength so more wavelets is again a method that allows us to decompose time series in
the time and frequency representation let's see so we'll have to define some parameters like the frequency range from 3 to 30 and perform
pass hour erp target and standard and get an object called time frequency target
now we have data let's take a look shape yes so the shape of the data is now different 63 channels 221 time samples
and this is the frequency range okay we can try to visualize as follows so let me first see if yeah we can
visualize it like plot plot okay just plot let's try to plot
so frequency and time from f p one channel okay how can we define the channel name
yeah the channels include slices and baseline so here we can visualize different channels so now let's again use a combined evoke then subtract
standard and target this is three dimensional numpy array and apply some baseline correction then visualize
right then you can see some clearpath time and frequency this information provides us where in time and then frequency we have significant
difference between two different conditions target european on target therapy so this red represents a difference and in space we can see the channel following channel
and also it hurts four hertz okay just a moment so we can select one channel and visualize so oozy
13 cz so it provides us again time and frequency information our right let me try to do this
yeah so time frequency analysis is an integral part of any eeg or meg research using these tools we decompose eeg into again time frequency representation or
pulse spectral representation and what we are looking for is to find some differences related to experimental conditions right and then underlying mental state while in the case of pci
for this information these kind of features can be constructed for improved classification you should have studied power spectral density or fourier
transforms in your signals and systems course there are different other methods that we can use for time frequency analysis using the
mne time frequency module okay and you can try to find relevant augmentation cross-spectral density for example using more lead so we have seen today how different ways
we can visualize a data erp data using the mne's available methods and we have also seen the time frequency composition please study the toolbox yourself get more hands-on
experiences in the coming sessions we're going to extract those data and then feed it to your classifier i think that's it for today i'll see you out
Loading video analysis...