Questions about eeg simulation

Hello

i’m trying to work with eeg simulation, already i could simulate my eeg from some specific scouts with the process menu:

sFiles = bst_process(‘CallProcess’, ‘process_simulate_matrix’, …
sFiles, [], …
‘subjectname’, SubjectNames{1}, …
‘condition’, num2str(i), …
‘samples’, 150, …
‘srate’, 100, …
‘matlab’, ‘Data(1,:slight_smile: = 0.0008sin(4pi*(t-5)).exp(-(4t-10))’);%%

%Process: Simulate recordings from scouts
sFiles = bst_process(‘CallProcess’, ‘process_simulate_recordings’, …
sFiles, [], …
‘scouts’, {eval(‘cortexFull.Atlas(1,8).Name’), {num2str(i)}}, …
‘savesources’, 1);

But i would like to know more detail about how the software use the information of the head model (my lead field), to generate the eeg recording for the specifics electrodes.
I would like to know every detail that permit me understand the basics behind this magic process, where i generate the specific source position (vertex) and some generic signal, and magically appear a eeg scalp record.

Saludos desde Chile :slight_smile:

Hello,

The second process you’re mentioning does the following:

  1. Create a new source file with the values you generated at the sources you want, and 0 everywhere.
  2. Simulate the corresponding recordings by multiplying the source values with the forward model.

The second step is the same the menu “Model evaluation > Simulate recordings” documented here:
http://neuroimage.usc.edu/brainstorm/Tutorials/SourceEstimation#Model_evaluation

For documentation about the forward model:
http://neuroimage.usc.edu/brainstorm/Tutorials/HeadModel

Francois

Dear Francois

Thanks for your quick answer... Finally i could understand how i can create my own data, however i wanted to check if i was fine. So how i had some simulations from scouts in my data, i wanted to compared the simulation performed for brainstorm process and , the simulation using simply multiplication.

So, from your information i understood the next:

EEG[N_sensorxN_time]=HeadModel[N_sensorxN_sources]*TimeSources[N_sourcesxN_time]

i have in my power the next information:

HeadModel[65x45006]
generic.Value[1x150]: This is the signal wave generic that i made with brainstorm process
dipole.Vertice:14978
eeg.F[65x150]: This is the simulation made with brainstorm process

So using :

Gain_constrained=bst_gain_orient(HeadModel.Gain, HeadModel.GridOrient);

i have changed the gain matrix from unconstrained to constrained, after of that have generated the TimeSource matrix, how i had the information from Generic.Value(1x150), i created a matrix with zeros(15002,150), but in the row position of my dipole 14978, i added the Generic.Value for every time (150).

So finally i have:

mysimulation(65x150)=Gain.constrained(65x15002)*MySourceTime(15002x150)

well, i was waiting for to have the same information than the simulation by brainstorm process, they look really similar, however, the amplitude (scale), they have differences and when i plotted them they look like the next picture.

I would like to know the reason why if this is theoretically well done, why i have this differences in amplitude.

Cheers


Maybe your units are incorrect: In Brainstorm, everything should be in international units (Volts for EEG).

The function that runs this simulation in brainstorm is brainstorm3/toolbox/math/bst_simulations.m
You can place a breakpoint at the beginning of the function, call the process, and when it stops you can check the value of the various variables.
This way you should be able to understand why your code and Brainstorm’s don’t do the same thing.

Francois

Hi

Francois i’m trying to call the bst_simulation, i’m using the next code line:

bst_simulation(’/Users/me/Documents/Msc/data12year_DPA/@default_study/headmodel_surf_openmeeg.mat’);

the process start to run however in the line 56 of bst_simulation

[iDS, iResult]=bst_memory“‘LoadResultsFileFull’, ResulstsFile);

give me always the next error:

Line 851: Undefined function or variable “isLink”

Call stack:

>bst_memory.m>LoadResultFIle at 851
>bst_memory.m>LoadResultsFileFull at 1091
>bst_call.m at 26
>macro_methodcall.m at 37
>bst_memory.m at 71
>bst_simulation.m at 56

so after of that iDS is empty so in the next line

if isempty(iDS)
return
end

send me out throw me out of the code.

I would like to know what is the correct nomenclature for:

the input: ResultFile for to use

newDataFile= bst_simulation(ResultsFile,iVertices);

Cheers

You can find help in the header of bst_simulation.m:

  • ResultsFile : Full or relative path to a brainstorm sources file
  • iVertices : Indices of the sources to use to simulate the recordings

Your example shows you’ve been trying to call it on the head model.
You need to pass in argument your simulated source maps (results_…mat file, with ImageGridAmp=[Nsources x Ntime])

Hi Francois Thanks for your answers

Maybe i’m not being clear, what i want is: from my Lead Field and some specific vertex position (scout), generate my EEG. I have nothing more than my head model (no result_ … .mat matrix), so i’m trying to create my own EEG. I have been trying to use the Process1 menu for generate EEG simulation: simulate generic signal/simulate signal from scouts… this is from Lead_field + scouts i get EEG. However the function (Which you recommended me for to see) ‘bst_simulation.m’ permit to generate EEG from the result_…mat matrix this is the source_result i.e the inverse problem resolution, but i don’t have this information… So, i would like to know where is the code for the ‘process simulate generic signal/simulate signal from scouts’ i want to see if i can to do something similar to that…

Cheers

Hello,

Select a process in the pipeline editor, then leave your mouse for a second over the blue rectangle that shows its name, and it will tell you where it is.
http://neuroimage.usc.edu/brainstorm/Tutorials/PipelineEditor#Plugin_structure

Simulate generic signal: process_simulate_matrix.m
Simulate recordings from scours: process_simulate_recordings.m (see line 173 for Gain * ImageGridAmp)

The same kind of code is present in bst_simulation.m: see lines 184-186

Francois

FYI: To address all the recent questions we had related with simulations, I added some code in Brainstorm and wrote a new tutorial:
https://neuroimage.usc.edu/brainstorm/Tutorials/Simulations

Just committed a new process "Simulate recordings from dipoles":
https://neuroimage.usc.edu/brainstorm/Tutorials/Simulations#Single_dipoles


image