data-transfertransmissionhamming-code

Is there anything between Hamming code and parity control?


I need to transmit data over the line with some noise. Each transmission packet is only one byte (8 bits). I need that the receiver will be able to catch errors (and optionally correct some of them - but it is not essential as I can repeat the transmission in case of error).

Now I know two options:

  1. Hamming code (8 data bits out of 12 transmitted). Very good performing (single correction and double detection) but hard to implement (or this is not so hard but I don't really understand the idea of the code) and 33% less speed (50% redundancy).
  2. Parity control. Very easy to implement. However not very reliable: only one error will be detected (no corrections, double error will result in failed data transmission).

So may be there is any intermediate coding algorithm more reliable than parity control but easy than Hamming code?


Solution

  • Ok here is something you can do:

    take any 2 bits (or bytes, just understand that most languages support byte operators much more than bit operators), xor them together... this is your verification code...

    so you have:

    xor (^) table
    _________________________
      | 0 | 1 
    0 | 0 | 1
    1 | 1 | 0
    

    so some sort of code:

    byteA = 0x3d;
    byteB = 0x47;
    
    verificationCode = byteA ^ byteB;
    

    then you send these 3 bytes across the wire, and you can use them to detect a transmission failure...

    This is not a hamming code, it is a simple detection method ...

    hamming codes work on nibbles, half bytes:

    imagine a bit type:

    bit a = 1;
    bit b = 0;
    bit c = 1;
    bit d = 1;
    
    bit p1 = (a + b + d) % 2;
    bit p2 = (a + c + d) % 2;
    bit p3 = (b + c + d) % 2;
    

    then you mash the bits and pbits together and put them over the wire:

    [p1,p2,a,p3,b,c,d, p4 if it exists]

    so if you calculate the parity codes on the other side:

    if one bit is flipped, then you can recover:

    (assume all parity bits not specified are correct)

    if it isn't one of these state... then there are 2 or more bits wrong, and you must re-transmit...

    you can also add some verification by using a 4th parity bit, which also conveniently fits into an 8 bit byte...