Problem with parsing compressed EEG packets


#1

Hi!

I’ve implemented the algorithm for parsing compressed data. The problem is that several bytes from a payload stay unused every time. And I don’t know where the bugs may be.

Could anyone post here the Muse data (connected directly to Muse without MuseIO) and the data after decoding?


#2

Hi runner,

The best reference I’ve seen until now (step by step guide) on how to process the uncompressed packet (C0), is found in the following post by Farough (the Muse Developer Evangelist).

http://forum.choosemuse.com/forum/developer-forum/3290-bluetooth-connection-to-linux/page2

There shoul be no bytes unusead, at most some few bits if the total number of bits is not an exact multiple of 8.

HTH,

Eduardo


#3

Hi Eduardo,

Thanks for the reply. But I’ve already seen it, and still I have no idea what’s wrong. Besides there are mistakes there: median 5 should be 5 instead of 4 and in the payload the third element is c5 instead of b5 - if I have a right understanding. That’s why I want a real data as an example to test my code.

Thanks again,
runner


#4

Hi Runner,

The game in the example Eduardo linked is real data. Zhuang copied in his real data stream for help. If you would like to provide your real data with your interpretation of the decoding, feel free to do so and I will try to locate the issue with you.

I’m not sure what you mean by Median 5 should be 5 instead of 4. There are only 4 medians and in the example I only decoded the first median for the purposes of the walk through. The third element provided by Zhaung is c5, not b5. Perhaps you can review the example once more and check for misunderstanding.

The most important thing is you understand how to break the 5 bytes into medians. You interpret the length properly and you properly accommodate the length of the remainders according to truncated binary of the Medians. Those would be the most likely cause of the length mismatch.

I hope that helps, post your real data if you want more in depth assistance. It can be none brainwave data if you’re concerned. Just trying to fix the protocol for you.


#5

Hi Farough,

Sorry, I’ve made a mistake: Median 4 is 5 because:

05 | 0000 0101
08 | 0000 1000
78 | 0111 1000
40 | [B]01[/B]00 0000
81 | [B]1000 0001[/B]

So

Quantization Median
1…0000…000101
2…1000…000010
3…0000…000111
4…1000…000101

And here are my input file – muse_input.bin (it also contains version string and status output at the beginning of the file) and output file – muse_output.txt.

Thanks for your help,
runner


#6

I tried an example from here:

ff ff aa 55 e0 5d c2 48 5b 80 c0 5 8 78 40 81 1 50 e1 f0 c5 c7 ed 7b 7 fb 63 4e 3b 4d 3c f3 ac 6c 4c 4d 4c 3 71 2e 61 91 11 7b 50 f5 72 67 9e dc 30 4a 85 c1 58 c9 23 68 c8 6d c0 c c 58

And I got:

Uncompressed EEG
[374, 36, 534, 896]
Compressed EEG
Medians: [5, 2, 7, 5]
Quantization: [1, 16, 1, 16]
Result:
[359, 164, 542, 896]
[334, 260, 526, 896]
[344, 180, 526, 896]
[340, 116, 526, 880]
[341, 196, 526, 864]
[364, 196, 526, 864]
[368, 228, 525, 848]
[365, 196, 525, 832]
[365, 228, 520, 816]
[403, 180, 520, 784]
[408, 212, 520, 768]
[401, 180, 520, 720]
[416, 180, 517, 752]
[429, 180, 515, 752]
[430, 228, 515, 784]
[428, 196, 509, 752]

It reads only 38 bytes and 2 bits from 42 bytes in payload.

Following are the resulting differences. The first three numbers are: quotient, remainder and sign.

