ECC Report

  • Upload
    brk318

  • View
    234

  • Download
    0

Embed Size (px)

Citation preview

  • 8/8/2019 ECC Report

    1/30

    Implementation of the Berlekamp-Massey algorithm and Petersons

    algorithm in C Programming Language

    Lei Zhou, 995349591ECE Dept., University of Toronto

    Email: [email protected]

    Abstract

    BCH code is a family of cyclic codes. The good algebraic structure facilitates the design and

    implementation of the BCH code. Roughly speaking, there are about 3 decoding methods for the

    BCH code, Berlekamp-Massey algorithm, Petersons algorithm and Euclidean algorithm, among

    which Berlekamp-Massey is the most efficient one and is widely used in simulations and software

    applications. Petersons algorithm is simple in theory but the implementation complexity is high,

    which limits the application of this algorithm when the error correction capability grows higher. In

    this project, the Belerkamp-Massey algorithm and the Petersons algorithm are implemented. (31,

    11, 5) and (15, 5, 3) BCH codes are constructed and the performance of decoding these two codes

    shows the correctness the two decoding algorithms.

    1 System sketch

    As depicted in Fig.1, the communication system consists 5 parts: channel encoder/decoder, mod-

    ulator/demodulator and the communication channel. Binary source information bk are generated

    by the source and then are encoded in the channel encoder (BCH encoder in this study). After this

    encoding process, coded bits ck are mapped into frequency band waveforms in a certain manner

    according to the modulation scheme. Frequency band waveform s(t) goes through the commu-

    nication channel and the corrupted waveform r(t) coming out of the channel is demodulated at

    demodulator. Finally, corrupted codewords ck from the demodulator are decoded at the channel

    decoder and now we get the estimated binary source bk.

    In this project, BCH encoder is implemented in the systematic manner and the Berlekamp-

    Massey algorithm and the Petersons algorithm are chosen as decoding algorithms. BPSK modu-

    lation scheme and minimum distance receiver for the modulation and demodulation respectively.

    Finally, the AWGN channel is considered as the communication channel.

    1

  • 8/8/2019 ECC Report

    2/30

    Figure 1: Sketch of the communication system

    2 AWGN Channel and Binary Symmetric Channel

    In order to verify the BCH decoding algorithm, a memoryless Additive White Gaussian Noise(AWGN) channel is considered:

    y = x + n (1)

    Where x R is the input signal, n is the additive Gaussian noise with distribution N(0, 1) and yis the received signal. The signal to noise ratio SNR is defined as:

    SNR =E{|x|2}E{|n|2} (2)

    The conditional distribution of y given x can be written as:

    p(y|x) = 12

    exp{ (y x)22

    } (3)

    Recall that since BPSK modulation is used, the value of x is either +

    SNR or SNR. In thiscase, the bit error probability of the maximum likelihood receiver is well known as

    Pb = Q(

    SNR) (4)

    Where the Q function is defined as

    Q(x) =12

    x

    exp( t2

    2)dt (5)

    Therefore, we can have the equivalent BSC of AWGN channel, which is depicted in Fig.2:

    3 Modulation and Demodulation

    Coming out of the encoder, coded bits are piped into the modulator and are mapped onto some

    constellation points. After that, they are modulated by the carrier with frequency fc, and then,

    2

  • 8/8/2019 ECC Report

    3/30

    Figure 2: The equivalence of AWGN channel and binary symmetric channel

    they are sent out at the antenna. For the reason of the computational complicity of simulation,

    only baseband signals are considered here. In this study, the simplest modulation scheme BPSK is

    used. In BPSK, binary information bits are mapped to constelation points in this manner:

    0 +

    SNR

    1

    SNR

    After receiving the baseband signal from the AWGN channel, the best decision rule (in maximum

    likelihood sense, also known as the minimum distance receiver) is:

    y > 0 x = 0y < 0 x = 1

    where y is the received signal and x represents the binary bit sent to the channel. We just omit

    the case of y = 0 since the probability of y = 0 is zeros.

    4 BCH encoder and decoder

    In a communication system, information bits are generated from a source and then are pushed into

    to a source encoder to reduce the redundancy in the source bits. Then the coded bits are sent to the

    channel encoder, which will add some redundancy in a certain manner to overcome the unreliable

    transmission through the channel. Usually, channels unreliability is caused by the fading channel

    and the receiver noise and the interference from other signals.

    Shannons information theory told us that random coding with infinite length can achieve the

    information capacity. However, this has no practical implications since the encoding and decoding

    complexity are too high to be implemented in practice. To make the encoder and the decoder as

    simple as possible, linear finite length codes with well algebraic structure are investigated after

    3

  • 8/8/2019 ECC Report

    4/30

    Shannon. Among these linear codes, BCH code is one promising family of cyclic codes, which is

    define as:

    A BCH code with minimum distance dmin > 2t + 1 is a cyclic code whose generator polynomial

    g(x) has 2t consecutive roots: b, b+1, , b+2t1. When b = 1, its called the narrow senseBCH code.

    4.1 Encoder

    There are two methods to generate the BCH codewords, systematic manner and nonsystematic

    manner. In the nonsystematic manner, the encoding procedure is quite simple.

    C = W G (6)

    where W is the k 1 information bits and C is the n 1 codeword and the matrix G can begenerated by g(x)

    G =

    g(x)

    xg(x)...

    xnr1g(x)

    (7)

    which is a (n r) n dimensional matrix.The systematic encoder for BCH codes looks a bit more complex. Suppose u(x) is the informa-

    tion bits with degree less than k, then form m(x) = xru(x) with degree less than n. We can write

    m(x) in the following form:

    m(x) = q(x)g(x) + r(x) (8)

    where either deg r(x) < deg g(x) or r(x) 0. ( means equivalence in component wise). Sincem(x) r(x) = q(x)g(x) is a multiple of the generator polynomial g(x), its a codeword. Finally,the information bits u(x) is encoded systematically as m(x) r(x), which can be seen intuitivelyin Fig.3

    The two encoding schemes are actually equivalent to each other. However, to simplify the BCH

    decoder, systematic encoder will be used in this project.

    In this study, two BCH codes (31, 11, 5) code and (15, 5, 3) code are constructed and tested.

    The (31,11,5) encodes on of 211 messages into a length n codeword and can correct 5 bit errors at

    most. The generator polynomial of the (31, 15, 5) BCH code is

    g(x) = x20 + x18 + x17 + x13 + x10 + x9 + x7 + x6 + x4 + x2 + 1 (9)

    The corresponding 32 elements of GF(25) are listed in table 1.

    4

  • 8/8/2019 ECC Report

    5/30

    Figure 3: Systematic encoding procedure of cyclic codes

    Table 1: Table of elements of GF(25)

    power 0 1 2 3 4 5 6 7 8

    vector 00000 00001 00010 00100 01000 10000 00101 01010 10100 01101

    9 10 11 12 13 14 15 16 17 18

    11010 10001 00111 01110 11100 11101 11111 11011 10011 00011

    19 20 21 22 23 24 25 26 27 28

    00110 01100 11000 10101 01111 11110 11001 10111 01011 10110

    29 30

    01001 10010

    The (15,5,3) BCH code encodes one of 2

    5

    different source messages into a length n codewordcan can correct at most 3 bit errors. The generator polynomial is

    g(x) = x10 + x8 + x5 + x4 + x2 + x1 + 1 (10)

    The elements of GF(24) based on the primitive polynomial p(x) = x4 + x + 1 can be found in

    table 2.

    Table 2: Table of elements of GF(24)

    power 0 1 2

    3

    4

    5

    6

    7

    8

    vector 0000 0001 0010 0100 1000 0011 0110 1100 1011 0101

    9 10 11 12 13 14

    1010 0111 1110 1111 1101 1001

    5

  • 8/8/2019 ECC Report

    6/30

    4.2 Decoder

    4.2.1 Notation and Definitions

    In this subsection, the decoding method for binary primitive narrow sense BCH codes will be

    introduced. By the definition, for narrow sense BCH codes, , 2, , 2t are the roots of the

    generator polynomial g(x). Therefore, for any codeword c(x) in cyclic code C generated by g(x),

    we have

    c() = c(2) = = c(2t) = 0 (11)

    Suppose that a codeword c(x) is transmitted and a corrupted version r(x) is received, then

    r(x) = c(x) + e(x) (12)

    where e(x) is the error pattern polynomial.

    Assume that l errors happen and denote the error locations as i0, i1, , il1. Then we get thesyndromes of the error pattern as

    S1 = r() = e() = i0 + + il1

    S2 = r(2) = e(2) = (i0)2 + + (il1)2

    ...

    S2t = r(2t) = e(2t) = (i0)2t + + (il1)2t (13)

    Let the error locator polynomial be defined as

    (z) = l

    1j=0(1 ij z) = 1 + z + 2z2 + + lzl (14)

    From the above equation, its easy to see that each li is a root of (z). Therefore, if the

    error locator polynomial can be found by syndromes in (13), we can simply test each element i in

    GF(2m) to see if its the inverse is a root of (z), which is call the Chien search algorithm. After

    that, flip each bit at the error locations. As depicted in Fig.4, BCH decoding is usually carried on

    in the following five steps:

    1. Calculate the 2t syndromes.

    2. Find the error locator polynomial (x).

    3. Find the inverses of the zeros of (x), then the l error locations {i0, i1, , il1} are known.4. Find the values of the errors. (No need for binary BCH codes.)

    5. Using Forney algorithm to correct the errors.

    6

  • 8/8/2019 ECC Report

    7/30

    Figure 4: Sketch of BCH decoding procedure

    By some mathematical manipulations, the following relation between the coefficients of (z)

    and the syndromes holds.

    M

    =

    D (15)

    where

    D =

    Sl+1

    Sl+2...

    S2l

    (16)

    and

    =

    l

    l1...

    1

    (17)

    and

    M =

    S1 S2 Sl

    S2 S3 Sl+1...

    .... . .

    ...

    Sl Sl+1 S2l1

    (18)

    Deriving the error locator polynomial by syndromes is the most computational intense part in

    the BCH decoding procedure. There are about 3 methods to get error locations, Berlekamp-Massey

    algorithm, Petersons algorithm and Euclidean algorithm.

    7

  • 8/8/2019 ECC Report

    8/30

    4.2.2 Petersons Algorithm

    Petersons algorithm is a direct method, it simply treats (15) as a set of linear equations and solves

    it by getting the inverse of the syndrome matrix. The disadvantage is that the decoding complexity

    is as high as O(n3) due to the inverting of the syndrome matrix, where n is the error correcting

    capability. The algorithm of Petersons algorithm is as follows:

    1. l = t, where t is the error correcting capability of the BCH code.

    2. Form the syndrome matrix M and syndrome vector D according to (18) and (17).

    3. If det(M) = 0, l = l 1, goto 2. If det(M) = 0, solve the linear equation M = D.

    In this project, a QR decomposition is developed to solve the linear equation (15) instead of

    getting the inverse of M in GF(2m). In this method

    1. Let i = 1.

    2. IfMi,i = 0, find a row j such that Mj,i = 0, then switch row i and row j (j > i). If such aj doesnt exist, return an error. If Mi,i = 0, for all j > i, multiply row j of M by Mi,i/Mj,i,then replace row j by the difference of row i and row j.

    3. Form the same operation to vector D as to M.

    4. Ifi = l 1, where l is the dimension of matrix M, stop. If i < l 1, i = i 1, repeat step 2.

    4.2.3 Berlekamp-Masseys Algorithm

    Berlekamp-Masseys algorithm is an efficient iterative algorithm which accelerates the BCH decod-

    ing significantly. It can be understood as an iterative approach to find a minimum linear feedback

    shift register (LFSR) that produces the syndromes obtained by the received codeword. As shown

    in Fig.5. The goal of Berlekamp-Massey algorithm is to find a polynomial (i+1)(x) of minimum

    degree at iteration i + 1 that satisfies

    li+1j=0

    Skj(i+1)j = 0 li < k < i + 1 (19)

    Denote the error locator polynomial at the ith iteration as:

    (i)

    (x) = 1 + (i)

    1 x + + (i)

    li xli

    (20)

    Define the discrepancy at iteration i as:

    di = Si+1 + Si(i)1 + + Sili(i)li (21)

    Where {Si} are the syndromes of the received codewords.The iteration procedure is in the following:

    8

  • 8/8/2019 ECC Report

    9/30

    Figure 5: Structure of linear feedback shift register

    -If di = 0, then

    (i+1)(x) = (i)(x) li+1 = li (22)

    -If di= 0: Let (m)(x) be the solution at iteration m, such that

    1

    m < i, dm

    = 0, and

    (m lm) is maximal. Then

    (i+1)(x) = (i)(x) + did1m x

    im(m)(x)

    li+1 = max(li, lm + i m). (23)

    With an initial value ofi = 0, the iterative procedure stops when either i li+1+td1 or i = 2td1is satisfied.

    The initial conditions of this algorithm are

    1

    (x) = 1, l

    1 = 0, d

    1 = 1,0(x) = 1, l0 = 0, d0 = S1. (24)

    5 Analysis of the Simulation Result

    The whole system is implemented in C programming language and the figures are drawn in mat-

    lab. In the simulation, source information are generated randomly according to the the uniform

    distribution. Since the BCH encoder encodes the source bits block by block, to make our simula-

    tion as accurate as possible, a number of 108 blocks (with each block 11 information bits for (31,

    11, 5) code and 5 information bits for (15, 5, 3) code) are performed and go through the BCH

    decoder/decoder. The bit error rate is defined as

    BER =

    Ni=1 e(i)

    N k (25)

    where N is the number of block transmitted, k is the information bits in each block and e(i) is the

    number of error bits in block i.

    9

  • 8/8/2019 ECC Report

    10/30

    In this simulation, the (31,11,5) BCH code and the (15,5,3) BCH code are constructed in the

    systematic manner. A comparison of these two encoding schemes and the full rate uncoded BPSK

    scheme is made at Eb/N0 region 0 dB to 8 dB. At this Eb/N0 region , the corresponding flip

    probability of the binary symmetric channel can be computed by the following equation:

    Pb(R) = Q(EbN0

    R) (26)

    where R is the rate of the encoding scheme. E.g., R = 11/31 for the (31, 11,5) BCH code and

    R = 1 for the uncoded BPSK scheme.

    Nine points are taken from this Eb/N0 region (0 dB to 8 dB) and the corresponding flip prob-

    abilities of the binary symmetric channel are listed in table 3:

    Table 3: Binary symmetric channel settings for each encoding schemeEbN0

    (dB) 0 1 2 3 4 5 6 7 8

    Pb (R=1) .0786 .0563 .0375 .0229 .0125 .0060 .0024 .0008 .0002Pb (R = 11/31) .1998 .1723 .1444 .1170 .0909 .0671 .0464 .0297 .0172

    Pb (R=5/15) .2071 .1798 .1520 .1244 .0978 .0733 .0516 .0338 .0201

    0 1 2 3 4 5 6 7 810

    6

    105

    104

    103

    102

    101

    100

    BER(31,11,5) BCH vs (15,5,3) BCH vs uncoded BPSK

    Eb/No (dB)

    Biterrorrate

    uncoded BPSK

    (31,11,5) BCH code

    (15,5,3) BCH code

    Figure 6: Comparison of (31,11,5) BCH code and (15,5,3) BCH code and uncoded BPSK

    10

  • 8/8/2019 ECC Report

    11/30

  • 8/8/2019 ECC Report

    12/30

    which witness the correctness of the whole communication system.

    References

    [1] J. L. Massey, Shift-Register Synthesis and BCH Decoding, IEEE Trans. Inform. Theory, vol.

    IT-15(1), pp. 122-127, jan 1969

    [2] J.P. M. Schalkwijk, Nonbinary BCH decoding, presented at the 1967 Internatl Spmp. on Infor-

    mation Theory, San Remo, Italy. W. W.

    [3] W. W. Peterson, Error-Correcting Codes, Cambridge, Mass: 111. I. T. Press, and New York:

    Wiley, ch. 9, 1961.

    [4] R. T. Chien, Cyclic decoding procedures for the Bose- Chaudhuri-Hocquenghem codes, IEEE

    Trans. Inform. Theory, vol. IT-10, pp. 357-363, October 1964.

    [5] R. H. Morelos-Zaragoza, The Art of Error Correcting Coding, 2002 John Wiley & Sons.

    12

  • 8/8/2019 ECC Report

    13/30

    6 Appendix 1: Documentations of the Source Code

    ----------------------------------------------------------------------

    int MakeBin(int num, int digit, int *ret);

    /*

    ---Function:

    Transform a decimal number into a binary sequence

    ---Parameters:num the decimal number

    digit: length of the binary sequence

    ret: place the binary sequence in ret

    ---Return value:

    return -1 if pointer ret is invalid.

    return 0 if the decimal number is transformed successfully

    ---Usage:

    MakeBin(5,3, p); --> p=[1,0,1];

    MakeBin(5,4, p); --> p=[0,1,0,1];

    */

    ----------------------------------------------------------------------

    int Dist(int a, int b);

    /*---Function:

    Calculate the distance of the a-th and the b-th codewords in the codebook

    ---Parameters:

    a, b: the index of the two codes

    ---Return values:

    return -1 if the input parameters a and b are invalid

    else, return the distance of these two codewords

    ---Usage:

    Dist(12, 14)

    */

    ----------------------------------------------------------------------

    int *NonSystematicEncoder(int *code)/*

    ---function:

    nonsystematic encoder, generate a codeword by the generator matrix

    ---Parameters:

    code: length k bit sequence

    ---Return value:

    return the pointer to the coded bit sequence, this memory should be

    released after calling this function

    ---Usage:

    int p[k]={0};

    int *q=Encoder(p);

    */

    ----------------------------------------------------------------------int Power(int i, int j);

    /*

    ---Function:

    compute the the j-th power of alpha^i

    */

    ----------------------------------------------------------------------

    int Multiply(int i, int j);

    13

  • 8/8/2019 ECC Report

    14/30

    /*

    ---Function:

    compute the product of alpha^i and alpha^j

    */

    ----------------------------------------------------------------------

    int Plus(int i, int j);

    /*

    ---Function:

    compute the sum of alpha^i and alpha^j

    */

    ----------------------------------------------------------------------

    int CalSymFun(int p, int Code[n]);

    /*

    ---Function:

    Compute the syndrome S_p according to:

    S[p]=alpha^{i_1}^p+alpha^{i_1}^p+ ... +alpha^{i_l}^p

    where i_k are the error locations

    ---Parameters:

    p: the index of desired syndrome S[p]

    Code: the received codeword, which will be used to compute the syndrome

    ---Return value:return the power of the syndrome

    */

    ----------------------------------------------------------------------

    int det(const int *S, int dim);

    /*

    ---Function:

    Compute the determinant of matrix S in finite field GF(2^m)

    ---Parameters

    S: the syndrome matrix

    dim: the dimension of the syndrome matrix

    ---Return value:

    return the determinant of the syndrome matrix S*/

    ----------------------------------------------------------------------

    bool reshape(int *S, int *D, int dim);

    /*

    ---Function:

    Reshape the syndrome matrix S into an upper triangular form

    ---parameter:

    S: the syndrome matrix

    S=[ S1, S2, ..., S_t

    S2, S3, ..., S-t=1

    ...

    S_t, ..., S_2t-1]

    D: the syndrome vector [S_t+1, S_t+2, ... , S_2t];dim: the dimension of the syndrome matrix

    ---Return value:

    return false if the matrix S can not be shaped into upper triangular form

    return true if S and D are reshaped successfully

    */

    ----------------------------------------------------------------------

    bool root(int *M, int *D, int *sigma, int dim);

    14

  • 8/8/2019 ECC Report

    15/30

    /*

    ---Function:

    Solve the linear matrix equation M*SIGMA=D in finite field GF(2^m)

    ---Parameters:

    M: syndrome matrix

    D: syndrome vector

    sigma: the memory reserved for the solutions of M*SIGMA=D

    dim: the dimension of the syndrome matrix

    ---Return value:

    return false if theres no solution for this equation

    */

    ----------------------------------------------------------------------

    bool ErrorPolyPos_Peterson(int *sigma, int index, int p);

    /*

    ---Function:

    Using Chien search method to verify if there is an error at the

    p-th position of the codeword

    ---Parameters:

    sigma: the coefficients of the error locator polynomial

    index: the length of vector sigma

    p: the position index to be verified---Return value:

    return true if there is an error at position p

    return false if there is no error at position p

    */

    ----------------------------------------------------------------------

    bool Decoder_Peterson(int *Code, int *ret);

    /*

    ---Function:

    Decoding a received codeword using Petersons algorithm

    ---Parameters:

    Code: pointer to the memory of the codeword to be decoded

    ret: pointer to the decoded codeword---Return value:

    return true if the codeword is decoded successfully

    return true if the error bits exceed the error correction capability

    */

    ----------------------------------------------------------------------

    int deg(int *px, int len);

    /*

    ---Function:

    Get the degree of the input polynomial p(x)

    ---Parameters:

    px: the coefficients of the polynomial

    len: the length of vector px

    ---Return value:return the degree of p(x)

    */

    ----------------------------------------------------------------------

    int shift(int *s, int len, int d, int *ret);

    /*

    ---Function:

    shift the original sequence by d bits

    15

  • 8/8/2019 ECC Report

    16/30

    ---Parameters:

    s: pointer to the original sequence

    len: the length of s

    d: number of bits to shift. d>0 is right shift, d

  • 8/8/2019 ECC Report

    17/30

    Code: pointer to the memory of the codeword to be checked

    ---Return value:

    return true if its a valid codeword

    return false if its invalid.

    */

    ----------------------------------------------------------------------

    7 Appendix 2: Source Code

    #include #include #include #include

    /*BCH decoder using Berlekamp-Massey algorithm and Petersons algorithm

    Author: Lei ZhouEmail: [email protected]

    Details and some definitions:

    Two sample BCH codes are tested in this program. (31, 11, 5) code and (15, 5, 3) code.

    They can be generated by both systematic encoder or the nonsystematic encode.1.

    (31,11,5) (n, k, t) BCH Codeg ( D ) = 5 4 2 3 3 2 5 = 1 0 1 1 0 0 0 1 0 0 1 1 0 1 1 0 1 0 1 0 1h(D)= 1 0 1 1 1 0 0 0 0 1 0 1 (h(D)*g(D)=D^31+1)G: generator matrix11-by-31

    2.

    (15,5,3) (n, k, t) BCH Codeg ( D ) = 1 0 1 0 0 1 1 0 1 1 1h(D)= 1 0 1 0 1 1G: generator matrix 5-by-15

    3.

    Syndrome matrix and vector:S=[ S1, S2, ..., S_t

    S2, S3, ..., S-t=1...S_t, ..., S_2t-1]

    D=[S_t+1, S_t+2, ... , S_2t]^t;

    4.

    Error locator polynomial sigma(x)=1+sigma_1*x+...+sigma_t*x^tSIGMA=[sigma_t, ... , sigma_1]^t;

    5.

    Basic equationS*SIGMA=-DS*SIGMA=D (for binary case)

    The aim of different decoding algorithms is to find SIGMA given S and D.

    6.

    Eb/No region: 0:8 dB

    */

    #define SNR_point 9#define ZERO -100 // zero of finitefields /*#define n 31 // codedword length#define r 5 // n=2^r-1#define r_g 20 // r=deg of g(x)#define k 11 // codeword length#define L 2048 // total number ofdifferent message symbols 2^k

    17

  • 8/8/2019 ECC Report

    18/30

    #define t 5 // error correctioncapability

    #define SimuPoints 100000000 // total number ofblocks to be simulated

    double Pb=0.05;

    double Pbs[SNR_point]={0.19977546082435, 0.17227462344458, 0.14444759135564,0.11703206374608, 0.09091341081634, 0.06705825520717, 0.04639544983528,0.02965075307658, 0.01716933127511};

    int S[2*t]={0};int M[t*t]={0};

    int D[t]={0}; // generator polynomial of (31, 11, 5) BCH code

    int gx[n]={0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,0,0,1,0,0,1,1,0,1,1,0,1,0,1,0,1};

    // elements in the finite field F32int alpha[n][5]={

    0, 0, 0, 0, 1,0, 0, 0, 1, 0,0, 0, 1, 0, 0,0, 1, 0, 0, 0,1, 0, 0, 0, 0,0, 0, 1, 0, 1,0, 1, 0, 1, 0,1, 0, 1, 0, 0,0, 1, 1, 0, 1,1, 1, 0, 1, 0,1, 0, 0, 0, 1,

    0, 0, 1, 1, 1,0, 1, 1, 1, 0,1, 1, 1, 0, 0,1, 1, 1, 0, 1,1, 1, 1, 1, 1,1, 1, 0, 1, 1,1, 0, 0, 1, 1,0, 0, 0, 1, 1,0, 0, 1, 1, 0,0, 1, 1, 0, 0,1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 2^r-1=n#define r_g 10 // deg g(x)=r#define k 5 // information length#define L 32 // total number of different

    message symbols 2^k#define t 3 // error correction capability#define ZERO -100 // 0#define SimuPoints 100000000 // simulationpoints

    int gx[n]={0,0,0,0,1,0,1,0,0,1,1,0,1,1,1};

    double Pb=0.05;

    double Pbs[SNR_point]={0.20710808912126, 0.17980086985934, 0.15199648377800,0.12438705471731, 0.09782237033322, .07325649478140, 0.05164329492939,0.03378166845235, 0.02013606962981};

    int S[2*t]={0};

    int M[t*t]={0};int D[t]={0}; // M *sigma=-D

    int alpha[n][4]={0, 0, 0, 1,0, 0, 1, 0,0, 1, 0, 0,1, 0, 0, 0,0, 0, 1, 1,0, 1, 1, 0,1, 1, 0, 0,1, 0, 1, 1,0, 1, 0, 1,1, 0, 1, 0,0, 1, 1, 1,1, 1, 1, 0,1, 1, 1, 1,1, 1, 0, 1,1, 0, 0, 1,

    };int G[k][n]={

    1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0,0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0,0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0,0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0,0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1,

    };

    int H[n-k][n]={1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0,

    0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1,};

    int CodeWord[L][n]={0};

    /*---Function:

    Transform a decimal number into a binary sequence---Parameters:

    num the decimal numberdigitlength of the binary sequenceret: place the binary sequence in ret

    ---Return value:

    19

  • 8/8/2019 ECC Report

    20/30

    return -1 if pointer ret is invalid.return 0 if the decimal number is transformed successfully

    ---Usage:MakeBin(5,3, p); --> p=[1,0,1];MakeBin(5,4, p); --> p=[0,1,0,1];

    */

    int MakeBin(int num, int digit, int *ret) {if(ret==NULL){

    return -1;}int index=digit-1;while(num){

    ret[index]=num%2;num-=ret[index];num/=2;index--;

    }return 0;

    }

    /*---Function:

    Calculate the distance of the a-th and the b-th codewords in the codebook---Parameters:

    a, b: the index of the two codes---Return values:

    return -1 if the input parameters a and b are invalid

    else, return the distance of these two codewords---Usage:Dist(12, 14)

    */int Dist(int a, int b) {

    if(a>=L ||a =L || b

  • 8/8/2019 ECC Report

    21/30

    for(j=0; j

  • 8/8/2019 ECC Report

    22/30

    /*---Function:

    Compute the syndrome S_p according to S[p]=alpha^{i_1}^p+alpha^{i_1}^p+ ... +alpha^{i_l}^pwhere i_k are the error locations

    ---Parameters:p: the index of desired syndrome S[p]Code: the received codeword, which will be used to compute the syndrome

    ---Return value:return the power of the syndrome

    */

    int CalSymFun(int p, int Code[n]) {int i=0, tmp=ZERO, tmp1=ZERO;for(i=0; i

  • 8/8/2019 ECC Report

    23/30

    {TMP[i]=(int *)malloc(dim*sizeof(int));

    }for(i=0; i

  • 8/8/2019 ECC Report

    24/30

    D: syndrome vectorsigma: the memory reserved for the solutions of M*SIGMA=Ddim: the dimenssion of the syndrome matrix

    ---Return value:return false if theres no solution for this equation

    */bool root(int *M, int *D, int *sigma, int dim) {

    int i=0, j=0;

    if(dim==1){

    if(det(M,dim)==ZERO){

    return false;}sigma[0]=Multiply(D[0],-M[0]);return true;

    }if(det(M, dim)==ZERO){

    int *TMP_M=(int *)malloc((dim-1)*(dim-1)*sizeof(int));int nIndex=0;

    //re construct S, delete the dim-th column and dim-th rowfor(i=0; i

  • 8/8/2019 ECC Report

    25/30

    free(TMP[i]);}free(TMP);

    return true;}

    /*---Function:

    Using Chien search method to verify if there is an error at thep-th position of the codeword

    ---Parameters:

    sigma: the coefficients of the error locator polynomualindex: the length of vector sigmap: the position index to be verified

    ---Return value:return true if there is an error at position preturn false if there is no error at position p

    */bool ErrorPolyPos_Peterson(int *sigma, int index, int p) {

    int sum=0,i=0;for(i=0; i

  • 8/8/2019 ECC Report

    26/30

    int index=0;for(i=t-1; i>=0; i--){

    if(sigma[i]!=-1){

    index++;}

    }/********************** step 3 search error position *********************/

    int Err[n]={0}; /* error polynomial */

    for(i=0; i

  • 8/8/2019 ECC Report

    27/30

    if(i+d=0){

    ret[i+d]=s[i];}

    }return 0;

    }

    /*---Function:

    systematic encoder for cyclic codes.e.g., u(x) is the uncoded bits,

    m(x)=x^r*u(x);m(x)=a(x)*g(x)+r(x)then return vector [r(x), u(x)] as the coded bitsux is of length n-rgx is of length rNote that: if u(x)=x^4+x+1, then u=[1,0,0,1,1]

    ---Parameters:ux: uncoded bitsgx: generator polynomialret: points to the coded bits

    ---Return value:return -1 is the input parameters are invalidreturn 0 if this encoding process is done sucessfully

    */int SystematicEncoder(int *ux, int *gx, int *ret) {

    if (ret==NULL || ux==NULL || gx==NULL){

    return -1;}int i=0;

    int u_tmp[n-r_g]={0}; memcpy(u_tmp, ux, (n-r_g)*sizeof(int));

    int g_tmp[n]={0}; memcpy(g_tmp, gx, n*sizeof(int));

    memcpy(ret+r_g, ux, (n-r_g)*sizeof(int));

    //mx=[u(x), n-r zeros];int mx[n]={0};

    memcpy(mx, u_tmp, (n-r_g)*sizeof(int));

    while (deg(mx, n)-deg(gx, n) >=0){

    int tmp[n]={0};shift(gx, n, -(deg(mx, n)-deg(gx, n)), tmp);

    for(int i=0; i

  • 8/8/2019 ECC Report

    28/30

  • 8/8/2019 ECC Report

    29/30

    Err[n-i-1]=1;}

    }

    /********************** step correcting ******************************//* C(x)+E(x) */for(i=0; i

  • 8/8/2019 ECC Report

    30/30