lsl_archived icon indicating copy to clipboard operation
lsl_archived copied to clipboard

Cognionics Matlab - Parsing Method Question

Open markos14 opened this issue 8 years ago • 0 comments

I'm trying to get a better understanding of the Cognionics App branch of LSL. I have the Portable Data Acquisition System from Cognionics. The specs, packet formats, etc. are the same across the the product range. (Packet Start - 0xFF, Packet Counter - 0x0 to 0x7F, Chan.1 - MSB, Chan.1 - LSB2, Chan.1 - LSB1, Chan.2 - MSB, etc.)

I'm writing a Matlab script to test the LSL parsing method, but can't manage to get similar data values. Essentially what I'm doing in Matlab is:

         rawData = fread(comPort, 504, 'uint8');
         startPackets = find(rawData == 255);
         bytes = rawData( [starts+2  starts+3  start+4] );
         ADC_Value = bytes(:,1)*(2^24) + bytes(:,2)*(2^17) + bytes(:,3)*(2^10);
         ADC_Value_uVolts = ADC_Value*(1000000/(2^32));

This is my interpretation of the line from "mainwindow.cpp" in the Cognionics App:

sample[c] = (double)((msb<<24) | (lsb2<<17) | (lsb1<<10)) * value_scale;

However, the supposed microvolt values I get out are in the range of 96000 to 98000 uV which is wrong. Can someone explain to me: The theory behind MSB<<24, LSB2<<17, LSB1<<10. I would have thought reconstructing the 24 bit ADC value would have been MSB<<16, LSB2<<8, LSB1? I know it's in order to reconstruct a 2's compliment, signed int32 number, but it still doesn't make sense to me. Should I be doing some sign extension first or something?

Any help/insight would be very much appreciated.

Thanks,

Mark

markos14 avatar Dec 09 '16 12:12 markos14