3 0 -1 -> -15 || 5 0 -1 -> -25 || 2 0 1 -> 10 || 0 4 -1 -> -4 || 0 1 1 -> 1 || 4 3 1 -> 23 || 0 4 1 -> 4 || 0 3 -1 -> -3 || 0 0 1 -> 0 || 7 3 1 -> 38 || 1 0 1 -> 5 || 1 2 -1 -> -7 || 3 0 1 -> 15 || 2 3 1 -> 13 || 0 1 1 -> 1 || 0 2 -1 -> -2 || 4 0 1 -> 128 || 3 0 1 -> 96 || 2 1 -1 -> -80 || 2 0 -1 -> -64 || 2 1 1 -> 80 || 0 0 -1 -> 0 || 1 0 1 -> 32 || 1 0 -1 -> -32 || 1 0 1 -> 32 || 1 1 -1 -> -48 || 1 0 1 -> 32 || 1 0 -1 -> -32 || 0 0 -1 -> 0 || 0 0 1 -> 0 || 1 1 1 -> 48 || 1 0 -1 -> -32 || 1 1 1 -> 8 || 2 2 -1 -> -16 || 0 0 1 -> 0 || 0 0 -1 -> 0 || 0 0 1 -> 0 || 0 0 -1 -> 0 || 0 1 -1 -> -1 || 0 0 -1 -> 0 || 0 5 -1 -> -5 || 0 0 1 -> 0 || 0 0 -1 -> 0 || 0 0 1 -> 0 || 0 3 -1 -> -3 || 0 2 -1 -> -2 || 0 0 -1 -> 0 || 0 6 -1 -> -6 || 0 0 1 -> 0 || 0 0 -1 -> 0 || 0 0 1 -> 0 || 0 1 -1 -> -16 || 0 1 -1 -> -16 || 0 0 -1 -> 0 || 0 1 -1 -> -16 || 0 1 -1 -> -16 || 0 1 -1 -> -16 || 0 2 -1 -> -32 || 0 1 -1 -> -16 || 0 3 -1 -> -48 || 0 2 1 -> 32 || 0 0 -1 -> 0 || 0 2 1 -> 32 || 0 2 -1 -> -32

I hope It will be easier to find mistakes here.

Thanks,
runner


#7

Hi Runner,

You’ve got a mistake above in interpreting our conversion between 5 bytes and 4 10 bit numbers.

As stated here:

[SIZE=15px]Byte 1: [/SIZE][B][SIZE=15px]XXXX XXXX[/SIZE][/B][SIZE=15px] (LSB Median 1)[/SIZE]
[SIZE=15px]Byte 2: XXXX XX[/SIZE][B][SIZE=15px]XX [/SIZE][/B][SIZE=15px](Last 2 bits, MSB Median 1. First 6 bits, LSB Median 2)[/SIZE]
[SIZE=15px]Byte 3: [/SIZE][B][SIZE=15px]XXXX[/SIZE][/B][SIZE=15px] XXXX (Last 4 bits, MSB Median 2. First 4 bits, LSB Median 3)[/SIZE]
[SIZE=15px]Byte 4: XX[/SIZE][B][SIZE=15px]XX XXXX [/SIZE][/B][SIZE=15px](Last 6 bits, MSB Median 3. First 2 bits, LSB Median 4)[/SIZE]
[SIZE=15px]Byte 5: XXXX XXXX (MSB Median 4)[/SIZE]

If we take 5d : c2 : 48 : 5b : 80 our first EEG packet. This break into the following:

[B]In hex to bits[/B]:
5d : 0101 1101
c2 : 1100 0010
48 : 0100 1000
5b : 0101 1011
80 : 1000 0000

[B]Reconstructing 10 bit numbers[/B]:
EEG1 = 10 0101 1101 in decimal = 605
EEG2 = 10 0011 0000 in decimal = 560
EEG3 = 01 1011 0100 in decimal = 436
EEG4 = 10 0000 0001 in decimal = 513

[B]Similarly[/B] [B]the[/B] [B]Medians[/B]:
05 : 00000101
08 : 00001000
78 : 01111000
40 : 01000000
81 : 10000001

[B]Reconstruction[/B]:
Median1: 0000000101 = 5 with 1 quantization
Median2: 1000000010 = 2 with 16 quantization
Median3: 0000000111 = 7 with 1 quantization
Median4: 1000000101 = 5 with 16 quantization

1 50 = 256*1 + 80 = 336 bits in the packet. This is 42 bytes.

e1 f0 c5 c7 ed 7b 7 fb 63 4e 3b 4d 3c f3 ac 6c 4c 4d 4c 3 71 2e 61
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
91 11 7b 50 f5 72 67 9e dc 30 4a 85 c1 58 c9 23 68 c8 6d c0 c c 58
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

Therefore following our packet we have the start of the next compressed packet.

Lets just look at the start of the payload.

E1 = 1110 0001, F0 = 1111 0000, C5 = 1011 0101, C7 = 1011 1110, ED = 1110 1101.

Our first Median is 5.
With a median of 5, we expect to see 0 = 00, 1 = 01, 2 = 10, 3 = 110 and 4 = 111.
2 we expect 0 = 0, 1 = 1.
7 we expect 0 = 00, 1 = 100, 2 = 011, 3 = 100, 4 = 101, 5 = 110, 6 = 111.
5 we expect 0 = 00, 1 = 01, 2 = 10, 3 = 110 and 4 = 111.

Here is the payload in Binary.

e1 : 11100001
f0 : 11110000
c5 : 11000101
c7 : 11000111
ed : 11101101
7b : 01111011
07 : 00000111
fb : 11111011
63 : 01100011
4e : 01001110
3b : 00111011
4d : 01001101
3c : 00111100
f3 : 11110011
ac : 10101100
6c : 01101100
4c : 01001100
4d : 01001101
4c : 01001100
03 : 00000011
71 : 01110001
2e : 00101110
61 : 01100001
91 : 10010001
11 : 00010001
7b : 01111011
50 : 01010000
f5 : 11110101
72 : 01110010
67 : 01100111
9e : 10011110
dc : 11011100
30 : 00110000
4a : 01001010
85 : 10000101
c1 : 11000001
58 : 01011000
c9 : 11001001
23 : 00100011
68 : 01101000
c8 : 11001000
6d : 01101101

[B]This is the start of the next Compressed Packet[/B]:
c0 : 11000000
0c : 00001100
0c : 00001100
58 : 01011000

[B]Note[/B]: My previous post here had some mistakes in parsing the payload because I converted to binary incorrectly.
((35) + 0) * -1 = -15, ((55) + 0) * -1 = -25, ((25) + 0) * 1 = 10, ((05) + 4) * -1 = -4

I could go one but there are significant changes here. If you still believe there is an issue I can parse the entire payload.

Note that the remainder is of variable length. In this case is is only 2 bits for 0 or 1 remainder and 3 bits for 2, 3 and 4. This is important because if you misinterpret the starting position of a quotient it will change the amount of bits consumed significantly.

Hope that helps you understand.


#8

Hi Farough and Runner,

Farough, congratulations and many thanks for your patience in such detailed explanations !

Bellow is a picture I made for my self understanding just after the MCP release. Maybe it can be usefull for others (like me) not used to working with bits and bytes.
Please, correct me if I made any mistake (but it’s working fine with my readings)

For the compressed packet (C0) the process is the same, just remebering that each of the four 10 bits final values, each correspond to each channel (TP9, FP1, FP2, TP10),
and that the four upper bits of ech value correspond to the quantization and the six lower bits to the median of each channel.

The hardest part comes next, once we extract the number of BITS of the packet (bytes to read), and bit by bit, extracting the quotients, remainders and sign of each DIFF that must be added (subtracted) from the previous final calculated value).


#9

Hi Farough and Eduardo,

Thanks a lot for your help. You provided really good examples.

Farough, you are right – there was a mistake in the conversion. The thing that still bothers me is that my algorithm doesn’t read all 42 bytes. The differences are the same and the first four differences are coincide with your answers:

3 0 -1 -> -15 || 5 0 -1 -> -25 || 2 0 1 -> 10 || 0 4 -1 -> -4 || …

So I don’t know where the mistake can be. And I think it would be better to parse the entire payload.

Thanks,
runner


#10

Ok,

Here’s the parsing of the entire packet:
[TABLE=“border: 0, cellpadding: 0, cellspacing: 0, width: 868”]
[TR]
[TD][B]Median 5[/B]:[/TD]
[TD] [/TD]
[TD][B]Median 2[/B]:[/TD]
[TD] [/TD]
[TD][B]Median 7[/B]:[/TD]
[TD] [/TD]
[TD][B]Median 5[/B]:[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]1110-r00-s0[/TD]
TD-1=-15[/TD]
[TD]11110-r0-s1[/TD]
TD1=8[/TD]
[TD]10-r010-s1[/TD]
TD1=8[/TD]
[TD]110-r00-s0[/TD]
TD
-1=-10[/TD]
[/TR]
[TR]
[TD]111110-r00-s0[/TD]
TD
-1=-25[/TD]
[TD]1110-r0-s1[/TD]
TD1=6[/TD]
[TD]110-r011-s0[/TD]
TD
-1=-16[/TD]
[TD]0-r10-s0[/TD]
TD
-1=-7[/TD]
[/TR]
[TR]
[TD]110-r00-s1[/TD]
TD1=10[/TD]
[TD]110-r1-s0[/TD]
TD
-1=-5[/TD]
[TD]0-r00-s1[/TD]
TD1=0[/TD]
[TD]10-r10-s1[/TD]
TD1=7[/TD]
[/TR]
[TR]
[TD]0-r111-s0[/TD]
TD
-1=-4[/TD]
[TD]110-r0-s0[/TD]
TD
-1=-4[/TD]
[TD]10-r010-s0[/TD]
TD-1=-8[/TD]
[TD]0-r00-s0[/TD]
TD
-1=0[/TD]
[/TR]
[TR]
[TD]0-r01-s1[/TD]
TD1=1[/TD]
[TD]110-r1-s1[/TD]
TD1=5[/TD]
[TD]0-r100-s0[/TD]
TD
-1=-3[/TD]
[TD]10-r111-s0[/TD]
TD
-1=-9[/TD]
[/TR]
[TR]
[TD]11110-r110-s1[/TD]
TD1=23[/TD]
[TD]0-r0-s0[/TD]
TD
-1=0[/TD]
[TD]10-r00-s1[/TD]
TD1=7[/TD]
[TD]0-r00-s0[/TD]
TD
-1=0[/TD]
[/TR]
[TR]
[TD]0-r111-s0[/TD]
TD*1=4[/TD]
[TD]10-r0-s1[/TD]
TD*1=2[/TD]
[TD]0-r111-s1[/TD]
TD1=6[/TD]
[TD]10-r10-s1[/TD]
TD1=7[/TD]
[/TR]
[TR]
[TD]10-r110-s0[/TD]
TD
-1=8[/TD]
[TD]10-r0-s0[/TD]
TD
-1=-2[/TD]
[TD]0-r110-s1[/TD]
TD*1=5[/TD]
[TD]10-r00-s1[/TD]
TD1=5[/TD]
[/TR]
[TR]
[TD]0-r00-s1[/TD]
TD1=0[/TD]
[TD]10-r0-s1[/TD]
TD1=2[/TD]
[TD]0-r100-s0[/TD]
TD
-1=-3[/TD]
[TD]10-r01-s0[/TD]
TD
-1=-6[/TD]
[/TR]
[TR]
[TD]11111110-r110-s1[/TD]
TD1=38[/TD]
[TD]10-r1-s0[/TD]
TD
-1=-3[/TD]
[TD]0-r111-s1[/TD]
TD1=6[/TD]
[TD]0r-10-s0[/TD]
TD
-1=-2[/TD]
[/TR]
[TR]
[TD]10-r00-s1[/TD]
TD1=5[/TD]
[TD]10-r0-s1[/TD]
TD1=2[/TD]
[TD]0-r101s0[/TD]
TD
-1=-4[/TD]
[TD]10-r00-s1[/TD]
TD1=5[/TD]
[/TR]
[TR]
[TD]10-r10-s0[/TD]
TD
-1=-7[/TD]
[TD]10-r0-s0[/TD]
TD
-1=-2[/TD]
[TD]1110-r010-s0[/TD]
TD
-1=-22[/TD]
[TD]10-r110-s1[/TD]
TD*1=8[/TD]
[/TR]
[TR]
[TD]1110-r00-s1[/TD]
TD1=15[/TD]
[TD]0-r0-s0[/TD]
TD
-1=0[/TD]
[TD]110-r011-s1[/TD]
TD*1=16[/TD]
[TD]0-r00-s1[/TD]
TD*1=0[/TD]
[/TR]
[TR]
[TD]110-r110-s1[/TD]
TD*1=13[/TD]
[TD]0-r0-s1[/TD]
TD*1=0[/TD]
[TD]10-r011-s1[/TD]
TD1=9[/TD]
[TD]10-r01-s0[/TD]
TD
-1=-6[/TD]
[/TR]
[TR]
[TD]0-r01-s1[/TD]
TD*1=1[/TD]
[TD]10-r1-s1[/TD]
TD1=3[/TD]
[TD]10-r110-s1[/TD]
TD1=12[/TD]
[TD]0-r00-s1[/TD]
TD1=0[/TD]
[/TR]
[TR]
[TD]0-r10-s0[/TD]
TD
-1=-2[/TD]
[TD]10-r0-s0[/TD]
TD
-1=-3[/TD]
[TD]110-r00-s0[/TD]
TD
-1=-14[/TD]
[TD]10-r110-s1[/TD]
TD*1=8[/TD]
[/TR]
[/TABLE]

