The document discusses Cyclic Redundancy Check (CRC), an error-detecting code. It describes CRC implementation in software using C language. CRC works by dividing the message and CRC bits by a fixed polynomial to detect errors. The document provides code examples to calculate CRC using polynomials and implement CRC to detect errors in transmitted data using C programming language.
1. Cyclic Redundancy Check (CRC)
implementation in Software
using C
Ajay Singh (2014JOP2558)
Manoj Falaswal (2014JOP2489)
Physics Department
Indian Institute of Technology Delhi
2. Contents:-
1. Why Error Detection And Correction?
2. Type Of Errors
3. Error Detection Techniques
Parity Check
Two Dimensional Parity Check
Checksum
Cyclic Redundancy Check
4. CRC Implementation
Modulo-2 Arithmetic
Digital circuit for polynomial division
Implementation and Code for CRC in C
Performance of CRC
3. Why error detection and correction
• Because of attenuation, distortion, noise and
interference, error during transmission are
inevitable, leading to corruption transmitted
bits.
• Longer the frame size and higher the
probability of single bit error ,lower is the
probability receiving a frame without error.
4. Types of error
• Single-bit error: only one bit get corrupted
Common in parallel transmission.
• Burst error
more than one bit get corrupted
Very common in serial transmission of data
Occurs when the duration of noise is larger than
the duration of one bit.
5. Error detection techniques
• Use of redundancy: additional bits are added
to facilitate detection and correction of error.
• Popular techniques:
Parity Check
Two Dimensional Parity Check
Checksum
Cyclic Redundancy Check
• CRC is one of the most powerful and commonly
used error detecting technique.
6. Cyclic redundancy check (CRC)
• Basic approach: a m-bit block of bit sequence,
the sender generate an n-bit sequence, known
as frame check sequence (FCS) , so that the
resulting frame, consisting of m+n bits, is
exactly divisible by same pre determined
number.
• The receiver divides the incoming frame by
that number and, if there is no remainder,
assumes there are no error.
7. Cyclic redundancy check (CRC)
Sender Receiver
m n
Data 000….0
Divisor
CRC
(n+1) bits
N-bits
Data CRC
m n
Data 000….0
Divisor
(n+1) bits
RemCiRnCder
N Y
Rejected zero Accept
10. Polynomials
• All the value can be expressed as polynomial of a
dummy variable X. P=11001 => X4+X3+1
• CRC process can be expressed as:
Xn
*M(X)/P(X)=Q(X)+R(X)/P(X)
• Commonly used divisor polynomial:
(1) CRC-16 = X16+X15+X2+1
(2) CRC-CCITT = X16+X12+X5+1
11. Digital circuit for polynomial division
• The CRC process can be vary easily
implemented in hardware using Linear
Feedback shift register (LFSR).
• The LFSR divides a message polynomial by
suitably chosen divisor polynomial; the
reminder constitutes the FCS.
16. printf("n-----------------------------------
-----");
crc();
printf("nCRC is : %s",cs);
for(e=a;e<a+N-1;e++)
t[e]=cs[e-a];
printf("n--------------------------------
--------");
printf("nFinal codeword is :
%s",t);
printf("n--------------------------------
--------");
printf("nTest error detection
0(yes) 1(no)? : ");
scanf("%d",&e);
if(e==0)
{
do{
printf("nEnter the position
where error is to be inserted : ");
scanf("%d",&e);
}while(e==0 || e>a+N-1);
t[e-1]=(t[e-1]=='0')?'1':'0';
printf("n------------------------------------
----");
printf("nErroneous data :
%sn",t);
}
crc();
for(e=0;(e<N-1) &&
(cs[e]!='1');e++);
if(e<N-1)
printf("nError
detectednn");
else
printf("nNo error
detectednn");
printf("n---------------------------
-------------n");
return 0;
}
17. Performance of CRC
• CRC can detect all single bit errors
• CRC can detect all double-bit error(three 1’s)
• CRC can detect any odd number of error (X+1)
• CRC can detect all burst error of less than the
degree of the polynomial.
• CRC detects most of the larger burst errors
with a high probability.
• For example CRC-12 detects 99.97% of error