CRC

Guest Lecture by Wes Peterson, March 5, 2002.
recorded in mp3.

Notes taken by Edo Biagioni (esb).

There are different algorithms for error detection and correction. Some of the reasons for the widespread use of CRCs may include:

Fields and Polynomials

Brief description of a field: a set of elements, and two operations, addition and multiplication, both of which are associative and commutative. Multiplication must distribute over addition, i.e. a*(b + c) = (a*b) + (a*c), and there is no division by zero (see this link for a more formal definition -- esb). The reals and the rationals each form a field under the usual rules for addition and multiplication, and so do the integers modulo a given prime.

The smallest field is that of the integers modulo 2.

Think about polynomials P(x) that have 0 or 1 as their coefficients
(esb: for example, 1 * x3 + 0 * x2 + 1 * x1 + 1 * x0, which is simply x3 + x + 1).

With integers, the unique factorization theorem states that for any integer n and any divisor d, n = dq + r identifies values q and r. q and r are unique if and only if r < d. Likewise, with polynomials, for any a(x) and d(x) we have that a(x) = d(x)q(x) + r(x). Again, q(x) and r(x) are unique if the degree of r is less than the degree of d, deg(r) < deg(d).

Just as prime numbers are not divisible by any other integer (except 1), there are irreducible polynomials. This is covered at UH in Math 412/413.

Error Checking Overview

A message is a sequence of 1s and 0s. We can think of them as polynomials. For example the message 1 0 1 1 1 0 1 1 would be x7 + x5 + x4 + x3 + x + 1.

For error checking purposes, the only messages I am going to send are messages F(x) that are divisible by a given polynomial P(x). When I receive a message, I am going to check that it is divisible by P(x) -- if it is not, an error has occurred.

On the other hand, some errors might modify the message, but the resulting polynomial might still be divisible by P(x). These are the undetected errors, and we need to characterize them.

If G(x) is what we want to send, P(x) is the generator for the code (of degree m), F(x) is what we can send because it is divisible by P(x). Start by multiplying G(x) by xm -- this is equivalent to adding m 0 bits after the message G(x). The result is
G(x) xm = P(x) Q(x) + R (x), or
G(x) xm + R (x) = P(x) Q(x), or
G(x) xm - R (x) = P(x) Q(x).
Note that G(x) xm - R (x) is divisible by P(x).

The last form occurs because in modulo-2 arithmetic, adding is the same as subtracting: 1 + 1 = 0, 1 - 1 = 0, and 0 + 1 = 1, 0 - 1 = 1, and x + 0 = x. x - 0 = x for any x, so adding or subtracting has the same effect. This also holds for polynomials with coefficients modulo 2, since the addition and subtraction is done on the coefficients.

Example: G(x) = 1 1 0 1 0 1 1, m = 4,
G(x) xm = 1 1 0 1 0 1 1 0 0 0 0,
R(x) is a polynomial with degree less than m, so R(x) has the form 0 0 0 0 0 0 0 b1 b2 b3 b4 for some value of b1... b4.
Therefore, G(x) xm + R(x) = 1 1 0 1 0 1 1 b1 b2 b3 b4.

When we communicate, we will send F(x), receive H(x), where deg(F) = deg(H) = deg(G) + m. We can define H(x) as the sum of the original message and an error E(x), so that H(x) = F(x) + E(x). E(x) has a coefficient of 1 exactly where H(x) differs from F(x), i.e. exactly where there has been an error. To restate our concern above, we want to know under what conditions H(x) is divisible by P(x), since these are our undetectable errors. H(x) is divisible by P(x) if and only if E(x) is divisible by P(x).

Choosing P(x)

To find out if E(x) is divisible by P(x), we look at the types of polynomials P(x). If P(x) is divisible by x, then every F(x) is divisible by x, so the last bit that we send is always zero, so there would be no point in actually sending it. So we are going to assume that P(x) is not divisible by x, that is, the last bit of P(x) is 1, that is, the coefficient of x0 is 1.

If the transmission has a single bit error, E(x) = xi for some value of i. xi is not divisible by P(x) as long as P(x) is not divisible by x. We know this by the remainder theorem:

The remainder of F(x) divided by (x - a) is F(a).
It follows that if F(a) = 0, F(x) is divisible by (x - a).

Proof of the remainder theorem: F(x) = (x - a) q (x) + r. r is a constant, since r must have degree less than deg(x-a) = 1. F(a) = (a - a) q(a) + r = 0 q(a) + r = r. Therefore, if F(a) = 0, r = 0, and F(x) = (x - a) q(a) so F(x) is divisible by (x - 1).

For the case of polynomials with coefficients modulo 2,

F(x) is divisible by (x + 1) if and only if F(1) = 0
This can be proven by applying the remainder theorem with x = 1, and since if x is 1, x + 1 = 1 + 1 = 1 - 1 = 0. Also,
F(1) is the XOR of the terms, so it is 1 if the polynomial has an odd number of non-zero terms, and 0 if the polynomial has an even number of terms.
This can be proven since 1 raised to any power is still one.

As a result of these two lemmas, an even parity for F(x) makes it divisible by x+1, odd parity makes it not divisible by x+1.

This means that if F(x) is divisible by x+1, it can be used to detect all error patterns with an odd number of bit errors.

Because of unique factorization, if E(x) is divisible by x+1, it must have an even number of terms:
Assume p(x) is irreducible and of degree m.
Prove that there is an m such that xm - 1 is divisible by p(x).