Hey, I have the same problem right now and I'm interested in how you solved it in the end.
The data I get is three bytes each (24 bit two's complement). The ADC has 8 channels, so after every fread I get 24 bytes (as a row vector). It is stored in a Nx24 array, where N is the number of samples. So the data for channel 1 is stored in adc(:,1:3) (1 is MSB; 3 is LSB), channel 2 is stored adc(:,4:6) and so on. I read the data with
The way I do it now is very cumbersome and takes a lot of time to process.
hex = [dec2hex(adc(:,1+(i-1)*3)) dec2hex(adc(:,2+(i-1)*3)) dec2hex(adc(:,3+(i-1)*3))];
bin = dec2bin(hex2dec(hex),24);
bin32 = [bin(:,[1 1 1 1 1 1 1 1]) bin ];
val = double(typecast(uint32(bin2dec(bin32)),'int32'));
where i is the index for the current channel. I couldn't figure out a way to do it for all channels simultaneously.
This proposed solution does not work for me. For example
k = typecast([int8(-(adc(1,1)<0)) adc(1,1:3)],'int32');
where adc(1,1:3) = [0,9,10]. This should result in 154, but I get 168361984. After swapbytes(k) I get 2314. Also, when I try to compute this for the whole dataset
k = typecast([int8(-(adc(:,1)<0)) adc(:,1:3)],'int32');
Error using typecast. The first input argument must be a vector.
Can someone help me out here? Thanks, Andy