MatlabFilter communication with Application

Forum for software developers to discuss BCI2000 software development
Post Reply
okbalefthanded
Posts: 6
Joined: 12 Aug 2015, 07:42

MatlabFilter communication with Application

Post by okbalefthanded » 17 Sep 2015, 15:31

Hi,
I'm using the MatlabSignalProcessing module as a SignalProcessing module with the P3Speller Application module, so far I can easily process the incoming signal following the Matlab functions chain, what Is missing for me is the control signal communication with the P3Speller module, I tried with the State variables avaible: StimulusCode, StimulusType, PhaseInSequence, PauseApplication,... but the P3Speller doesn't change the state i.e. there's no change in the TextResult, Current character to recognize, and the intensification doesn't follow the length of the TextToSpell (no pause).
What I'm asking here for is:

- If it's still possible to use the avaible modules to make a full online P300 system without the need to change the code and build BCI2000 again, and how can I do it ?
Thanks
Regards,
Okba

pbrunner
Posts: 344
Joined: 17 Sep 2010, 12:43

Re: MatlabFilter communication with Application

Post by pbrunner » 17 Sep 2015, 18:15

Okba,

the MatlabFilter reads the states and signals and then writes them back to BCI2000, so you should be able to affect the P3Speller application through manipulating he states within the MatlabFilter.

To isolate your problem, can you please try to verify whether the MATALB demo that comes with BCI2000 behaves correctly. Specifically, this executes the "/prog/bci_Process.m" function in which a random value is written into the state MyDemoState. For this please execute the "/batch/MatlabDemo_SignalGenerator.bat" and hit "Set Config" and then "Start". After suspending this run, please load the resulting data file into MATLAB using the load_bcidat function in "/tools/mex". The state.MyDemoState.NumericValue variable should then show a random integer value from 0 to 12. This is at least the behavior that I observe in the current SVN stack. I will send you a link to the current binaries in a private email, so you can verify this on your machine.

If you indeed observe this behavior, you will need to verify that your MATLAB code produces the intended behavior in the P3Speller application. For this you can either use debug messages (e.g., bciout) or attach yourself in Visual Studio to the debug version of the P3Speller process and set breakpoints.

Please report back whether this has resolved your issues.

Regards, Peter

okbalefthanded
Posts: 6
Joined: 12 Aug 2015, 07:42

Re: MatlabFilter communication with Application

Post by okbalefthanded » 20 Sep 2015, 17:17

Thanks for the e-mail, I appreciate it.

here's what I did so far:
- As you mentioned, I run the Matlab Demo batch and checked with the bci_load function the data recorded, the variable State.MyDemoState has a vector of random numbers from 0 to 11, which means it worked fine.

- I tested the P3Speller task with the matlabfilter, In the bci_process() function I made simple changes to the states variables like:
bci_States.SelectedTarget = 4;
bci_States.SelectedRow = 4;
bci_States.SelectedColumn = 7;
I checked the values in the matlab engine window the values did really changed, I also checked the data recorded as above and the values also has been well stored.
Yet I still face the same problem, I change the state variables values but the P3Speller flashes and stop flashing following the parameters forever (with no pause or stop).
I set the TextToSpell to the following sequence: "4 5 6 7"
After starting the run, the TextToSpell remain the same "4 5 6 7" (4) without any change even if I modify the bci_States.
I face the same issue with the binaries you sent me.
Thanks,
Regards,
Okba.

pbrunner
Posts: 344
Joined: 17 Sep 2010, 12:43

Re: MatlabFilter communication with Application

Post by pbrunner » 21 Sep 2015, 14:44

Okba,

as the next step I would recommend that you debug the P3Speller application once, while running the BCI2000 stock P3SignalProcessing and once with your MATLAB filter replacement. For this, please compile the current BCI2000 SVN stack in debug mode. If you have a professional version of VS2012 you can attach yourself to the P3Speller process and have the application stop at breakpoints that you set in the code. If you only have access to the express version of VS2012 you need to comment out the line in the batch file that starts the P3Speller.exe. Instead you set P3Speller project as your startup project, set the command-line parameters to the same as in the batch file and start the P3Speller.exe directly from VS2012.

During the debugging, first investigate what state variables are probed in the P3Speller to conclude the stimulation sequence. You can also add debug messages at critical sections [1] to help understand what you are missing in your P3SignalProcessing implementation.

Regards, Peter

[1] http://www.bci2000.org/wiki/index.php/P ... bug_Output

pahwam
Posts: 3
Joined: 08 Apr 2015, 17:13

Re: MatlabFilter communication with Application

Post by pahwam » 02 Dec 2015, 21:22

Okba and Peter,

If I understand correctly, the MatlabFilter is designed so that the 'States' can not be changed inside of Matlab, thus ensuring backwards compatibilityof the State vector. In the MatlabFilter.cpp file there is a member function called MatlabWSToStates() that has some comments that allude to this design. My intuition suggests that this function will need to be altered in order to allow the states to be modified inside of Matlab and then executed in BCI2000.

Hope this helps, and let me know if you find a solution as I am working to achieve similar functionality!

Best,

Mrinal

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest