[Easy-to-understand communication] Channel coding-Hamming code

1. What is hamming code


"Hamming code", also known as "Hamming code", is called "hanming code" in English. In the field of communication, "Hamming code" has a wide range of applications and was invented by Richard Wesley Hamming in 1950. . "Hamming code" is a kind of "error correction code" that can be used to detect and correct errors that occur when data is sent from the sender to the receiver.

Hamming inventor Richard Hamming in the late 1940s, the use of the Bell Model V (Bell Model V) computer in Bell Labs work (Bell Labs). Input is to rely on punch cards (Punched Card), which will inevitably cause some read errors. On working days, when the machine detects an error, it will stop and flash lights (flash lights) so that the operator can solve the error. During weekends and after get off work, without an operator, the machine will simply move to the next job.

Hamming worked on weekends, and he became increasingly frustrated that he always had to restart the program after an error with an unreliable card reader . In the next few years, in order to solve the problem of debugging, he developed increasingly powerful debugging algorithms . In 1950, he published what is called Hamming code today, and it still shows its application value on ECC memory today .

 

Second, let’s first understand what a "redundant bit" is


"Redundant bit" is a binary bit, which is used to add to the data information that needs to be transmitted to ensure that the information will not be lost or changed during the transmission process.

Regarding the question of how many "redundant bits" are needed, we have a formula that can be used to calculate:

Among them, r refers to how many bits are needed for redundant bits, and m refers to the number of binary bits of the transmitted data.

Assuming that the binary digits of the transmitted data are 7 bits, the number of redundant bits can be calculated by the above formula:

= 2^4 ≥ 7 + 4 + 1

Therefore, ours needs at least 4 binary bits as "redundant bits".

 

3. Let's take a look at the "parity bit"


A parity bit is a bit used to add to the binary data. It determines whether the data has changed during transmission by ensuring that the number of "1"s in the entire binary data information is odd or even. Therefore, there are two types of detection methods:

One, odd parity

In the odd check detection mode, for the data information bits that need to be sent, the number of 1 is checked . If the number of 1s in this string of bits is odd, in order to ensure that the number of 1s in the entire string of data is odd after adding "redundant bit"," it is conceivable that the redundant bit should be set to " 0". If the number of 1s in the data bit stream is even before the "redundant bit" is added, then in order to make the number of 1s into an odd number at the end, the redundant bit should be set to 1.

Two, even parity

In the same way, in the even check detection mode, the number of 1 is still checked for the data information bits that need to be sent . If the number of 1s in this string of bits is odd, in order to ensure that the number of 1s in the whole string of data is even after adding "redundant bit"," it is conceivable that the redundant bit should be set to " 1". If the number of 1s in the data bit stream is an even number before adding the "redundant bit", then in order to make the number of 1s into an even number at the end, the redundant bit should be set to 0.

This time we use "even parity" as a demonstration, that is, we need to ensure that the number of "1"s in the entire data of the data binary bit plus the "parity bit" should be an even number.

Assuming that the data information that needs to be transmitted this time is 3 binary bits, the demonstration animation is as follows: (click on the animation to view it in full screen, the effect is better!)

 

 

 

As the animation demonstrates, our "parity check bit" has been successfully added to the data information that needs to be transmitted. This animation uses the "even check" method, that is, the number of 1 must be at the end Satisfaction is an even number. Assuming that during the transmission process, one of the digits has changed, what will happen? We still use the situation described in the animation above: suppose that during the transmission process, one of the data bits has changed. (Click on the animated picture to view the full screen for better results!)

 

At this time, the even check circuit finds that the number of the last "1" is not an even number, indicating that the data must have changed during the data transmission process. However, the "parity check method" still has the following two shortcomings:

1. Although it is known that the data has changed during transmission, it is not known which bit has changed, so the error cannot be corrected, and the sender can only be required to send the data again.

2. The "parity check method" can only find 1, 3, and 5 bits. . . . . . Odd number of binary bits have changed. Assuming that 2 bits have changed during data transmission, the "parity check method" cannot find that the data has been changed, and the data is still considered correct. The following animation demonstration: (click on the animated picture to view the full screen for better results!)

 

 

 Fourth, the coding method of Hamming code


For beginners, the Hamming code may make the head bigger. However, if you carefully read and understand the "parity check method" described above, Hamming code will become very simple. We have described two shortcomings of the "parity check method" above, one of which is that the parity check method will become invalid when an even-numbered bit of 2 or greater changes during transmission. However, with the rapid development of science and technology, in the process of data communication and transmission, the probability of data change is very, very small, and the probability of one bit of data changing is even smaller. Therefore, 2 bits means more than 2 bits. We assume that the changed situation will never happen. Therefore, the remaining problem we need to solve is: assuming that one person has changed, is there any way for us to find out which one has changed? If we can find out which bit has changed, we can correct it. 0 becomes 1, and 1 becomes 0. Hamming code solves this problem very well.

First, let's take a look at how the Hamming code is encoded! Hamming code is actually an upgraded version of the "parity check method". It is a combination of multiple "parity check methods", but the position of the parity bit is not necessarily the last bit, but there are other Calculation method.

Assuming that the data information we need to transmit is composed of 7 binary bits, we have calculated through the second part that at least 4 redundant bits are required. Therefore, the entire information stream has 11 binary bits. There are 7 data bits and 4 "parity bits".

 

At this time, some students will take it for granted. The last 4, 3, 2, and 1 positions must be 4 "parity check bits". In fact, the Hamming code has special regulations for the position of the "parity check bits":

All power-of-two bits (2^0=1,2^1=2,2^2=4,2^3=8...) are used as "parity bits", therefore, the first bit, the second bit , The 4th bit, the 8th bit is the parity bit, and the other 7 bits are the data bit.

At this time, some students must be confused again. If the "parity bit" is arranged in this way, which parity bit "controls" which group of data?

At this point, we are going to talk about the core encoding method of Hamming code. We express the binary form of the index, as shown in the following figure:

 

We can then classify the binary index in one of these ways:

Counting from right to left (from low to high), the index with "1" in the first digit is: 1011,1001,0111,0101,0011,0001

The corresponding decimal index is: 11,9,7,5,3,1, then the data bits above these bits and the number 1 "parity bit" form a group.

As shown below:

 

The same reason: count from right to left (lower to higher), the second digit is "1", the indexes are: 1011, 1010,0111,0110,0011,0010

The corresponding decimal index is: 11,10,7,6,3,2, then the data bits above these bits and the No. 2 "parity bit" form a group.

As shown below:

 

In the same way, the data bits "managed" by the parity bit No. 3 are as follows:

The data bits of parity bit No. 4 "management" are as follows:

In this way, we have established the grouping, and then we need to start filling the data bits, assuming that we need to transmit 7 data bits: 1011001

As shown below:

Next, we need to fill in the "parity bit" of each group separately. (Using odd parity)

For the first group (1, 3, 5, 7, 9, and 11 bits are a group): the number of 1 is 4, and the number is even, so the number ① should be 1. In this way, the number of 1s can be guaranteed to be odd at the end.

Similarly, for the second group (2,3,6,7,10,11 bits 1 group): the number of 1 is 3, which is already an odd number, so the number ② should be 0.

For the third group (a group of 4, 5, 6, and 7 digits), the number of 1 is 1, therefore, the number ③ should be 0.

 

For the fourth group (8,9,10,11 is a group), the number of 1 is 2, therefore, ④ should be 1.

Finally, the total Hamming code is constructed, as shown below:

 

"Error correction" and "correction" of Hamming code 


Above, we have completed the coding of the "hamming code", then, how does the hamming code find errors and correct them?

Assuming that the "0" on the "5" bit changes to "1" during the transmission, the data received by the receiver is: 10111010101.

 

Hamming code checks the "odd parity" of each group to determine whether an error has occurred.

First of all, the first group (1, 3, 5, 7, 9, 11 digits): the number of 1 is 6 digits, which is no longer an odd number. Therefore, we can conclude that there must be some data in this group. The error occurred, but I cannot determine which one has the error. In order to achieve "odd parity", we must add 1 to reach an odd number of 1s.

Next, we check the second group (2,3,6,7,10,11), the number of 1 is 3 digits, which still meets the "odd parity", so we can also conclude that there is no one in this group The bit data has changed. Therefore, we only need to add 0.

We continue to check the third group (4,5,6,7). The number of 1 is 2, which does not meet the "odd parity". Therefore, we can conclude that there are also data changes in this group. In order to achieve "odd parity", we must add 1 to reach an odd number of 1s.

We check the fourth group (8, 9, 10, 11 bits), the number of 1 is 3 bits, which meets the "odd parity", so there is no change. So we only need to add 0.

As shown below:

 We found that the final binary number is: 0101. We will magically find that 0101 is the binary representation of decimal 5. Therefore, we can accurately know that the data has changed on the 5th position. The No. 5 position can be inverted. Finally, the receiver can modify it to the correct data.

Although we feel that Hamming codes are a bit complicated in both "encoding" and "error correction", but through specific electronic technology, fast electronic components can be designed to specifically perform these operations.

 

Guess you like

Origin blog.csdn.net/a493823882/article/details/109343791