Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. BCH Encoder

BCH Encoder

Scheduled Pinned Locked Moved C / C++ / MFC
databasedata-structureshelpquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Abbas_Riazi
    wrote on last edited by
    #1

    I'm writing an application that requires some BCH ECC (Error Correction Coding). I found some code on the net but the result of calculation is different with the results from MATLAB. Is there anyone that has some experience in this field? The MATLAB code is as follow:

    n =31
    k=21

    %gf is Galois field
    msg=gf([1 1 1 0 0 1 1 1 1 0 0 0 0 1 1 0 0 1 1 0 1])

    cbch=bchenc(msg, n, k)

    cbch Array elements =

    1 1 1 0 0 1 1 1 1 0 0
    0 0 1 1 0 0 1 1 0 1 1
    0 1 0 0 1 0 1 0 1

    Here is the C code (console app):

    #include "StdAfx.h"
    #include
    #include
    #include

    int m = 5, n = 31, k = 21, t = 2, d = 5;
    int length = 31;
    int p[6]; /* irreducible polynomial */
    int alpha_to[32], index_of[32], g[11];
    int recd[31], data[21], bb[11];
    int numerr, errpos[32], decerror = 0;
    int seed;

    void
    read_p()
    /* Primitive polynomial of degree 5 */
    {
    // register int i;
    p[0] = p[2] = p[5] = 1; p[1] = p[3] = p[4] =0;
    }

    void
    generate_gf()
    /*
    * generate GF(2**m) from the irreducible polynomial p(X) in p[0]..p[m]
    * lookup tables: index->polynomial form alpha_to[] contains j=alpha**i;
    * polynomial form -> index form index_of[j=alpha**i] = i alpha=2 is the
    * primitive element of GF(2**m)
    */
    {
    register int i, mask;
    mask = 1;
    alpha_to[m] = 0;
    for (i = 0; i < m; i++) {
    alpha_to[i] = mask;
    index_of[alpha_to[i]] = i;
    if (p[i] != 0)
    alpha_to[m] ^= mask;
    mask <<= 1;
    }
    index_of[alpha_to[m]] = m;
    mask >>= 1;
    for (i = m + 1; i < n; i++) {
    if (alpha_to[i - 1] >= mask)
    alpha_to[i] = alpha_to[m] ^ ((alpha_to[i - 1] ^ mask) << 1);
    else
    alpha_to[i] = alpha_to[i - 1] << 1;
    index_of[alpha_to[i]] = i;
    }
    index_of[0] = -1;
    }

    void
    gen_poly()
    /*
    * Compute generator polynomial of BCH code of length = 31, redundancy = 10
    * (OK, this is not very efficient, but we only do it once, right? :)
    */
    {
    register int ii, jj, ll, kaux;
    int test, aux, nocycles, root, noterms, rdncy;
    int cycle[15][6], size[15], min[11], zeros[11];
    /* Generate cycle sets modulo 31 */
    cycle[0][0] = 0; size[0] = 1;
    cycle[1][0] = 1; size[1] = 1;
    jj = 1; /* cycle set index */
    do {
    /* Generate the jj-th cycle set */
    ii = 0;
    do {
    ii++;
    cycle

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups