SlideShare a Scribd company logo
Cyclic Redundancy Check (CRC) 
implementation in Software 
using C 
Ajay Singh (2014JOP2558) 
Manoj Falaswal (2014JOP2489) 
Physics Department 
Indian Institute of Technology Delhi
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
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.
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.
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.
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.
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
Data: 1010 
Divisor: 1011 
1001 Quotient 
1 0 1 0 0 0 0 
1 0 1 1 
0 0 1 0 
0 0 0 0 
0 1 0 0 
0 0 0 0 
1 0 0 0 
1 0 1 1 
0 1 1 Reminder 
1 0 1 1 
Modulo-2 Arithmetic 
Data to be sent: 
1 0 1 0 0 1 1 
Data CRC
Received Data: 1010011 
Divisor: 1011 
1001 Quotient 
1 0 1 0 0 1 1 
1 0 1 1 
0 0 1 0 
0 0 0 0 
0 1 0 1 
0 0 0 0 
1 0 1 1 
1 0 1 1 
0 0 0 Reminder 
1 0 1 1 
Modulo-2 Arithmetic 
No error
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
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.
Implementation 
C2 C1 + C0 + 
clock 
Input 1 0 1 0 0 0 0 
Initial C2 C1 C0 C2(+)C0 C2(+)input input 
0 0 0 0 1 1 
Step 1 0 0 1 1 0 0 
Step 2 0 1 0 0 1 1 
Step 3 1 0 1 0 1 0 
Step 4 0 0 1 1 0 0 
Step 5 0 1 0 0 0 0 
Step 6 1 0 0 1 1 0 
Step 7 0 1 1 1 0 - 
Data to be sent:1010011
Code for CRC in C 
#include <stdio.h> 
#include <string.h> 
void main() 
{ 
int i,j,keylen,msglen; 
char input[100], 
key[30],temp[30],quot[100],rem[30],key1[30]; 
clrscr(); 
printf("Enter Data: "); 
gets(input); 
printf("Enter Key: "); 
gets(key); 
keylen=strlen(key); 
msglen=strlen(input); 
strcpy(key1,key); 
for(i=0;i<keylen-1;i++) 
{ 
input[msglen+i]='0'; 
} 
1
for(i=0;i<keylen;i++) 
temp[i]=input[i]; 
for(i=0;i<msglen;i++) 
{ 
quot[i]=temp[0]; 
if(quot[i]=='0') 
for(j=0;j<keylen;j++) 
key[j]='0'; 
else 
for(j=0;j<keylen;j++) 
key[j]=key1[j]; 
for(j=keylen-1;j>0;j--) 
{ 
if(temp[j]==key[j]) 
rem[j-1]='0'; 
else 
rem[j-1]='1'; 
} 
rem[keylen-1]=input[i+keylen]; 
strcpy(temp,rem); 
} 
strcpy(rem,temp); 
printf("nQuotient is "); 
for(i=0;i<msglen;i++) 
printf("%c",quot[i]); 
printf("nRemainder is "); 
for(i=0;i<keylen-1;i++) 
printf("%c",rem[i]); 
printf("nFinal data is: "); 
for(i=0;i<msglen;i++) 
printf("%c",input[i]); 
for(i=0;i<keylen-1;i++) 
printf("%c",rem[i]); 
}
#include<stdio.h> 
#include<string.h> 
#define N strlen(g) 
char t[28],cs[28],g[]="1011"; 
int a,e,c; 
void xor(){ 
for(c = 1;c < N; c++) 
cs[c] = (( cs[c] == g[c])?'0':'1'); 
} 
void crc(){ 
for(e=0;e<N;e++) 
cs[e]=t[e]; 
do{ 
if(cs[0]=='1') 
xor(); 
for(c=0;c<N-1;c++) 
cs[c]=cs[c+1]; 
cs[c]=t[e++]; 
} 
while(e<=a+N-1); 
} 
int main() 
{ 
printf("nEnter data : "); 
scanf("%s",t); 
printf("n------------------------------------- 
---"); 
printf("nGeneratng polynomial : 
%s",g); 
a=strlen(t); 
for(e=a;e<a+N-1;e++) 
t[e]='0'; 
printf("n------------------------------------- 
---"); 
printf("nModified data is : %s",t); 
2
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; 
}
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
Reference Links: 
http://en.wikipedia.org/wiki/Computation_of_cyclic_redundancy_checks 
http://www.barrgroup.com/Embedded-Systems/How-To/CRC-Calculation- 
C-Code 
http://stackoverflow.com/questions/18974220/how-to-implement-crc-using- 
c-language 
http://www.ccodechamp.com/c-program-to-implement-cyclic-redundancy- 
check-crc/ 
http://getprogramcode.com/2013/03/c-program-to-implement-crc-cyclic-redundancy- 
code/ 
http://www.barrgroup.com/Embedded-Systems/How-To/CRC-Calculation- 
C-Code
!

More Related Content

What's hot (20)

Turbo codes
Turbo codesTurbo codes
Turbo codes
 
Wireless networking
Wireless networkingWireless networking
Wireless networking
 
Convolutional Codes And Their Decoding
Convolutional Codes And Their DecodingConvolutional Codes And Their Decoding
Convolutional Codes And Their Decoding
 
DLT645 protocol english version
DLT645 protocol english versionDLT645 protocol english version
DLT645 protocol english version
 
Ec8791 lpc2148 uart
Ec8791 lpc2148 uartEc8791 lpc2148 uart
Ec8791 lpc2148 uart
 
Earlang ejercicios
Earlang ejerciciosEarlang ejercicios
Earlang ejercicios
 
Channel coding
Channel coding  Channel coding
Channel coding
 
Turbo codes.ppt
Turbo codes.pptTurbo codes.ppt
Turbo codes.ppt
 
DIGITAL COMMUNICATION: ENCODING AND DECODING OF CYCLIC CODE
DIGITAL COMMUNICATION: ENCODING AND DECODING OF CYCLIC CODE DIGITAL COMMUNICATION: ENCODING AND DECODING OF CYCLIC CODE
DIGITAL COMMUNICATION: ENCODING AND DECODING OF CYCLIC CODE
 
Cyclic Redundancy Check
Cyclic Redundancy CheckCyclic Redundancy Check
Cyclic Redundancy Check
 
Linear block code
Linear block codeLinear block code
Linear block code
 
Mobile Computing I-Unit Notes
Mobile Computing I-Unit NotesMobile Computing I-Unit Notes
Mobile Computing I-Unit Notes
 
Multiple access techniques for wireless communications
Multiple access techniques for wireless communicationsMultiple access techniques for wireless communications
Multiple access techniques for wireless communications
 
Linear block coding
Linear block codingLinear block coding
Linear block coding
 
LDPC Encoding
LDPC EncodingLDPC Encoding
LDPC Encoding
 
Data Link Layer
Data Link LayerData Link Layer
Data Link Layer
 
GSM channels
GSM channelsGSM channels
GSM channels
 
ELEMENTS OF CELLULAR RADIO SYSTEM DESIGN
ELEMENTS OF CELLULAR RADIO SYSTEM DESIGNELEMENTS OF CELLULAR RADIO SYSTEM DESIGN
ELEMENTS OF CELLULAR RADIO SYSTEM DESIGN
 
Information theory
Information theoryInformation theory
Information theory
 
Hamming code system
Hamming code systemHamming code system
Hamming code system
 

Viewers also liked

Fire and Gas Detection System_ - Simplified_Revised
Fire and Gas Detection System_ - Simplified_RevisedFire and Gas Detection System_ - Simplified_Revised
Fire and Gas Detection System_ - Simplified_RevisedGan Chun Chet
 
LPG Gas detector
LPG Gas detectorLPG Gas detector
LPG Gas detectorajay singh
 
Wireless gas leakage detector with device control
Wireless gas leakage detector  with device controlWireless gas leakage detector  with device control
Wireless gas leakage detector with device controlReshma Gowri Chandran
 
Gas sensor Alarm
Gas sensor AlarmGas sensor Alarm
Gas sensor AlarmUdit Jain
 
Project report of Cell phone detector circuit
Project report of Cell phone detector circuitProject report of Cell phone detector circuit
Project report of Cell phone detector circuitMoin Aman
 
Project presentation on wireless lpg leakage detector
Project presentation on wireless lpg leakage detectorProject presentation on wireless lpg leakage detector
Project presentation on wireless lpg leakage detectorPETER ASIGRI
 
fire detection and alarm system
fire detection and alarm systemfire detection and alarm system
fire detection and alarm systemsingh1515
 
Wireless robot ppt
Wireless robot pptWireless robot ppt
Wireless robot pptVarun B P
 
Gas Leakage Detector using Arduino with SMS Alert - Engineering Project
Gas Leakage Detector using Arduino with SMS Alert - Engineering ProjectGas Leakage Detector using Arduino with SMS Alert - Engineering Project
Gas Leakage Detector using Arduino with SMS Alert - Engineering ProjectCircuitsToday
 

Viewers also liked (12)

Fire and Gas Detection System_ - Simplified_Revised
Fire and Gas Detection System_ - Simplified_RevisedFire and Gas Detection System_ - Simplified_Revised
Fire and Gas Detection System_ - Simplified_Revised
 
LPG Gas detector
LPG Gas detectorLPG Gas detector
LPG Gas detector
 
Wireless gas leakage detector with device control
Wireless gas leakage detector  with device controlWireless gas leakage detector  with device control
Wireless gas leakage detector with device control
 
GSM BASED GAS LEAKAGE DETECTION SYSTEM
GSM BASED GAS LEAKAGE DETECTION SYSTEMGSM BASED GAS LEAKAGE DETECTION SYSTEM
GSM BASED GAS LEAKAGE DETECTION SYSTEM
 
Gas sensor Alarm
Gas sensor AlarmGas sensor Alarm
Gas sensor Alarm
 
Vehicle security system final report
Vehicle security system final reportVehicle security system final report
Vehicle security system final report
 
Project report of Cell phone detector circuit
Project report of Cell phone detector circuitProject report of Cell phone detector circuit
Project report of Cell phone detector circuit
 
Project presentation on wireless lpg leakage detector
Project presentation on wireless lpg leakage detectorProject presentation on wireless lpg leakage detector
Project presentation on wireless lpg leakage detector
 
fire detection and alarm system
fire detection and alarm systemfire detection and alarm system
fire detection and alarm system
 
Wireless robot ppt
Wireless robot pptWireless robot ppt
Wireless robot ppt
 
Ppt
PptPpt
Ppt
 
Gas Leakage Detector using Arduino with SMS Alert - Engineering Project
Gas Leakage Detector using Arduino with SMS Alert - Engineering ProjectGas Leakage Detector using Arduino with SMS Alert - Engineering Project
Gas Leakage Detector using Arduino with SMS Alert - Engineering Project
 

Similar to CRC implementation

13-DataLink_02.ppt
13-DataLink_02.ppt13-DataLink_02.ppt
13-DataLink_02.pptWinterSnow16
 
Skr+3200+chapter+3+(kweh)
Skr+3200+chapter+3+(kweh)Skr+3200+chapter+3+(kweh)
Skr+3200+chapter+3+(kweh)Ammar Shafiq
 
Error Detection and correction concepts in Data communication and networks
Error Detection and correction concepts in Data communication and networksError Detection and correction concepts in Data communication and networks
Error Detection and correction concepts in Data communication and networksNt Arvind
 
GROUP03_AMAK:ERROR DETECTION AND CORRECTION PPT
GROUP03_AMAK:ERROR DETECTION AND CORRECTION PPTGROUP03_AMAK:ERROR DETECTION AND CORRECTION PPT
GROUP03_AMAK:ERROR DETECTION AND CORRECTION PPTKrishbathija
 
CRC Error coding technique
CRC Error coding techniqueCRC Error coding technique
CRC Error coding techniqueMantra VLSI
 
Error detection.
Error detection.Error detection.
Error detection.Wasim Akbar
 
05 directnets errors
05 directnets errors05 directnets errors
05 directnets errorsjyang1983
 
Error detection and correction unit-05
Error detection and correction unit-05Error detection and correction unit-05
Error detection and correction unit-05shrinivasgnaik
 
Performance Evaluation & Design Methodologies for Automated 32 Bit CRC Checki...
Performance Evaluation & Design Methodologies for Automated 32 Bit CRC Checki...Performance Evaluation & Design Methodologies for Automated 32 Bit CRC Checki...
Performance Evaluation & Design Methodologies for Automated 32 Bit CRC Checki...VIT-AP University
 
第四次课程 Chap8
第四次课程 Chap8第四次课程 Chap8
第四次课程 Chap8Emma2013
 
1 Unit-1 DEC B.Tech ECE III Sem Syllabus & Intro.pptx
1 Unit-1 DEC B.Tech ECE III Sem Syllabus & Intro.pptx1 Unit-1 DEC B.Tech ECE III Sem Syllabus & Intro.pptx
1 Unit-1 DEC B.Tech ECE III Sem Syllabus & Intro.pptxSatish Chandra
 
Lecture 4 from virtual university of pakistan
Lecture 4 from virtual university of pakistanLecture 4 from virtual university of pakistan
Lecture 4 from virtual university of pakistanSaba Hanif
 

Similar to CRC implementation (20)

BCH Codes
BCH CodesBCH Codes
BCH Codes
 
B0210714
B0210714B0210714
B0210714
 
13-DataLink_02.ppt
13-DataLink_02.ppt13-DataLink_02.ppt
13-DataLink_02.ppt
 
Data links
Data links Data links
Data links
 
lect5.ppt
lect5.pptlect5.ppt
lect5.ppt
 
5. Error Coding
5. Error Coding5. Error Coding
5. Error Coding
 
Skr+3200+chapter+3+(kweh)
Skr+3200+chapter+3+(kweh)Skr+3200+chapter+3+(kweh)
Skr+3200+chapter+3+(kweh)
 
Error Detection and correction concepts in Data communication and networks
Error Detection and correction concepts in Data communication and networksError Detection and correction concepts in Data communication and networks
Error Detection and correction concepts in Data communication and networks
 
GROUP03_AMAK:ERROR DETECTION AND CORRECTION PPT
GROUP03_AMAK:ERROR DETECTION AND CORRECTION PPTGROUP03_AMAK:ERROR DETECTION AND CORRECTION PPT
GROUP03_AMAK:ERROR DETECTION AND CORRECTION PPT
 
CRC Error coding technique
CRC Error coding techniqueCRC Error coding technique
CRC Error coding technique
 
Error detection.
Error detection.Error detection.
Error detection.
 
Lecture 21
Lecture 21Lecture 21
Lecture 21
 
05 directnets errors
05 directnets errors05 directnets errors
05 directnets errors
 
CRC JAVA CODE
CRC JAVA CODECRC JAVA CODE
CRC JAVA CODE
 
Chapter 10
Chapter 10Chapter 10
Chapter 10
 
Error detection and correction unit-05
Error detection and correction unit-05Error detection and correction unit-05
Error detection and correction unit-05
 
Performance Evaluation & Design Methodologies for Automated 32 Bit CRC Checki...
Performance Evaluation & Design Methodologies for Automated 32 Bit CRC Checki...Performance Evaluation & Design Methodologies for Automated 32 Bit CRC Checki...
Performance Evaluation & Design Methodologies for Automated 32 Bit CRC Checki...
 
第四次课程 Chap8
第四次课程 Chap8第四次课程 Chap8
第四次课程 Chap8
 
1 Unit-1 DEC B.Tech ECE III Sem Syllabus & Intro.pptx
1 Unit-1 DEC B.Tech ECE III Sem Syllabus & Intro.pptx1 Unit-1 DEC B.Tech ECE III Sem Syllabus & Intro.pptx
1 Unit-1 DEC B.Tech ECE III Sem Syllabus & Intro.pptx
 
Lecture 4 from virtual university of pakistan
Lecture 4 from virtual university of pakistanLecture 4 from virtual university of pakistan
Lecture 4 from virtual university of pakistan
 

More from ajay singh

After Highschool
After HighschoolAfter Highschool
After Highschoolajay singh
 
Bragg solitons
Bragg solitonsBragg solitons
Bragg solitonsajay singh
 
Design and development of solar pumped Nd:YAG Laser
Design and development of solar pumped Nd:YAG LaserDesign and development of solar pumped Nd:YAG Laser
Design and development of solar pumped Nd:YAG Laserajay singh
 
Dalits in india
Dalits in indiaDalits in india
Dalits in indiaajay singh
 
Solar pumped Laser
Solar pumped LaserSolar pumped Laser
Solar pumped Laserajay singh
 
Casteism is no more
Casteism is no moreCasteism is no more
Casteism is no moreajay singh
 
Study of Raman Scattering in Carbon nanotubes
Study of Raman Scattering in Carbon nanotubesStudy of Raman Scattering in Carbon nanotubes
Study of Raman Scattering in Carbon nanotubesajay singh
 
Raman Study of Carbon Nanotube
Raman Study of Carbon NanotubeRaman Study of Carbon Nanotube
Raman Study of Carbon Nanotubeajay singh
 
PRBS generation
PRBS generationPRBS generation
PRBS generationajay singh
 
Pseudo Random Bit Sequence Generator
Pseudo Random Bit Sequence Generator Pseudo Random Bit Sequence Generator
Pseudo Random Bit Sequence Generator ajay singh
 
Photonic crystal fibers (PCF)
Photonic crystal fibers (PCF)Photonic crystal fibers (PCF)
Photonic crystal fibers (PCF)ajay singh
 
Guided modes of Optical Step Index Fiber
Guided modes of Optical Step Index FiberGuided modes of Optical Step Index Fiber
Guided modes of Optical Step Index Fiberajay singh
 
Guided Modes Of Planer waveguide
Guided Modes Of Planer waveguideGuided Modes Of Planer waveguide
Guided Modes Of Planer waveguideajay singh
 
Liquid crystal spatial light modulator (LCSLMs)
Liquid crystal spatial light modulator  (LCSLMs)Liquid crystal spatial light modulator  (LCSLMs)
Liquid crystal spatial light modulator (LCSLMs)ajay singh
 
Hydrogen storage
Hydrogen storage Hydrogen storage
Hydrogen storage ajay singh
 
Argon ion lasers
Argon ion lasersArgon ion lasers
Argon ion lasersajay singh
 
Laser eye surgery
Laser eye surgeryLaser eye surgery
Laser eye surgeryajay singh
 
Application of Laser in Material Processing and Eye Surgery
Application of Laser in Material Processing and Eye SurgeryApplication of Laser in Material Processing and Eye Surgery
Application of Laser in Material Processing and Eye Surgeryajay singh
 

More from ajay singh (20)

After Highschool
After HighschoolAfter Highschool
After Highschool
 
Solar lasers
Solar lasersSolar lasers
Solar lasers
 
Bragg solitons
Bragg solitonsBragg solitons
Bragg solitons
 
Design and development of solar pumped Nd:YAG Laser
Design and development of solar pumped Nd:YAG LaserDesign and development of solar pumped Nd:YAG Laser
Design and development of solar pumped Nd:YAG Laser
 
Solar Laser
Solar LaserSolar Laser
Solar Laser
 
Dalits in india
Dalits in indiaDalits in india
Dalits in india
 
Solar pumped Laser
Solar pumped LaserSolar pumped Laser
Solar pumped Laser
 
Casteism is no more
Casteism is no moreCasteism is no more
Casteism is no more
 
Study of Raman Scattering in Carbon nanotubes
Study of Raman Scattering in Carbon nanotubesStudy of Raman Scattering in Carbon nanotubes
Study of Raman Scattering in Carbon nanotubes
 
Raman Study of Carbon Nanotube
Raman Study of Carbon NanotubeRaman Study of Carbon Nanotube
Raman Study of Carbon Nanotube
 
PRBS generation
PRBS generationPRBS generation
PRBS generation
 
Pseudo Random Bit Sequence Generator
Pseudo Random Bit Sequence Generator Pseudo Random Bit Sequence Generator
Pseudo Random Bit Sequence Generator
 
Photonic crystal fibers (PCF)
Photonic crystal fibers (PCF)Photonic crystal fibers (PCF)
Photonic crystal fibers (PCF)
 
Guided modes of Optical Step Index Fiber
Guided modes of Optical Step Index FiberGuided modes of Optical Step Index Fiber
Guided modes of Optical Step Index Fiber
 
Guided Modes Of Planer waveguide
Guided Modes Of Planer waveguideGuided Modes Of Planer waveguide
Guided Modes Of Planer waveguide
 
Liquid crystal spatial light modulator (LCSLMs)
Liquid crystal spatial light modulator  (LCSLMs)Liquid crystal spatial light modulator  (LCSLMs)
Liquid crystal spatial light modulator (LCSLMs)
 
Hydrogen storage
Hydrogen storage Hydrogen storage
Hydrogen storage
 
Argon ion lasers
Argon ion lasersArgon ion lasers
Argon ion lasers
 
Laser eye surgery
Laser eye surgeryLaser eye surgery
Laser eye surgery
 
Application of Laser in Material Processing and Eye Surgery
Application of Laser in Material Processing and Eye SurgeryApplication of Laser in Material Processing and Eye Surgery
Application of Laser in Material Processing and Eye Surgery
 

Recently uploaded

ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdfAhmedHussein950959
 
School management system project report.pdf
School management system project report.pdfSchool management system project report.pdf
School management system project report.pdfKamal Acharya
 
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data StreamKIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data StreamDr. Radhey Shyam
 
retail automation billing system ppt.pptx
retail automation billing system ppt.pptxretail automation billing system ppt.pptx
retail automation billing system ppt.pptxfaamieahmd
 
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...Amil baba
 
Construction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptxConstruction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptxwendy cai
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.PrashantGoswami42
 
A case study of cinema management system project report..pdf
A case study of cinema management system project report..pdfA case study of cinema management system project report..pdf
A case study of cinema management system project report..pdfKamal Acharya
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Aryaabh.arya
 
Fruit shop management system project report.pdf
Fruit shop management system project report.pdfFruit shop management system project report.pdf
Fruit shop management system project report.pdfKamal Acharya
 
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and VisualizationKIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and VisualizationDr. Radhey Shyam
 
İTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering WorkshopİTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering WorkshopEmre Günaydın
 
shape functions of 1D and 2 D rectangular elements.pptx
shape functions of 1D and 2 D rectangular elements.pptxshape functions of 1D and 2 D rectangular elements.pptx
shape functions of 1D and 2 D rectangular elements.pptxVishalDeshpande27
 
AI for workflow automation Use cases applications benefits and development.pdf
AI for workflow automation Use cases applications benefits and development.pdfAI for workflow automation Use cases applications benefits and development.pdf
AI for workflow automation Use cases applications benefits and development.pdfmahaffeycheryld
 
Peek implant persentation - Copy (1).pdf
Peek implant persentation - Copy (1).pdfPeek implant persentation - Copy (1).pdf
Peek implant persentation - Copy (1).pdfAyahmorsy
 
Arduino based vehicle speed tracker project
Arduino based vehicle speed tracker projectArduino based vehicle speed tracker project
Arduino based vehicle speed tracker projectRased Khan
 
Explosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdfExplosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdf884710SadaqatAli
 
RS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
RS Khurmi Machine Design Clutch and Brake Exercise Numerical SolutionsRS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
RS Khurmi Machine Design Clutch and Brake Exercise Numerical SolutionsAtif Razi
 
ONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdf
ONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdfONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdf
ONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Furniture showroom management system project.pdf
Furniture showroom management system project.pdfFurniture showroom management system project.pdf
Furniture showroom management system project.pdfKamal Acharya
 

Recently uploaded (20)

ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
School management system project report.pdf
School management system project report.pdfSchool management system project report.pdf
School management system project report.pdf
 
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data StreamKIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
 
retail automation billing system ppt.pptx
retail automation billing system ppt.pptxretail automation billing system ppt.pptx
retail automation billing system ppt.pptx
 
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
 
Construction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptxConstruction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptx
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
A case study of cinema management system project report..pdf
A case study of cinema management system project report..pdfA case study of cinema management system project report..pdf
A case study of cinema management system project report..pdf
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
Fruit shop management system project report.pdf
Fruit shop management system project report.pdfFruit shop management system project report.pdf
Fruit shop management system project report.pdf
 
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and VisualizationKIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
 
İTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering WorkshopİTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering Workshop
 
shape functions of 1D and 2 D rectangular elements.pptx
shape functions of 1D and 2 D rectangular elements.pptxshape functions of 1D and 2 D rectangular elements.pptx
shape functions of 1D and 2 D rectangular elements.pptx
 
AI for workflow automation Use cases applications benefits and development.pdf
AI for workflow automation Use cases applications benefits and development.pdfAI for workflow automation Use cases applications benefits and development.pdf
AI for workflow automation Use cases applications benefits and development.pdf
 
Peek implant persentation - Copy (1).pdf
Peek implant persentation - Copy (1).pdfPeek implant persentation - Copy (1).pdf
Peek implant persentation - Copy (1).pdf
 
Arduino based vehicle speed tracker project
Arduino based vehicle speed tracker projectArduino based vehicle speed tracker project
Arduino based vehicle speed tracker project
 
Explosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdfExplosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdf
 
RS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
RS Khurmi Machine Design Clutch and Brake Exercise Numerical SolutionsRS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
RS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
 
ONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdf
ONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdfONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdf
ONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdf
 
Furniture showroom management system project.pdf
Furniture showroom management system project.pdfFurniture showroom management system project.pdf
Furniture showroom management system project.pdf
 

CRC implementation

  • 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
  • 8. Data: 1010 Divisor: 1011 1001 Quotient 1 0 1 0 0 0 0 1 0 1 1 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 1 1 0 1 1 Reminder 1 0 1 1 Modulo-2 Arithmetic Data to be sent: 1 0 1 0 0 1 1 Data CRC
  • 9. Received Data: 1010011 Divisor: 1011 1001 Quotient 1 0 1 0 0 1 1 1 0 1 1 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 1 0 1 1 1 0 1 1 0 0 0 Reminder 1 0 1 1 Modulo-2 Arithmetic No error
  • 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.
  • 12. Implementation C2 C1 + C0 + clock Input 1 0 1 0 0 0 0 Initial C2 C1 C0 C2(+)C0 C2(+)input input 0 0 0 0 1 1 Step 1 0 0 1 1 0 0 Step 2 0 1 0 0 1 1 Step 3 1 0 1 0 1 0 Step 4 0 0 1 1 0 0 Step 5 0 1 0 0 0 0 Step 6 1 0 0 1 1 0 Step 7 0 1 1 1 0 - Data to be sent:1010011
  • 13. Code for CRC in C #include <stdio.h> #include <string.h> void main() { int i,j,keylen,msglen; char input[100], key[30],temp[30],quot[100],rem[30],key1[30]; clrscr(); printf("Enter Data: "); gets(input); printf("Enter Key: "); gets(key); keylen=strlen(key); msglen=strlen(input); strcpy(key1,key); for(i=0;i<keylen-1;i++) { input[msglen+i]='0'; } 1
  • 14. for(i=0;i<keylen;i++) temp[i]=input[i]; for(i=0;i<msglen;i++) { quot[i]=temp[0]; if(quot[i]=='0') for(j=0;j<keylen;j++) key[j]='0'; else for(j=0;j<keylen;j++) key[j]=key1[j]; for(j=keylen-1;j>0;j--) { if(temp[j]==key[j]) rem[j-1]='0'; else rem[j-1]='1'; } rem[keylen-1]=input[i+keylen]; strcpy(temp,rem); } strcpy(rem,temp); printf("nQuotient is "); for(i=0;i<msglen;i++) printf("%c",quot[i]); printf("nRemainder is "); for(i=0;i<keylen-1;i++) printf("%c",rem[i]); printf("nFinal data is: "); for(i=0;i<msglen;i++) printf("%c",input[i]); for(i=0;i<keylen-1;i++) printf("%c",rem[i]); }
  • 15. #include<stdio.h> #include<string.h> #define N strlen(g) char t[28],cs[28],g[]="1011"; int a,e,c; void xor(){ for(c = 1;c < N; c++) cs[c] = (( cs[c] == g[c])?'0':'1'); } void crc(){ for(e=0;e<N;e++) cs[e]=t[e]; do{ if(cs[0]=='1') xor(); for(c=0;c<N-1;c++) cs[c]=cs[c+1]; cs[c]=t[e++]; } while(e<=a+N-1); } int main() { printf("nEnter data : "); scanf("%s",t); printf("n------------------------------------- ---"); printf("nGeneratng polynomial : %s",g); a=strlen(t); for(e=a;e<a+N-1;e++) t[e]='0'; printf("n------------------------------------- ---"); printf("nModified data is : %s",t); 2
  • 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
  • 18. Reference Links: http://en.wikipedia.org/wiki/Computation_of_cyclic_redundancy_checks http://www.barrgroup.com/Embedded-Systems/How-To/CRC-Calculation- C-Code http://stackoverflow.com/questions/18974220/how-to-implement-crc-using- c-language http://www.ccodechamp.com/c-program-to-implement-cyclic-redundancy- check-crc/ http://getprogramcode.com/2013/03/c-program-to-implement-crc-cyclic-redundancy- code/ http://www.barrgroup.com/Embedded-Systems/How-To/CRC-Calculation- C-Code
  • 19.
  • 20. !