Cyclic Redundancy Check (CRC)

Terminology

  • degree of polynomial: the highest power of the variable in the polynomial:

    • e.g., degree of π‘₯3+π‘₯+1 is 3
  • burst error: a contiguous sequence of bits that are erroneous (flipped from 0 to 1 or from 1 to 0)

Construction of frame

Let’s say we want to transmit frame 𝑇 that contains a data block 𝐷 of length 𝑑 bits. The idea of CRC is to append a checksum 𝑅 (CRC bits) of length π‘Ÿ bits to the end of data block 𝐷 before transmission.

image|w45

In fact, both data block 𝐷 and checksum 𝑅 can be viewed as polynomials over the finite field of integer modulo 2, that is:

  • each coefficient is either 0 or 1
  • addition and subtraction are performed modulo 2 (equivalent to XOR operation)

For example, data block 𝐷=1101 can be represented as polynomial:

𝐷(π‘₯)=π‘₯3+π‘₯2+0Β·π‘₯+1=π‘₯3+π‘₯2+1

So if we describe the generation of frame 𝑇 mathematically, we have:

𝑇(π‘₯)=π‘₯π‘Ÿπ·(π‘₯)+𝑅(π‘₯)

similarly, we can describe it in binary format:

𝑇=2π‘ŸΒ·π·βŠ•π‘…=𝐷β‰ͺπ‘ŸβŠ•π‘…

Generating CRC bits

To generate CRC bits 𝑅, both sender and receiver agree on a generator polynomial 𝐺 of degree π‘Ÿ (which means 𝐺 has π‘Ÿ+1 bits). The generator polynomial is usually chosen to have good error-detection properties. Then, the sender computes CRC bits 𝑅 such that the following condition holds:

π‘₯π‘Ÿπ·(π‘₯)+𝑅(π‘₯)=𝑛·𝐺(π‘₯)

which means π‘₯π‘Ÿπ·(π‘₯)+𝑅(π‘₯) is divisible by 𝐺(π‘₯). Recall that polynomial division can be written in the form of:

𝑃(π‘₯)⏟dividend=𝑄(π‘₯)⏟quotient·𝑀(π‘₯)⏟divisor+𝑆(π‘₯)⏟remainder

we can rewrite the condition as:

π‘₯π‘Ÿπ·(π‘₯)=𝑛·𝐺(π‘₯)βˆ’π‘…(π‘₯)=𝑛·𝐺(π‘₯)+𝑅(π‘₯)since addition and subtraction in𝐺𝐹(2)

which means the remainder of dividing π‘₯π‘Ÿπ·(π‘₯) by 𝐺(π‘₯) is 𝑅(π‘₯):

π‘₯π‘Ÿπ·(π‘₯)⏟dividend𝑃(π‘₯)=π‘›βŸquotient𝑄(π‘₯)·𝐺(π‘₯)⏟divisor𝑀(π‘₯)+𝑅(π‘₯)⏟remainder𝑆(π‘₯)

and hence we can obtain 𝑅(π‘₯) by performing polynomial division of π‘₯π‘Ÿπ·(π‘₯) by 𝐺(π‘₯) and taking the remainder.

Selection of generator polynomial

There two major direction in selecting generator polynomial 𝐺(π‘₯):

  • 𝐺(π‘₯)=𝑃(π‘₯) where 𝑃(π‘₯) is the primitive polynomial of degree π‘Ÿ over 𝐺𝐹(2), which is irreducible and allow data blocks of maximum length 2π‘Ÿβˆ’1 bits

  • 𝐺(π‘₯)=(π‘₯+1)·𝑃(π‘₯) where 𝑃(π‘₯) is the primitive polynomial of degree π‘Ÿβˆ’1 over 𝐺𝐹(2):

    • can also detect all burst errors of length β‰€π‘Ÿ bits
    • can detect all odd number of bit errors (parity check)
    • can only handle data blocks of maximum length 2π‘Ÿβˆ’1βˆ’1 bits

Parity check

If 𝐺(π‘₯) contains the factor (π‘₯+1), then CRC can detect all odd number of bit errors. This is because:

𝑇(π‘₯)=𝑄(π‘₯)·𝐺(π‘₯)=𝑄(π‘₯)Β·(π‘₯+1)·𝑃(π‘₯)

If we substitute π‘₯=1, we have:

𝑇(1)=𝑄(1)Β·(1+1)·𝑃(1)=0

The 𝑇(1) are actually equivalent to counting the number of 1 bits in 𝑇, and recall that the calculation is done in module 2, so 𝑇(1)=0 means there are even number of 1 bits in 𝑇