PS: the examination for the industrial network course is coming soon. I found an article on the Internet to learn more.
Principle of cyclic Verification Code (CRC) verification error detection and correction
Errors caused by physical processes are usually abrupt rather than individual errors in some media. Network designers have developed two basic policies to handle errors. One way is to add enough redundant information to each data block to be sent so that the receiver can deduce the characters that have been sent. Another method is to add enough bytes to let the receiver know the error, but do not know what the error is, and then ask the receiver to re-transmit it. The former uses an error-correcting code, while the latter uses an error-detecting code ).
1. Error Correction Code
Before learning about the error correction code, we should first understand a basic concept: Haiming distance. Generally, a frame includes M data (packet) bits and R detection bits or verification bits. If the entire length is set to n (n = m + r), the unit with the length of N is usually called the n-bit codeword ).
Given any two code words, such as 10001001 and 10110001, you can determine how many corresponding bits are different. In this example, three digits are different. To determine how many digits are different, you only need to perform an exclusive or operation on the two code words, and then calculate the number of 1 in the result. The number of different digits in two codewords is called Hamming distance ). It is important that, if two codewords have a Hamming distance D, it requires a d bit error to convert one codeword to another.
The Checksum and Error Correction capabilities of a encoding are determined by its Hamming distance. D + 1 encoding is required to detect D-bit errors, because D-bit errors cannot convert a valid code word into another valid code word. When the recipient sees an invalid code word, it can correct it to understand that a transmission error occurs. Similarly, in order to correct the D-bit error, the distance must be 2D + 1 encoding, because the distance of the valid code word is far away even if d changes, the changed code word is still closer to the original code word than other code words. As a simple example of Error Correction Code, consider the following code with only four valid code words:
0000000000, 0000011111, 1111100000, and 1111111111
This code is 5 away, that is, it can correct dual-bit errors. If the receiver knows that the original code word is 0000000111 after the code word 0000011111 is reached. However, if three errors occur and 0000000000 is changed to 0000000111, the error cannot be corrected correctly.
2. Check the error code
The error code is also used for data transmission. For example, if the channel is in the ticket mode and cannot be re-transmitted, most of them use the error code checking method to increase transmission.
Assume that channel errors are isolated, and the error rate of each channel is 10-6. The size of the data block is 100 bits. For Block Error Correction with 1000 bits, 10 bits are required; for 1 MB of data, 10000 bits are required. If you only need to check the one-digit error of a data block, one parity of each block is enough. An additional data block is required for each transmission of 1000 data blocks. The entire overhead of error checking + retransmission is only 2001 bits per MB of data, and the Hamming code is 10000 bits.
If only one parity bit is added to a block, the detection rate of long burst errors of the block will be very bad. The probability of detecting errors is only 0.5, which is unacceptable. Improvement measures can be taken to form a rectangle matrix with N-Bit Width and K-Row Height for sending each data block. Calculate the parity of each column separately and attach it to the matrix as the last row of the matrix, and then send it by row. When the block arrives, the receiver detects all the parity bits. If any of them has an error, you need to re-transmit the entire block.
This method can detect sudden errors with a single degree of N, because each column has only one change. However, if the first digit is reversed, the last digit is reversed, and all other digits are correct, the burst error with the length of N + 1 will not be detected. If a block is damaged by a long burst error or a short burst error, the probability of the parity value in each column in N is 0.5, the probability of this error block being accepted should not be 2-N.
Although the above method is sometimes enough, in practice, another method is widely used, that is, polynomial encoding (also called cyclic embedding code or CRC code ). Polynomial Code is based on the bit string as a polynomial with a coefficient of 0 or 1, a K-bit frame can be seen as a coefficient sequence of Xk-1 from K-1 to x0. If a polynomial code is used, the sender and receiver must negotiate with each other in advance to generate a polynomial g (x). The height and low position of the generated polynomial must be 1. To calculate the M-bit frame M (x) checksum, the generated polynomial must be shorter than the polynomial. The basic idea is to add the checksum to the end of the frame so that the polynomial of the frame with the checksum can be wiped out by G (x. When the receiver receives a frame with a Checksum, g (x) is used to remove it. If there is a remainder, an error occurs during transmission.
The algorithm for calculating the checksum is as follows:
①. If G (x) is set to R level and R zeros are appended at the end of the frame to make the frame m + R bit, then the corresponding polynomial is xrm (X ).
②. According to mod 2 Division, remove the bits corresponding to xrm (x) with the bits corresponding to G (x.
③. Subtract the remainder from the bit string corresponding to xrm (x) by mod 2. The result is the frame of the conveyor belt checksum, called polynomial T (X ).
The following three polynomials have become international standards:
Three polynomials:
CRC-12 = x ^ 12 + x ^ 11 + x ^ 3 + x ^ 2 + x + 1
CRC-16 = x ^ 16 + x ^ 15 + x ^ 2 + 1
CRC-CCITT = x ^ 16 + x ^ 12 + x ^ 5 + 1
All three polynomials contain x + 1 as the basic factor. The CRC-12 is used when the string length is 6 bits; the other two polynomials are used when the string length is 8 bits. A 16-bit checksum, such as a CRC-16 or CRC-CCITT, can capture all unit errors and double errors, all odd-digit errors, all burst errors with length less than or equal to 16 bits, the length of 99.997% is 17 bits, and the length of 99.998% is 18 bits or more than 18 bits.
Assume that the original packet generated using polynomial g (x) = X4 + X3 + x + 1 is 11001010101 encoded packets.
First, the generated polynomial is 11011, and K zeros are added after the original message. Here K = 4 is the number of polynomials.
Then retrieve the remainder
11011 110010101010000
----------
11001
11011
--------
10010
11011
--------
10011
11011
--------
10000
11011
--------
10111
11011
--------
11000
11011
--------
11000
11011
--------
11
Cyclic Redundancy Verification Code
Cyclic Redundancy checksum (CRC) is widely used in serial transmission (disk and communication ). CRC also adds a few verification codes to the Information Code to increase the code distance of the entire coding system and the capability of checking and correcting errors.
The CRC theory is very complicated. Generally, the book only introduces the method for calculating the verification code after generating polynomial. The error checking capability is related to generating polynomials and can only be memorized based on the conclusions in the book.
The basic principle of the cyclic redundancy check code (CRC) is: after the K-bit information code is spliced with the R-bit check code, the length of the entire code is N bits. Therefore, this encoding is also called (n, k. For a given (n, k) code, it can be proved that there is a polynomial g (x) whose maximum power is N-K = R ). The checksum code for K-bit information can be generated based on g (x), while G (x) is called the polynomial of CRC code generation.
The specific generation process of the Verification Code is as follows: assume that the sending information is represented by the information polynomial C (x), and C (X) is shifted to the r bit, it can be expressed as C (x) * 2R, in this way, the right side of C (x) will be blank out of the r bit, which is the position of the verification code. The remainder obtained by dividing C (x) * 2r by the generated polynomial g (x) is the verification code.
Several Basic Concepts
1. polynomial and binary digital
There is a direct correspondence between polynomials and binary numbers: the highest power of X corresponds to the highest bit of the binary number. The following correspond to the power of each polynomial. This power corresponds to 1, if this power item does not exist, it corresponds to 0. It can be seen that the maximum power of X is R, and the conversion to the corresponding binary number has R + 1 bits.
Polynomials include generating polynomials g (x) and Information polynomials C (X ).
If the generated polynomial is g (x) = X4 + X3 + x + 1, it can be converted to binary digital 11011.
The sending information bit 1111 can be converted into a data polynomial of C (x) = X3 + X2 + x + 1.
2. Generate Polynomials
It is a convention between the receiver and the sender, that is, a binary number. This number remains unchanged throughout the transmission process.
At the sender, the information polynomials are calculated using the generative polynomials by Division 2 to generate the verification code. The receiver uses the generative polynomial to perform a Division 2 test on the received encoded polynomial and determine the error location.
The following conditions shall be met:
A. The highest bit and the lowest Bit of the generated polynomial must be 1.
B. When an error occurs in any part of the transmitted information (CRC code), the remainder of the generated polynomial should not be 0 after the modulus 2 is division.
C. When an error occurs for different bits, the remainder should be different.
D. Perform the division of the remainder by mod 2. The remainder should be cyclically generated.
Reflecting these requirements as mathematical relationships is complicated. However, the commonly used generative polynomials corresponding to different code systems can be found from relevant data, as shown in 9:
N k code from d g (x) polynomial g (x)
7 4 3x3 + x + 1
1011
7 4 3x3 + X2 + 1
1101
7 3 4x4 + X3 + X2 + 1
11101
7 3 4x4 + X2 + x + 1
10111
15 11 3x4 + x + 1
10011
15 7 5x8 + X7 + X6 + X4 + 1
111010001
31 26 3x5 + X2 + 1
100101
31 21 5x10 + x9 + X8 + X6 + X5 + X3 + 1
11101101001
63 57 3x6 + x + 1
1000011
63 51 5x12 + x10 + X5 + X4 + X2 + 1
1010000110101
1041 1024x16 + x15 + X2 + 1
11000000000000101
Figure 9 commonly used generative Polynomials
3. Division of Modulo 2 (Division by bit)
The division of Modulo 2 is similar to the division of arithmetic division, but the result of Division (subtraction) of each bitwise does not affect other bitwise, that is, it does not take the last bitwise. So it is actually an exclusive or. Then shift the shift to reduce the modulo 2 of the next position. The procedure is as follows:
A. Use the divisor to perform a modulo 2 reduction on the maximum number of divisor digits without any borrow space.
B. Remove one digit from the right. If the maximum remainder is 1, the quotient is 1, and the remainder is reduced by 2. If the remainder is 0, the quotient is 0, and the divisor is shifted to the right.
C. When the number of digits of the remainder is smaller than the divisor, the remainder is the final remainder.
[Example] 1111000 divided by 1101:
1011 --- business
----
1111000 ----- Divisor
1101 ---- Divisor
----
010000
1101
----
01010
1101
----
111 ---- Remainder
CRC code generation steps
1. Convert the generated polynomial g (x) with the highest power of X to the corresponding R + 1 binary number.
2. Shift the Information Code left to the r bit, which is equivalent to the corresponding information polynomial C (x) * 2R.
3. Use the generative polynomial (Binary Number) to divide the Information Code by mod 2 to obtain the remainder of the r bit.
4. Place the remainder to the left of the Information Code and then empty the result to obtain the complete CRC code.
[Example] assume that the generated polynomial is g (x) = X3 + x + 1. The 4-bit original packet is 1010, And the encoded packet is obtained.
Solution:
1. Convert the generated polynomial g (x) = X3 + x + 1 into the corresponding binary divisor of 1011.
2. The generated polynomial has four bits (R + 1). Change the original packet C (X) to a value of 1010000 (R ).
3. Use the binary number corresponding to the generated polynomial to divide the original packet after four shifts left:
1001 ------- vendors
------------------------
1010000
1011 ---------- Divisor
------------
1000
1011
------------
011 ------- remainder (check bit)
5. encoded packets (CRC code ):
1010000
+ 011
------------------
1010011
CRC and Error Correction
After receiving the CRC code, the receiving end uses the generated polynomial g (x) to perform the modulo 2 Division. If the remainder is 0, the code word is correct. If one error occurs, the remainder is not 0, and the remainder is different from the other. It can be proved that the correspondence between the remainder and the error bit is only related to the Code System and the generated polynomial, but not the information bit to be tested. Figure 10 shows the error mode of g (x) = 1011, C (x) = 1010. Changing C (x) (code word) only changes the content of the code word in the table, the correlation between the remainder and the error bit is not changed.
CRC Code received
Remainder error bit
A7 A6 A5 A4 A3 A2 A1
Correct 1 0 1 0 0 1 1
000 none
Error
Incorrect
1 0 1 0 0 1 0
1 0 1 0 0 0 1
1 0 1 0 1 1 1
1 0 1 1 0 1 1
1 0 0 0 0 1 1
1 1 1 0 0 1 1
0 0 1 0 0 1 1
001
010
100
011
110
111
101
1
2
3
4
5
6
7
Figure 10 (1011) Error Mode of CRC code (g (x) =)
If an error occurs in one round robin code, if G (x) is used as the modulo 2, a remainder not 0 is obtained. If we continue to divide the remainder by 0, we will find an interesting result. The remainder of each result will be cyclically in the order shown in figure 10. For example, if an error occurs in the first place, the remainder will be 001, and 0 will be supplemented before division. The remainder of the second time will be 010, followed by 100, 0ll ..., This is the origin of the "cyclic code" name. This is a valuable feature. If the remainder is not 0, the division of the remainder is supplemented with 0, and the checksum word is cyclically shifted to the left. Figure 10 shows that when the remainder (101) occurs, the error bit is also moved to the A7 position. You can use the exclusive OR gate to correct it and send it back to A1. In this way, we do not need to use the decoding circuit to provide correction conditions for each bit like the Haiming verification. When the number of digits increases, cyclic code verification can effectively reduce the hardware cost, which is the main reason for its wide application.