Ganglion Data Stream Conversion Methodology

yoosungyoosung South Korea
edited May 2023 in Ganglion

Hi,
I would like to inquire about the floating value's decimal converstion methodology for Ganglion's Channel 1.
I'm receiving raw data values directly via bluetooth.

Currently, the sample data looks as follows, in which the first value of 124 corresponds to the Packet ID.
[124, 254, 63, 33, 135, 32, 11, 106, 1, 101, 96, 21, 112, 186, 152, 0, 25, 231, 255, 197]

I understand that the next two bytes and the first three bits of the next byte represent the data value for Channel 1.

This is 1111111000111111001 in terms of bits.

How can this be converted into -503.97956827888265?
More precisely, how can I get the 14 decimal values from the bit representation of 1111111000111111001?

Help would be much appreciated.

Thank you.

Best,
Yoosung

Comments

  • wjcroftwjcroft Mount Shasta, CA
    edited May 2023

    Actually the BEST way to decode the stream is to use the Brainflow library. Decoding it by yourself may lead to errors and is not recommended. Additionally, the Brainflow method allows you to talk to the Ganglion in either of two ways: directly with the Bluetooth operating system API on the laptop; or instead via the BLED112 dongle, which emulates a serial port.

    https://brainflow.readthedocs.io/en/stable/SupportedBoards.html#ganglion

  • yoosungyoosung South Korea

    May I inquire what the input data should look like for the convert19bitAsInt32 function as shown by the document?(https://docs.openbci.com/Ganglion/GanglionDataFormat/)

    The function should give me -3 if the input is 0b1111111111111111101.
    However, I have tried the following inputs but can't seem to replicate the output of -3.

    // var result = convert19bitAsInt32([0b111, 11111111,11111101]);
    --> 1111101

    // var result = convert19bitAsInt32([0b1111111111111111101]);
    --> 0

    // var result = convert19bitAsInt32('0b1111111111111111101');
    --> 1

    // var result = convert19bitAsInt32('1111111111111111101');
    --> 1

    // var result = convert19bitAsInt32([11111111, 11111111,101]);
    --> 101

    // var result = convert19bitAsInt32('0b1111100000000000110')
    --> not this style

    // var result = convert19bitAsInt32([11111000, 00000000,110]);
    --> 110

    // var result = convert19bitAsInt32([0b11111000, 0b00000000,0b110]);
    --> 6


    function convert19bitAsInt32 (threeByteBuffer) {
    let prefix = 0;

    if (threeByteBuffer[2] & 0x01 > 0) {
    // console.log('\t\tNegative number')
    prefix = 0b1111111111111;
    }

    return (prefix <! 19) | (threeByteBuffer[0] <! 16) | (threeByteBuffer[1] <! 8) | threeByteBuffer[2];

    }

  • yoosungyoosung South Korea

    Also, may I ask what the <! operator does in the above function?
    I've tried searching online, but have not been able to find an answer.

  • yoosungyoosung South Korea

    I've solved the issue by changing all the <! to <<
    Thanks.


    function convert19bitAsInt32 (threeByteBuffer) {
    let prefix = 0;

    if (threeByteBuffer[2] & 0x01 > 0) {
    // console.log('\t\tNegative number')
    prefix = 0b1111111111111;
    }

    return (prefix <<19) | (threeByteBuffer[0] << 16) | (threeByteBuffer[1] << 8) | threeByteBuffer[2];

    }

  • yoosungyoosung South Korea

    One last question.
    I've finally succeeded in decoding the channel values.

    In order to match my channel values with the ones given by the txt file, is multiplying by the below scale factor the only step needed?

    Scale Factor (Volts/count) = 1.2 Volts * 8388607.0 * 1.5 * 51.0;

  • yoosungyoosung South Korea

    Hi,
    I understand I've been asking a lot lately, but may I be able to get an update on my last question?

    I'm getting bizarre values after multiplying by the scalee factor (https://docs.openbci.com/Ganglion/GanglionDataFormat/).

    If the input sequence is [172, 125, 24, 32, 50, 72, 219, 84, 156, 24, 90, 190, 37, 242, 169, 253, 200, 55, 193, 124],

    For channel 1 on the Ganglion, I get

    -> 19bit : 0111110100011000001
    -> convert to int : 256193
    -> multiplied by scale factor :197287599.6912618

    Some insight would be really helpful.
    Best,
    Yoosung

  • @wjcroft said:
    Actually the BEST way to decode the stream is to use the Brainflow library. Decoding it by yourself may lead to errors and is not recommended. Additionally, the Brainflow method allows you to talk to the Ganglion in either of two ways: directly with the Bluetooth operating system API on the laptop; or instead via the BLED112 dongle, which emulates a serial port.

    https://brainflow.readthedocs.io/en/stable/SupportedBoards.html#ganglion

    I use the brainflow library but I have no idea what the data returned by it is - get_board_data?

  • wjcroftwjcroft Mount Shasta, CA
    edited May 2023

    Yoosung is trying to decode the Bluetooth data stream bytes.

    Code section in Brainflow that unpacks compressed / uncompressed data.

    https://github.com/brainflow-dev/brainflow/blob/master/src/board_controller/openbci/ganglion_native.cpp#L469

    Scaling,

    https://github.com/brainflow-dev/brainflow/blob/master/src/board_controller/openbci/ganglion_native.cpp#L485

Sign In or Register to comment.