Different sampling rate between EEG signal and AUX signal, using LSL from GUI [workaround]
Hello,
I found an issue that sampling rates between EEG signal and AUX signal which contain external trigger signals turn to be different values when transmitting them via the Lab Stream layer.
I tried a real-time EEG analysis to communicate them using Matlab and LSL, however, the amount of the AUX chunk was a tenth of the EEG signal. (GUI setting below). I used an 8ch Cyton board on this test. As the EEG signal's sampling rate should be 250Hz, the AUX rate goes to be just 25Hz.
The slower sampling rate, especially for ’trigger’ signals coming from the AUX channel, does not allow us to align EEG epochs. An on-set time of an epoch now can be located in between two triggers (since EEG is sampled in 250Hz and Triggers is sampled in 10 times sparse time window). This may cause serious ‘jitter’ problem and we cannot guarantee the same onset time of collected epochs.
This issue occurs in both macOS and Windows 10. Could you find a way to utilize the same sampling frequency 250Hz both for EEG (timeseries) and triggers (AUX)?
Comments
Rai, hello.
Richard @retiutut has already mentioned your issue to me. This mismatch in sample rates is apparently due to a bug in the current GUI/Hub implementation. More than likely in the Hub portion. Since the Hub will be phased out shortly and replaced with BrainFlow library access directly from the GUI -- my guess is that the bug will be resolved within a couple weeks at most.
In the meanwhile, you could use one of the other means of generating an LSL stream, without using the GUI. Such as the Python repos, Brainflow examples, etc.
Regards, William
I agree with William that removing the Hub may fix this issue, as we are simplifying data acquisition with Brainflow.
I was able to see similar results using the following Python sketch. Some code is commented out to test a single stream, but I think this is a valid test. If anyone has any improvements to the following code, please share the updated code on this thread. Rai originally noticed this when using Matlab, I think.
If integrating Brainflow does not seem to make EEG && AUX (Analog) Sample Rates appear at ~250Hz from LSL output, I think the following code may be the culprit from
W_Networking.pde
:Which seems silly, because all cases return the same variable...
Richard, what is the easiest way for Rai to generate his own LSL stream? Use one of the Python repos, or something done with BrainFlow examples? Link?
Thank you William and Richard,
I have already tried python version LSL sending system. These are the codes I used. I send the EEG sig and AUX from python side and receive them by Matlab. I used the Cython board and I did not connect any external pin on this test.
python code
Matlab code
The amounts of both chunks were almost same, so I thought seemingly both sampling rates were also same. However, when looking up to the data of the AUX signals, actually these data were sent only every 10 times.
So I expect It means AUX signals are also downsampled (or reduced in some way) even using the python system although superficial sampling rates of both signals are the same.
Rai, thanks.
When using the Python / LSL sending program, you must put the Cyton into either 'digital' or 'analog' (Aux mode), via a serial port SDK command:
https://docs.openbci.com/docs/02Cyton/CytonSDK#board-mode
The default "board mode", is to send the Accelerometer data at reduced rate.
Regards, William
Hi William, thank you.
I tried to change the board mode, but I could not do it because commando line said that command not recognized.
You appear to be sending the 'command' to Python. You need to send the SDK string directly to the Cyton serial port.
I guess we would try to take a Brainflow-Python example and stream out data using Pylsl to Matlab. (though this can be tested with send/receive Python scripts).
Thank you. I set up analog mode correctly I guess, but I could not start LSL stream because command line said this kind of error.
The order in which you send the SDK commands, is important. Did you send the analog mode command BEFORE starting the stream? There are also some timing guidelines for sending SDK commands, mentioned in the docs.
Also, the second screenshot shows that you have not changed the value you scan for end byte / stop byte. End byte with analog mode is 193 or 0xC1.
https://docs.openbci.com/docs/02Cyton/CytonDataFormat#binary-format
@Rai_sato, let us know if the proper end byte resolved your issue, and you are now streaming ok with Aux data.
@wjcroft, I am sorry for the late reply. I could not do it in these 3 days.
Still, I could not solve this problem because it seems I could not change the value properly.
I first changed the board mode using a 'screen' command on command prompt and launched the user.py with LSL stream plugins like below.
So could you let us know how to change the board mode in your environment usually?
type screen commend
put '/2' to change the board setting
Success: analog$$$
then launch the user.py and do the LSL stream
The Python streaming program(s) contain examples of where SDK command(s) are sent to the board, over the serial port. For example when the command is sent to start board, 'b'.
https://github.com/OpenBCI/pyOpenBCI/blob/master/pyOpenBCI/cyton.py
In that file, the lines like:
self.ser.write(b'b')
(sending a single byte, 'b'). You would simply output a string to turn on the analog or digital mode you want. You should NOT change the board mode with a separate unix shell command, since the serial port will be opened / closed every time a separate command runs. Potentially resetting the Cyton dongle. The mode command should be sent from inside the Python, just before the 'b' command is sent.Similarly in the other Python repo, the serial write commands look like:
board.ser_write(bytes(c))
https://github.com/OpenBCI/OpenBCI_Python
The pyOpenBCI is the newer and better organized, maintained repo. OpenBCI_Python is deprecated.
@wjcroft, Thank you for answering. I could correctly get the AUX signals using the python method.
The sampling rate of AUX was also same as EEG signals.
We are looking forward you to fixing the GUI issue.
@Rai_sato Can you please share with us exactly what you used? This is important for others who also want EEG and AUX data without using the GUI.
lsl_exampllsl_example_analogBoardMode.py
cyton.py
the following is the same as the original code
RESOLUTION: FOR NOW, PLEASE USE @rai_sato's EXAMPLE ABOVE
On Windows, I was able to get this to work and tested using Python send code above, and receiving using GUI LSL stream test. This is a working solution!
On Mac, I get errors involving the end byte, even if I change 0xC0 to 0xC1in cyton.py, and then reinstall pyOpenBCI from my local folder:
@retiutut I'm using the scripts (lsl example and cyton) provided by @rai_santo in combination with the files from https://github.com/openbci-archive/pyOpenBCI.
I was not able to fix the jittering this way as seen in the screenshot below. Is there anything else I must do to get it working?
I would really appreciate your support!
thx
Alex
What is the picture above showing exactly? What is making the visualization? Can you share some code so that this can be replicated?