[B]Applying to the Original EEG[/B]:
[TABLE=“border: 0, cellpadding: 0, cellspacing: 0, width: 677”]
[TR]
[TD][B]Quantization[/B][/TD]
[TD][B]Channel 1[/B][/TD]
[TD][B]Quantization[/B][/TD]
[TD][B]Channel 2[/B][/TD]
[TD][B]Quantization[/B][/TD]
[TD][B]Channel 3[/B][/TD]
[TD][B]Quantization[/B][/TD]
[TD][B]Channel 4[/B][/TD]
[/TR]
[TR]
[TD=“align: right”]1[/TD]
[TD=“align: right”]605[/TD]
[TD=“align: right”]16[/TD]
[TD=“align: right”]560[/TD]
[TD=“align: right”]1[/TD]
[TD=“align: right”]436[/TD]
[TD=“align: right”]16[/TD]
[TD=“align: right”]513[/TD]
[/TR]
[TR]
[TD=“align: right”]-15[/TD]
[TD=“align: right”]620[/TD]
[TD=“align: right”]8[/TD]
[TD=“align: right”]432[/TD]
[TD=“align: right”]8[/TD]
[TD=“align: right”]428[/TD]
[TD=“align: right”]-10[/TD]
[TD=“align: right”]673[/TD]
[/TR]
[TR]
[TD=“align: right”]-25[/TD]
[TD=“align: right”]645[/TD]
[TD=“align: right”]6[/TD]
[TD=“align: right”]336[/TD]
[TD=“align: right”]-16[/TD]
[TD=“align: right”]444[/TD]
[TD=“align: right”]-7[/TD]
[TD=“align: right”]785[/TD]
[/TR]
[TR]
[TD=“align: right”]10[/TD]
[TD=“align: right”]635[/TD]
[TD=“align: right”]-5[/TD]
[TD=“align: right”]416[/TD]
[TD=“align: right”]0[/TD]
[TD=“align: right”]444[/TD]
[TD=“align: right”]7[/TD]
[TD=“align: right”]673[/TD]
[/TR]
[TR]
[TD=“align: right”]-4[/TD]
[TD=“align: right”]639[/TD]
[TD=“align: right”]-4[/TD]
[TD=“align: right”]480[/TD]
[TD=“align: right”]-8[/TD]
[TD=“align: right”]452[/TD]
[TD=“align: right”]0[/TD]
[TD=“align: right”]673[/TD]
[/TR]
[TR]
[TD=“align: right”]1[/TD]
[TD=“align: right”]638[/TD]
[TD=“align: right”]5[/TD]
[TD=“align: right”]400[/TD]
[TD=“align: right”]-3[/TD]
[TD=“align: right”]455[/TD]
[TD=“align: right”]-9[/TD]
[TD=“align: right”]817[/TD]
[/TR]
[TR]
[TD=“align: right”]23[/TD]
[TD=“align: right”]615[/TD]
[TD=“align: right”]0[/TD]
[TD=“align: right”]400[/TD]
[TD=“align: right”]7[/TD]
[TD=“align: right”]448[/TD]
[TD=“align: right”]0[/TD]
[TD=“align: right”]817[/TD]
[/TR]
[TR]
[TD=“align: right”]4[/TD]
[TD=“align: right”]611[/TD]
[TD=“align: right”]2[/TD]
[TD=“align: right”]368[/TD]
[TD=“align: right”]6[/TD]
[TD=“align: right”]442[/TD]
[TD=“align: right”]7[/TD]
[TD=“align: right”]705[/TD]
[/TR]
[TR]
[TD=“align: right”]8[/TD]
[TD=“align: right”]603[/TD]
[TD=“align: right”]-2[/TD]
[TD=“align: right”]400[/TD]
[TD=“align: right”]5[/TD]
[TD=“align: right”]437[/TD]
[TD=“align: right”]5[/TD]
[TD=“align: right”]625[/TD]
[/TR]
[TR]
[TD=“align: right”]0[/TD]
[TD=“align: right”]603[/TD]
[TD=“align: right”]2[/TD]
[TD=“align: right”]368[/TD]
[TD=“align: right”]-3[/TD]
[TD=“align: right”]440[/TD]
[TD=“align: right”]-6[/TD]
[TD=“align: right”]721[/TD]
[/TR]
[TR]
[TD=“align: right”]38[/TD]
[TD=“align: right”]565[/TD]
[TD=“align: right”]-3[/TD]
[TD=“align: right”]416[/TD]
[TD=“align: right”]6[/TD]
[TD=“align: right”]434[/TD]
[TD=“align: right”]-2[/TD]
[TD=“align: right”]753[/TD]
[/TR]
[TR]
[TD=“align: right”]5[/TD]
[TD=“align: right”]560[/TD]
[TD=“align: right”]2[/TD]
[TD=“align: right”]384[/TD]
[TD=“align: right”]-4[/TD]
[TD=“align: right”]438[/TD]
[TD=“align: right”]5[/TD]
[TD=“align: right”]673[/TD]
[/TR]
[TR]
[TD=“align: right”]-7[/TD]
[TD=“align: right”]567[/TD]
[TD=“align: right”]-2[/TD]
[TD=“align: right”]416[/TD]
[TD=“align: right”]-22[/TD]
[TD=“align: right”]460[/TD]
[TD=“align: right”]8[/TD]
[TD=“align: right”]545[/TD]
[/TR]
[TR]
[TD=“align: right”]15[/TD]
[TD=“align: right”]552[/TD]
[TD=“align: right”]0[/TD]
[TD=“align: right”]416[/TD]
[TD=“align: right”]16[/TD]
[TD=“align: right”]444[/TD]
[TD=“align: right”]0[/TD]
[TD=“align: right”]545[/TD]
[/TR]
[TR]
[TD=“align: right”]13[/TD]
[TD=“align: right”]539[/TD]
[TD=“align: right”]0[/TD]
[TD=“align: right”]416[/TD]
[TD=“align: right”]9[/TD]
[TD=“align: right”]435[/TD]
[TD=“align: right”]-6[/TD]
[TD=“align: right”]641[/TD]
[/TR]
[TR]
[TD=“align: right”]1[/TD]
[TD=“align: right”]538[/TD]
[TD=“align: right”]3[/TD]
[TD=“align: right”]368[/TD]
[TD=“align: right”]12[/TD]
[TD=“align: right”]423[/TD]
[TD=“align: right”]0[/TD]
[TD=“align: right”]641[/TD]
[/TR]
[TR]
[TD=“align: right”]-2[/TD]
[TD=“align: right”]540[/TD]
[TD=“align: right”]-3[/TD]
[TD=“align: right”]416[/TD]
[TD=“align: right”]-14[/TD]
[TD=“align: right”]437[/TD]
[TD=“align: right”]8[/TD]
[TD=“align: right”]513[/TD]
[/TR]
[/TABLE]

