I need to read the data as UBYTE (8-bit Unsigned Byte) in MATLAB and then used bit shift operators to get two 12-bit streams with 3600000 samples. I have to do that by a command that the first two 12 bit values are contained in the first 3 UBYTEs, 8 bits from the first byte with the first 4 bits from the second byte, then the first 4 bits from byte 2 with all 8 bits from byte 3. Then the process repeats with the next 3 bytes (byte 4-6 etc.) and so on.
First 12 bit value: byte 1 |+ (( byte 2 & 0xf0) << 4)
Second 12 bit value: (( byte 2 & 0xf) << 4) |+ ((byte 3 & 0xf0) >> 4) |+ ((byte 3 & 0xf) << 8)
How can I apply this command in MATLAB?
If I understand correctly then something like this might work:
I might have made a mistake with the masks, but the
bitshift
andbitand
commands are probably what you are looking for.The output is two arrays of unit16. If you need the output to be a 12-bit type I'm not sure how best to do that in matlab.