## Bose–Chaudhuri–Hocquenghem (BCH) code: (15, 5, 7) and C Implementation Using the Octave GNU Tool

### 2. Introduction

• ##### Primitive element α=x=2 of the GF(16) has order 15. See the Table 2-1:

Table 2-1: GF(16): Representation of various degrees of a primitive α element

### 3. BCH Code (15,5,7) Using Polynomials

##### First the polynomials u(x) are prepared, which use information bits as coefficients. Next the polynomials c(x) = u(x)*g(x) are calculated. The coefficients of the polynomial c(x) will be the desired code words. See table 3-1:

Table 3-1: BCH Code (15,5,7) with Generator Polynomial g(x) = x^10 + x^8 + x^5 + x^4 + x^2 + x + 1

• ##### The received code word is correct if the corresponding polynomial is divisible by the generator polynomial g(x) without remainder. For example: position 22 of the code word is 0x4DC2 from Table 3-1 with the corresponding polynomial: x^14 + x^11+ x ^10 + x^8 + x^7 + x^6 + x is divisible by (18) without remainder. See the Figure 3-1:

Figure 3-1: 0x4DC2 is divided by g(x) without remainder

### 4. Generator Matrix G and Parity-Check Matrix H of the BCH (15,5,7)

##### Using the generator matrix (25), the code words BCH (15,5,7) are calculated. The results are shown in Table 4-1:

Table 4-1: BCH Code (15,5,7) with Generator Matrix G

##### The resulting polynomial must be divisible without remainder by a polynomial (x^15 – 1):

Figure 4-1: c(x)*h(x) is divided by (x^15 – 1) without remainder

### 6. Octave GNU file BCH_Code.m

##### The script generates and tests the BCH Code: (15,5,7)

% Hamming Distance between two Messages: Input and Pattern
% Input parameters:
% InMessage – input message
% PatternMessage – pattern message list
% MessageLength – message length in bits
% Output parameters:
% DistanceValue – Hamming distance
function DistanceValue = MessageCompare(InMessage, PatternMessage, MessageLength)

% Receiving the message
% Input parameters:
% InMessage – input message
% WordMessageList – message list
% MessageLength – message length in bits
% Output parameters:
% Distance – min Hamming distance
% MessageNmb – number of the message in the WordMessageList
% MessageValue – message value
function [Distance MessageNmb MessageValue] = ReceivingMessage(InMessage, WordMessageList, MessageLength)

% Hamming Distance In Message List
% Input parameters:
% MessageList – message list
% MessageLength – message length in bits
% Output parameters:
% MinHammingDistance – min Hamming distance
% MaxHammingDistance – max Hamming distance
function [MinHammingDistance MaxHammingDistance] = DistanceInMessageList(MessageList, MessageLength)

% Code Generator with Polynomial
% Input parameters:
% Polynomial – vector of the polynomial coefficients
% MessageLength – message length in bits <= 64
% Output parameters:
% BitMessageList – bit message array
% WordMessageList – word message array
function [BitMessageList WordMessageList] = CodeGeneratorPolynomial(Polynomial, MessageLength)

% Code Generator with Matrix
% Input parameters:
% GeneratorMatrix – generator matrix k x n
% MessageLength – message length in bits
% InfoLength – information bit number
% Output parameters:
% BitMessageList – bit message array
% WordMessageList – word message array
function [BitMessageList WordMessageList] = CodeGeneratorMatrix(GeneratorMatrix, MessageLength, InfoLength)

% Hex Integer Table to File
% Support C-Code
% Input parameters:
% ParameterVector – data array
% FileNameString – output file name
function HexIntegerParamVector2file(ParameterVector, FileNameString)

### 7. C Language BCH_Code.c/h

##### Supports the BCH Code: (15,5,7)

/*
Hamming Distance between code1 and code2
Input
uint16 code1
uint16 code2
Return
uint8 – Hamming Distance
*/
uint8 HammingDistance(uint16 code1, uint16 code2)

/*
Receiving the BCH message
Input
uint16 code – input message
receiving_message_t* ptr_result – pointer on the receiving result
Return
void
*/
void ReceivingMessage(uint16 code, receiving_message_t* ptr_result)