Please note that if you wish, you can make all signs of 1 into -1 and all signs of 0 to +1. Then instead of subtracting all differences from the previous you may add the differences to the previous sample. Double negative is unnecessary. Above I’ve subtracted all values.

Hope this helps. I used all 42 bytes.


#11

Farough,

Thanks a lot. It reads exactly 40 bytes now.

But a couple of questions are left:

  1. You subtract differences from previous samples. And I thought they should be added as shown here: https://sites.google.com/a/interaxon.ca/muse-developer-site/muse-communication-protocol/compressed-eeg-packets#TOC-Pseudo-code-for-Parsing-Compressed-Data.

  2. Some values are negative (in a real data) however https://sites.google.com/a/interaxon.ca/muse-developer-site/museio/osc-paths/osc-paths---v3-6-0#TOC-muse-eeg says that values should be from 0 to 1023. Do I get something wrong?

Thanks,
runner


#12

It should be reading exactly 42 bytes here.

As I mentioned in my note, if you make change signs to be negative for 1 and positive for 0 you can add the delta’s instead of subtracting them. The documentation notes the redundant double negative.

You can expect to go under 0 or over 1023 for two different reasons.
Firstly, if you have quantization, your data becomes lossy and make go beyond it’s normal bounds. The lossy compression occurs because the data is no longer on a scale of brainwaves and increases the bandwidth substantially.
Secondly, the default settings actually outputs in microvolts with a range of 0.0 - 1682.815 in microvolts. Whereas 0-1023 is just the binary version before converting it into microvolts.

