MAMEM / eeg-processing-toolbox

Matlab code for proccesing EEG signals.
http://www.mamem.eu/
Apache License 2.0
74 stars 36 forks source link

Error in ssveptoolkit.preprocessing.Amuse/amuse #49

Closed iaaly closed 8 years ago

iaaly commented 8 years ago

Hi, Please I need your help I'm facing a weird error.

The example code works perfectly with the included signals.

Now I'm trying to use my own signals, I started with two signals acquired from two different subjects, I've added a method in Session.m to generate the trials from my signals. The sampling rate I use is 512. The sessions loads successfully, but I have a problem in executing the example code exampleOptimal. Specifically the error appears in the Amuse script as the following:

Error using  - 
Matrix dimensions must agree.

Error in ssveptoolkit.preprocessing.Amuse/amuse (line
86)
            Xb=Xb-kron(mean(Xb')',ones(1,N));

Error in ssveptoolkit.preprocessing.Amuse/process
(line 24)
                [W,~,yest] = AM.amuse(signal);

Error in ssveptoolkit.experiment.Experimenter/run
(line 62)
                    trials =
                    E.preprocessing{i}.process(trials);

Error in exampleOptimal (line 46)
experiment.run();

I'm guessing that this error is due to the change in the sampling rate? Any idea?

Thank you

liarosge commented 8 years ago

Can you post the method that you included in Session.m?

Amuse doesn't have anything to do with the sampling rate. Maybe the signal variable is not of the correct size? It should be m x N, where m= number of channels and N=number of samples

iaaly commented 8 years ago

First I added a constant array in the properties of Session.m containing the labels, Each trial corresponds to a frequency 20Hz, 15Hz or 12Hz, or 0 indicating no stimulation.

FREQ = [0,20,15,12];

Here's the method I used to fill the trials in Session.m:

        function trials = getTrials(S, signal, time, stims, subjectid, session)
            trials = {};
            nbTrials = (length(stims) - 2)/3;
            for i=1:nbTrials
                sig_start = find(stims(3*i,1)==time);
                sig_end = find(stims(3*i+1,1)==time);
                signal_part =signal(sig_start:sig_end-1,:);
                stim_freq = S.FREQ(stims(2+3*(i-1),2) - 33023); 
                trials{i} = ssveptoolkit.util.Trial(signal_part, stim_freq, S.SAMPLING_RATE, subjectid,session);
                S.subjectids = [S.subjectids subjectid];
                S.sessionids = [S.sessionids session];
            end

        end

I don't think the problem in it because I verified the trials in the object returned from the .loadAll(1) event. Please note that the number of electrodes I'm using is 32 instead of 256, so the signal matrix has 32 columns only, could this be the reason?

Should I edit the parameters (first and last) of the 'amu' object? I also left the parameters of 'extr' the same, only change the sampleRange to [1,3584] since in my experiment the trial duration is 7 seconds (7*512), but the problem appears the before the sampling...

iaaly commented 8 years ago

You are right I had a problem in the matrix dimension, I added the followinf before assigning teh trials{i}:

signal_part=signal_part'

I also changed the amu.first to 1 and amu.last to 32, now it works like a charm, Thank you sir!

liarosge commented 8 years ago

try changing this line trials{i} = ssveptoolkit.util.Trial(signal_part, stim_freq, S.SAMPLING_RATE, subjectid,session);

to trials{i} = ssveptoolkit.util.Trial(signal_part', stim_freq, 512, subjectid,session);

like i said the "signal_part" should be 32x3584, it seems judging by your code that it is 3584x32.

Also, yes you will probably have to change the first and last properties (first=1, last =32). I am not really sure how Amuse will work with 32 channels. You can also remove the amuse part from the pipeline by changing line experiment.preprocessing = {amu,ss,refer,df}; to experiment.preprocessing = {ss,refer,df};