ad space

Example of How Hamming Coding Works?

In digital communication, ensuring data integrity is critical. One of the most effective error-detection and correction techniques is the Hamming Code. It allows for the detection and correction of single-bit errors in transmitted data. In this post, we’ll walk through the process of encoding data using Hamming code, transmitting it with a possible error, and finally correcting it on the receiver side. We’ll use an example where the transmitted data is 1011 and walk through each step to demonstrate how the receiver can recover the original data even with an error.


Step 1: Understanding Hamming Code

Hamming code uses redundant bits (also called parity bits) to ensure that the receiver can detect and correct errors. The number of redundant bits needed depends on the number of data bits being transmitted. For example, if we want to transmit 4 data bits, we need 3 redundant bits to create a 7-bit encoded message.

Hamming Code Structure

Here’s the structure of the Hamming code for a 4-bit data message:

Bit Position1234567
ContentP1P2D1P4D2D3D4
  • P1, P2, P4: These are the redundant (parity) bits, placed in positions 1, 2, 4 respectively.
  • D1, D2, D3, D4: These are the data bits that we want to transmit, placed in positions 3, 5, 6, 7 respectively.

Step 2: Encoding Data Using Hamming Code

Let's say we want to transmit the 4-bit data 1011. The process starts with placing the data bits in the Hamming code structure:

Bit Position1234567
ContentP1P21P4011

Now, we calculate the parity bits.

  • P1: Covers positions 1, 3, 5, 7. We XOR the bits at these positions: P1=D1D2D4=101=0P1 = D1 \oplus D2 \oplus D4 = 1 \oplus 0 \oplus 1 = 0
  • P2: Covers positions 2, 3, 6, 7. We XOR the bits at these positions: P2=D1D3D4=111=1P2 = D1 \oplus D3 \oplus D4 = 1 \oplus 1 \oplus 1 = 1
  • P4: Covers positions 4, 5, 6, 7. We XOR the bits at these positions: P4=D2D3D4=011=0P4 = D2 \oplus D3 \oplus D4 = 0 \oplus 1 \oplus 1 = 0

The encoded data is:

Encoded Data=0110011\text{Encoded Data} = 0 \, 1 \, 1 \, 0 \, 0 \, 1 \, 1

This is the 7-bit encoded message that will be transmitted.

Below is the circuit diagram of Hamming Encoder:

hamming encoder

 


Step 3: Transmitting Data with Error

Now, suppose during transmission, an error occurs and the transmitted data is altered. The receiver gets the following data:

Received Data=0110010\text{Received Data} = 0 \, 1 \, 1 \, 0 \, 0 \, 1 \, 0

As you can see, bit position 7 is flipped from 1 to 0.


Step 4: Error Detection and Correction

On the receiver side, we need to check for errors using the parity bits. The receiver will calculate the parity for each bit position (P1, P2, and P4) and compare it with the expected values.

Step 4.1: Checking Parity Bits

  • P1: XOR the bits at positions 1, 3, 5, 7:

    P1=110=0P1 = 1 \oplus 1 \oplus 0 = 0

    This matches the expected parity, so no error is detected here.

  • P2: XOR the bits at positions 2, 3, 6, 7:

    P2=110=0P2 = 1 \oplus 1 \oplus 0 = 0

    This does not match the expected value (which was 1), indicating an error in one of these positions.

  • P4: XOR the bits at positions 4, 5, 6, 7:

    P4=010=1P4 = 0 \oplus 1 \oplus 0 = 1

    This does not match the expected value (which was 0), indicating an error in one of these positions.

Step 4.2: Identifying the Error Position

By combining the error information from the parity bits, the receiver can determine which bit is erroneous. The error position is calculated as:

Error Position=P1P2P4=011=7\text{Error Position} = P1 \oplus P2 \oplus P4 = 0 \oplus 1 \oplus 1 = 7

This means that the error is in bit position 7.

Step 4.3: Correcting the Error

The receiver flips the erroneous bit at position 7 to correct the error:

Corrected Data=0110011\text{Corrected Data} = 0 \, 1 \, 1 \, 0 \, 0 \, 1 \, 1

Now, the data is corrected and matches the original transmitted data.


Step 5: Decoding the Data

Finally, the receiver extracts the original data bits (D1, D2, D3, D4) from positions 3, 5, 6, and 7:

Decoded Data=1011\text{Decoded Data} = 1 \, 0 \, 1 \, 1

The receiver successfully recovers the original transmitted data (1011) after detecting and correcting the error.


Conclusion

In this post, we've demonstrated how Hamming code works to ensure reliable data transmission by detecting and correcting single-bit errors. We started by encoding 4 bits of data into a 7-bit message, transmitted it with an error, and then decoded and corrected the data using the Hamming code's error correction mechanism. This technique can be crucial in communication systems where data integrity is important.

Using Arduino, you can implement Hamming code to detect and correct errors in transmitted data, ensuring that the receiver always gets the correct message. This method is widely used in computer memory systems, communication protocols, and digital systems.

Post a Comment

Previous Post Next Post