3.1 Crc Module based design In our attempt to get a better understanding of the error detection capability of Cyclic Redundancy Check codes a programme was developed to check on various error scenarios. This was necessary because given a large message size it was virtually impossible to manually perform error detection.The implementation was done using the Java Programming Language . The implementation is based on the general CRC encoding algorithm using feed back shift registers as shown in the figure below. fig 2. Shift register computation of CRC 3.2 Code Description The program is an implementation of a CRC code.It is used for encoding and decoding of a 20byte Message vector M with the standard 32 CRC generator polynom g( x ) = x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x8+x^7+x^5+x^4+x^2+x+1. The main class of the programe(CrcEncoder_Decoder) is responsible for the encoding.A call to the method decode which calculates the syndrome.Within the decode method , a call to the checkError is made which returns a decision as to if the received code word is correct. Input Encoder_Decoder Decode CheckError Fig 3.Process flow of CrC implementation. The programme works by first encoding the received message to get a codeword U.This codeword is then decoded to get the syndrome associated with the received code vector Z which gives an idea as to if there is an error or not. Different Errors are then introduced in the received code vector and decoded again to get corresponding syndrome vectors. A more detailed description of the code can be found in the source code as comments in the Appendix.All output is written to a text f 3.3 Code Testing A 20byte input message (fixed) was used together with a standard 32 CRC generator polynom as stated in the previous 3.1 above. We thus have a (192,160) cyclic code implementation. MESSAGE VECTOR M = (10010010010010010010010010010010010010010010010010010010010010010010010 010010010010010010010010010010010010010010010010010010010010010010010010 01001001001001001) In testing our implementation, three different scenarios were considered and are described below; 3.3.1 No Error Scenario In this scenario the no errors are introduced and the code vector R received is the same as the code word U transmitted. The result of this test is shown below CASE 1 :NO BIT ERROR Received Codeword Z= (11000010001111011111101111111111100100100100100100100100100100100100100 100100100100100100100100100100100100100100100100100100100100100100100100 1001001001001001001001001001001001001001001001001) Syndrome = 00000000000000000000000000000000 MESSAGE RECEIVED WITHOUT ERROR 3.3.2 Single bit Error Scenario: In this scenario a single bit error in introduced in the received code vector at position 2 as shown below CASE 2 :SINGLE BIT ERROR Received Codeword Z= (11100010001111011111101111111111100100100100100100100100100100100100100 100100100100100100100100100100100100100100100100100100100100100100100100 1001001001001001001001001001001001001001001001001) Syndrome = 00100000000000000000000000000000 MESSAGE RECEIVED IN ERROR 3.3.3 Multiple Bit Errors CASE 3:MULTIBLE BIT ERRORS : Received Codeword Z= (11100010001111011111101111111111100100100100100100100100100100100100100 100100100100100100100100100100100100100100100100100100100100100100100100 1001001001001001001001001001001001001001001000001) (additional bit error at position 188 .i.e. 2 bit errors) Syndrome = 10111101110110111101011010110010 MESSAGE RECEIVED IN ERROR Received Codeword Z= (11100010001111011111101111111111100100100100100100100100100100100100100 100100100100100100100100100100100100100100100100100100100100100100100100 1001001001001001001001001001001001001001001010001) (additional bit error at position 187 .i.e. 3 bit errors) Syndrome = 01011101000111010111110110010111 MESSAGE RECEIVED IN ERROR Received Codeword Z= (11100010000111011111101111111111100100100100100100100100100100100100100 100100100100100100100100100100100100100100100100100100100100100100100100 1001001001001001001001001001001001001001001010001) (additional bit error at position 10.ie 4 bit errors) Syndrome = 01011101001111010111110110010111 MESSAGE RECEIVED IN ERROR Received Codeword Z= (11100010000011011111101111111111100100100100100100100100100100100100100 100100100100100100100100100100100100100100100100100100100100100100100100 1001001001001001001001001001001001001001001010001) (additional bit error at position 11 .i.e. 5 bit errors) Syndrome = 01011101001011010111110110010111 MESSAGE RECEIVED IN ERROR Received Codeword Z= (11100010000011011111111111111111100100100100100100100100100100100100100 100100100100100100100100100100100100100100100100100100100100100100100100 1001001001001001001001001001001001001001001010001) (additional bit error at position 21.ie 6 bit errors) Syndrome = 01011101001011010111100110010111 MESSAGE RECEIVED IN ERROR 3.3.4 Discussion of results In the results from our simulations presented above it can be seen that the error detecting capabilities of cyclic redundancy check code is an improvement on that of the single and rectangular block codes discussed in the initial parts of this report. It is worthy of mention however that a zero vector syndrome does not necessarily imply that the message received is without errors .This is because if a codeword is erroneously transformed into a new codeword, a zero syndrome would still be received. It is however assumed that the probability of a codeword been transformed into another codeword is negligible and can does be ignored. Appendix :A Source Code /*CRC code Implementation *Authors: * ALEX NYARKO * BENJAMIN BOATENG * ANTHONY KOFI TSETSE *Date:22-05-2004 *This program is an implementation of a CRC code.It is used for encoding and decoding of a 20byte *Message vector M with the standard 32 CRC generator polynom *g( x ) = x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x8+x^7+x^5+x^4+x^2+x+1. * *Input:Message Vector M ,generator polynom g ,length of CodeWord N and Length of message K. *Input parameters are fixed.This programme can be cudtomised for variable input. * *Output :Transmitted codeword U ,Received codeword Z and Syndrome. * */ import tio.*; import java.io.*; class CrcEncoder_Decoder{ public static void main(String[] args) throws java.io.IOException { PrintWriter outf= new PrintWriter(new FileWriter("outputresult.txt")); int n,k; boolean nkcheck=true; n=192; k=160;//20 bytes message frame int[] message=new int[k];//Array to store message bits int[] messgpad=new int[n];//Array for padded message bits to be fed into the system int[] codeword=new int[n];// Array to store code word int[] sro=new int[n-k];// Array for shift registers int[] srn=new int[n-k];// Array for new shift register contents as a result of updates int[] g=new int[n-k+1];//Array to store generator polynom g[0]=g[26]=g[23]=g[22]=g[16]=g[12]=g[11]=g[10]=g[8]=g[7]=g[5]=g[4]=g[2]=g [1]=g[n-k]=1;//generator polynom coefficients int out=0; for(int i=0;i<k;i=i+3){ message[i]=1;//generating message bits } for(int p=0;p<k;p++){//this loop padds the messages bit with trailing zero for input into the system messgpad[p]=message[k-p-1]; } //===== Code for encoding begins here int input; for(int q=0;q<n;q++){ //loop controlls input bits fed into system input=messgpad[q]; srn[0]=add(input,out); for (int s=1;s<n-k;s++){//loop computes new contents of shift registers srn[s]=add(sro[s-1],g[s]*out); } out=srn[n-k-1]; for(int t=0;t<n-k;t++){//Loop controlls updating of contents of old shift registers sro[t]=srn[t]; } } for(int j=0;j<n-k;j++){ codeword[j]=sro[j]; } for(int i=n-k;i<n;i++){ codeword[i]=message[i-(n-k)]; } outf.println("THIS IS THE OUTPUT OF THE CYCLIC BLOCK ENCODER/DECODER USING LINEAR FEEDBACK SHIFT REGISTERS "); outf.print("MESSAGE VECTOR M= ("); for(int i=0;i<k;i++){ outf.print(message[i]); } outf.print(")"); outf.println(""); outf.print("TRANSMITTED CODEWORD U = ("); for(int i=0;i<n;i++) outf.print(codeword[i]); outf.print(")"); outf.println(""); outf.println(""); outf.println("CASE 1 :NO BIT ERROR "); receivedCodePrint(codeword,outf); /* outf.print("Received Codeword Z= ("); for(int i=0;i<n;i++) outf.print(codeword[i]); outf.print(")"); outf.println("");*/ decode(n,k,g,codeword ,outf); outf.println("CASE 2 :SINGLE BIT ERROR "); codeword[2]=1;//Bit error introduced in codeword at position 2 of codeword receivedCodePrint(codeword,outf); decode(n,k,g,codeword,outf); outf.println("CASE 3:MULTIBLE BIT ERRORS : "); codeword[188]=0;//Additional error introduce at position 188 i.e 2 bit errors now receivedCodePrint(codeword,outf); decode(n,k,g,codeword,outf); codeword[187]=1;//Additional error introduce at position 187 i.e 3 bit errors now receivedCodePrint(codeword,outf); decode(n,k,g,codeword,outf); codeword[10]=0;//Additional error introduce at position 10 i.e 4 bit errors now receivedCodePrint(codeword,outf); decode(n,k,g,codeword,outf); codeword[11]=0;//Additional error introduce at position 11 i.e 5 bit errors now receivedCodePrint(codeword,outf); decode(n,k,g,codeword,outf); codeword[21]=1;//Additional error introduce at position i.e 6 bit errors now receivedCodePrint(codeword,outf); decode(n,k,g,codeword,outf); outf.close(); } //Decoder starts here public static void decode(int n,int k ,int g1[],int inputd[],PrintWriter Y){ int input; int out=0; int[] sro=new int[n-k];// Array for shift registers int[] srn=new int[n-k];// Array for new shift register contents as a result of updates for(int i=0;i<n-k;i++){ srn[i]=sro[i]=0; } for(int q=n-1;q>=0;q--){ //loop controlls input bits fed into system input=inputd[q]; srn[0]=add(input,out); for (int s=1;s<n-k;s++){//loop computes new contents of shift registers srn[s]=add(sro[s-1],g1[s]*out); } out=srn[n-k-1]; for(int t=0;t<n-k;t++){//Loop controlls updating of contents of old shift registers sro[t]=srn[t]; } } Y.print("Syndrome = "); for(int i=0;i<n-k;i++) Y.print(sro[i]); Y.println(""); if(checkError(sro)) Y.println("MESSAGE RECEIVED IN ERROR"); else Y.println("MESSAGE RECEIVED WITHOUT ERROR "); } //End of decoder public static int add(int x,int y){//method for exclusive OR(XOR) operation if(x==y) return 0; else return 1; } public static boolean checkError(int syndrome[]){//This method checks to see if there is a nonzero element in the syndrome vector boolean error=false; for(int i=0;i<syndrome.length;i++){ if (syndrome[i]==1){ error=true; break; } } return error; } public static void receivedCodePrint(int received[],PrintWriter X){ X.print("Received Codeword Z= ("); for(int i=0;i<192;i++) X.print(received[i]); X.print(")"); X.println(""); } }