farmsnero.blogg.se

2byte to 1 byte evom
2byte to 1 byte evom











Then in the receiver: adc1 = (data * 5.0) / 256 That may not be as bad as it sounds, for example, if your ADC is 12 bit (not clear in your question), you loose just 4 bits. Essentially you would need treat your ADC as if it were 8 bit. It cannot be done without loosing bits and therefore precision. If it is not at least 33%, then you best to accept that data is too dynamic to be completely transmitted with the requirements given.

2byte to 1 byte evom

What every the ration of compression is found, is an indicator of the best compression scheme we could derive. Take a couple 1000 (million) samples and write it as packed 12-bit data into a file.

2byte to 1 byte evom

Might need a minor adjustment to insure any bias in the receiving sum eventually works its way out. Sometimes sending the course value, other times, the delta.Īs commented below always send a signed 8-bit delta. 24-bits of data in 3 8-bit messages.Īs answered in the beginning of this answer. Like #2, but send 2 out of every 3 samples.

2byte to 1 byte evom

The 2nd A/D sample on the transmits end is thrown away. The receiving end needs 2 samples to put things back together. Use the MSB to distinguish if the upper or lower is sent. Send the first A/D sample in 2 parts by cutting the 12-bit value into 2 6-bits halves. Simple divide the 12-bit value by 16, send those 8 bits and multiply by 16 on the receiving end. Refinements include having the delta give up 2 bits of mantissa for a 2-bit exponent.ġ2 bits of random data do not fit in 8 bits. Other considerations apply, yet here it is to give the OP another point of view. Likely should reserve another bit to detect a missed sequence when sending a delta. sample = ADC() ĭiff = sample - (encode_value = -64 & diff > 7 The following is a coarse implementation idea.Īssume 2-byte ADC value in the ranges 0-3FFF. When the ADC is changing fast, sent a 7-bit approximation. For example, chux's solution encodes values exactly as long as the values don't change too fast, but only has a precision of about 0.04 when the values are changing quickly. Other encodings might perform better, depending on what you expect the signal to look like. This keeps a precision of 5/256, or about 0.02. For example, we can just throw away the 4 least-significant bits of every value: encoded = val > 4Īnd decode appropriately: decoded = encoded * 5.0 / 256 If 1.5 bytes per value is still too much, there are lossy encoding options. You might need to deal with a trailing half-byte. That'd look something like def pack(val1, val2): UPDATE: With the additional information that these are only 12-bit values, rather than 16-bit, and that the maximum value is 5.0, we can do a lot better, though still not quite 3 significant figures in 8 bits.įirst, instead of wasting 4 bits per value, we can pack 2 values into 3 bytes.

2byte to 1 byte evom

A byte can only encode 256 different values, and encoding everything from 0.00 to 9.99 takes 1000 different values, so you still can't do it. If you instead throw away half your data, you can reduce the size of things, but you say you want at least 2 digits after the decimal point. If there were some magic way to stuff two-byte values into one-byte values, we would do it to everything, and then we would do it again, and we would keep doing it and keep halving the size of everything until we were shoving all the world's information into a single byte.













2byte to 1 byte evom