There is a problem I currently cannot resolve and need help.
I have transmitter and receiver devices. Transmitter needs to transmit random byte sequence (with possible repetitions) or unknown length. The sequence can be transformed (encoded) before transmission if we need.
Receiver device receives the sequence bytewise. It strongly requires to not have repetitioned bytes in incoming sequence. Every new byte must be different from the previous received one.
The question is how to encode the input byte sequence on transmitter side to avoid repetitions in receiver incoming byte sequence?
All bytes of incoming sequence should be uniquely decoded on receiver side.
I've heard about scramblers. As I understand some of they can output byte sequence without repetitions. But is there some simpler way?
Ignoring the first byte, the restriction that you can't have repeat bytes means that every byte represents a 1-in-255 choice, not a one-in-256. That means you can send slightly less than 8 bits per byte (7.994353 bits)
Hence, coding theory tells us that you need to transform your 256-symbol input stream into a 255-symbol stream. You then encode this 255-symbol stream by remembering the previous byte you sent out. If the symbol you want to send is lower than the previous byte you send, you send it unmodified, else you send it +1.
The decoding algorithm is the reverse. If you receive a byte that higher than the previously received byte, subtract one.
As a simple example, consider sending 254 254 254. The first one can be sent straight away (first symbol), the second will be sent as 255 (+1) and the next one will be 254 again. Thus the receiver sees 254 255 254. The only byte that's higher than the preceding byte is 255, so subtract one from that to recover the initial sequence 254 254 254.
This coding is the most efficient possible, we just have the minor challenge of mapping a random byte stream (256 symbols) to a 255-symbol stream. Remember, in this 255-symbol code, duplications are allowed. That's the reason why we invented it.
One easy but inefficient hack is to replace 254 with 254 0 and 255 with 254 1. The downside is that this effectively uses 15.998 bits for those two inputs. One difficult but perfectly space-efficient hack is to consider the whole input as a base-256 number, and convert it to base-255.
What exactly you choose probably depends on your input.
You can send data as padded group of 8 bytes, with 7 bytes of data and one special byte which has 7 bits to set 0 or 1 depends if it requires corresponding data byte to be modified (xor with FF or something) to make them different than previous. Last bit is used to make this byte different than last data one.
original data:
0x00 0x00 0x00 0x00 0x00 0x00 0x00
packet:
0x00 0xFF 0x00 0xFF 0x00 0xFF 0x00 0b01010100 <- last bit would be flipped if previous data byte is the same as this byte
Note: if you do not have buffer for 8 bytes you can send padding byte first keep it in register, left/right shift and process next byte based on bit value.
A simple approach is to just use the top bit for uniqueness, and the lower 7 bits to carry data:
0xxxxxxx 1xyyyyyy 0yyzzzzz 1zzz....
This encodes every 7 bytes of input as 8 bytes on the connection. On the sender, you have one bit of state to toggle between 0 and 1, and a 0-6 counter for the variable bitshifts. On the receiver, you don't even need to decode the top bit, so you just have the 0-6 counter to reverse the bit shifts. On both sides, you need to keep part of one byte as well, so you need about 2 bytes of state for this. Still, not too bad and certainly doable in an FPGA or about a dozen ARM instructions.
Guys what do you think about idea to use some soft byte scrambler?
I mean some simple algorithm than will transform original byte stream into pseudo-random sequence without repetitions?
Is it possible to avoid repetitions reliably this way?
Just would like to know it as additional possible solution...
I can receive from the camera a packet that contains information about the frame. So, I know its size. The rest of the packet is an array of bytes (uint8).
I would like to know how to manage this packet of bytes and how to decode it in order to get a frame. I know from the header that the frame can be I-frame or P-frame and that its size is 640x360. The encoding can be set to H264 or MP4. I'm working with MatLab script, which is an M-file. If MatLab cannot manage this array of bytes directly, I would like to know how a byte stream works, to be able to re-assamble the frame myself.
I am trying to communicate with a camera in Simulink via the two blocks tcp/ip and receive/send.
Therefore I need to send the following specific 12 byte sequence (displayed in hex):
07:00:00:00:00:00:00:00:00:8c:01:00
I was trying to solve it with the simulink block "byte pack". I connected 12 constant-blocks with it and chose the decimal for each constant-block, that is corresponding to a byte of the 12 bytes, and changed the input data type to double. But it didnt work and I dont know what I've made wrong.
Any suggestions or other solutions to my problem?
I am trying to build a DSP process in Matlab.
The ADC delivers uint16 data. This data should be filtered and processed. The filter works in the DSP with fixed point (fract16).
Should a transformation take place if I want to do work with the data Matlab? How to do it?
You can just treat the 16 bit unsigned fractional data as integers and then scale the data to floating point in the range 0.0..+1.0 prior to any processing. E.g.
data = data / 65535.0;
If the data is actually signed fractional (int16) then you would convert it to the range -1.0..+1.0 like this:
data = data / 32768.0;
I'm trying to decode packets sent by this application : https://itunes.apple.com/ie/app/sensor-data-streamer/id608278214?mt=8 -- it sends sensor data in a udp packet. I'm using wireshark to look at the contents of the packet, and the header matches the description so I'm looking at the right thing.
I need to decode the raw hex to a float, but everything I've tried (python, web forms, iphone apps) to convert the data results in nonsense. For example, here is the payload
The first 4 highlighted bytes are the header. Then the next 4 are the X accel, next 4 are Y accel, and next 4 are the Z accel. The values change quickly so it's tough to figure out the exact expected value. But the mapping should be something (in the order of)
0000ee3b -> +0.0072
004030bc -> -0.0215 (some positive or negative number close to zero)
802b80bf -> -1.0032
I'm assuming they are using some iPhone function to encode the data. Does anyone have any idea what the conversion mechanism is?
Thanks,
reza
Seems it is just little-endian IEEE-754 encoding.