thecodingdad / eeg2code

5 stars 2 forks source link

EEG2Code: implementation/pre-preprocessing questions about delays and shifts #1

Open juliencarponcy opened 7 months ago

juliencarponcy commented 7 months ago

Dear Sebastian,

I tried to reach you by email but saw your former academic email is not available, and I can't get my hand on a newer one, so i'm posting here just in case:

I was interested in trying your EEG2code algorithm and I found your repository on GitHub, with the Matlab and python versions of the code. However, it appears that a substantial number of parameters are extracted from your .mat files which are not available, and this is making difficult for me to make sense of how you are windowing and applying delays in the pre-processing stages, before training the model.

I especially struggle to fully understand what is done in the following lines : https://github.com/thecodingdad/eeg2code/blob/d3a17357cfa49f02933b3f0c58e02d25b488d338/keras/EEG2CodeKeras2.py#L77-L91

I pre-processed our own c-VEPdata (EEG: 8 chanels @ 250Hz), to be more “compatible” with your framework, meaning that I have downsampled to 240Hz so that 4 EEG samples can match one bit of the sequences (@60fps), I also resampled the sequences to produce a full code at 240Hz that match the length of resampled EEG data. I was thinking of using windows of 60 samples to match your 250ms of signal.

However, when it comes to the lines I cited above, I struggle to fully grasp what are exactly realtarget, targetdelays, and targetshift, and what are the units (samples I would guess?).

I have browsed the related papers and the github repository but I don’t find much about this pre-processing stages.

Could you help me understand what is the final structure of the data you’re throwing to the model, especially regarding these delays? More specifically, If I have a long-form EEG array and a Boolean code of the same length, and if I cut the signals in 250ms window, what sample of the code should be your independent variable? The last one? A specific delay should be introduced between last sample and the predicted bit?

Thank you very much in advance for your help,

Best,

Julien

thecodingdad commented 7 months ago

Hi Julien,

first: I'm not working in the topic anymore since my last publication (I've left the university). I will try to answer your questions as detailed as I remember ;)

The part you're interested in, is the correction of the monitor raster latency. I've written a paper on that topic (https://doi.org/10.1016/j.jneumeth.2017.11.018) but I could also recommend to have a look at my phd thesis (http://dx.doi.org/10.15496/publikation-37739).

Short: the monitor raster latency occurs because a monitor presents a single frame line by line (from top to bottom) which means the last row of pixels is shown 1/Refreshrate seconds delayed compared tontge first line. For a 60Hz refreshrate this is a delay of 1/60s=16.67ms. Since we use way higher samplingrate for EEG recordings (I used 600Hz) we can (without interpolation) correct the EEG data in steps of 1/samplingrate seconds. The variable "targetdelays" contains, for each target, the number of samples to shift the EEG data in order to correct for the monitor raster latency. The delay of a target can be determined by its vertical position on the monitor. If all your targets are on the same row, you don't have to correct for it.

I would also recommend to have a look at this example: https://doi.org/10.6084/m9.figshare.7701065.v1 The code contains a full example (incl. data) for how to train a model and how to predict the binary sequence. Just the correction for the raster latency and the target prediction is missing, whereby the latter is just a simple comparison (pearson correlation coefficient) of the model prediction to alle possible target sequences.

Hope that helps!

Best, Sebastian