Hope that clarifies things. I could post all the signs inverted, but hopefully you get the idea.


#13

Yeah, thanks a lot, I finally got that. I fixed my mistakes. And this is what I get now:

[SIZE=11px]Uncompressed EEG : [605, 560, 436, 513]
Compressed EEG
Medians: [5, 2, 7, 5]
Quantization: [1, 16, 1, 16]
42 bytes of payload:
e1 f0 c5 c7 ed 7b 07 fb 63 4e 3b 4d 3c f3 ac 6c 4c 4d 4c 03 71 2e 61 91 11 7b 50 f5 72 67 9e dc 30 4a 85 c1 58 c9 23 68 c8 6d [/SIZE]
[TABLE=“cellpadding: 4, cellspacing: 0”]
[TR]
[TD=“width: 25%”][SIZE=11px]3 0 -1 -> -15
5 0 -1 -> -25
2 0 1 -> 10
0 4 -1 -> -4
0 1 1 -> 1
4 3 1 -> 23
0 4 1 -> 4
0 3 -1 -> -3
0 0 1 -> 0
7 3 1 -> 38
1 0 1 -> 5
1 2 -1 -> -7
3 0 1 -> 15
2 3 1 -> 13
0 1 1 -> 1
0 2 -1 -> -2 [/SIZE][/TD]
[TD=“width: 25%”][SIZE=11px]4 0 1 -> 8
3 0 1 -> 6
2 1 -1 -> -5
2 0 -1 -> -4
2 1 1 -> 5
0 0 -1 -> 0
1 0 1 -> 2
1 0 -1 -> -2
1 0 1 -> 2
1 1 -1 -> -3
1 0 1 -> 2
1 0 -1 -> -2
0 0 -1 -> 0
0 0 1 -> 0
1 1 1 -> 3
1 0 -1 -> -2 [/SIZE][/TD]
[TD=“width: 25%”][SIZE=11px]1 1 1 -> 8
2 2 -1 -> -16
0 0 1 -> 0
1 1 -1 -> -8
0 3 -1 -> -3
1 0 1 -> 7
0 6 1 -> 6
0 5 1 -> 5
0 3 -1 -> -3
0 6 1 -> 6
0 4 -1 -> -4
3 1 -1 -> -22
2 2 1 -> 16
1 2 1 -> 9
1 5 1 -> 12
2 0 -1 -> -14 [/SIZE][/TD]
[TD=“width: 25%”][SIZE=11px]2 0 -1 -> -10
0 2 -1 -> -2
1 2 1 -> 7
0 0 -1 -> 0
1 4 -1 -> -9
0 0 -1 -> 0
1 2 1 -> 7
1 0 1 -> 5
1 1 -1 -> -6
0 2 -1 -> -2
1 0 1 -> 5
1 3 1 -> 8
0 0 1 -> 0
1 1 -1 -> -6
0 0 1 -> 0
1 3 1 -> 8 [/SIZE][/TD]
[/TR]
[/TABLE]
[SIZE=11px] Result:
[620, 432, 428, 673]
[645, 336, 444, 705]
[635, 416, 444, 593]
[639, 480, 452, 593]
[638, 400, 455, 737]
[615, 400, 448, 737]
[611, 368, 442, 625]
[614, 400, 437, 545]
[614, 368, 440, 641]
[576, 416, 434, 673]
[571, 384, 438, 593]
[578, 416, 460, 465]
[563, 416, 444, 465]
[550, 416, 435, 561]
[549, 368, 423, 561]
[551, 400, 437, 433] [/SIZE]

[SIZE=12px]Many thanks again,
runner[/SIZE]