资源简介
BCH码 编码译码 能编译!!!!
能运行
代码片段和文件信息
/************************************************************************/
/*
日期:2014-05-17 17:17:58
程序功能:BCH编码和译码的算法实现
Author:郑峦、李军
开发环境:Microsoft Visual++ 6.0,windows XP
*/
/************************************************************************/
#include
#include
#include
#include
//定义全局变量
int m n length k t d;
int p[21];
int alpha_to[1048576] index_of[1048576] g[548576];
int recd[1048576] data[1048576] bb[548576];
int numerr errpos[1024] decerror = 0;
/*
* read_p()的功能:
*1: 输入多项式p(x)的阶层m用于计算伽罗瓦域GF(2**m).用于得到预先计算的p(x)的系数
*2: 输入码长
*/
void read_p()
{
int i ninf;
printf(“\n确定多项式p(x)阶层m的值, 其BCH码的长度区间为:\n“);
printf(“ 2**(m-1)-1 < 码长 <= 2**m-1\n\n“);
do {
printf(“输入m (m在2和20之间取值): “);
scanf(“%d“ &m);
} while ( !(m>1) || !(m<21) );
//计算出输入多项式p(x)
for (i=1; i p[i] = 0;
p[0] = p[m] = 1;
if (m == 2) p[1] = 1;
else if (m == 3) p[1] = 1;
else if (m == 4) p[1] = 1;
else if (m == 5) p[2] = 1;
else if (m == 6) p[1] = 1;
else if (m == 7) p[1] = 1;
else if (m == 8) p[4] = p[5] = p[6] = 1;
else if (m == 9) p[4] = 1;
else if (m == 10) p[3] = 1;
else if (m == 11) p[2] = 1;
else if (m == 12) p[3] = p[4] = p[7] = 1;
else if (m == 13) p[1] = p[3] = p[4] = 1;
else if (m == 14) p[1] = p[11] = p[12] = 1;
else if (m == 15) p[1] = 1;
else if (m == 16) p[2] = p[3] = p[5] = 1;
else if (m == 17) p[3] = 1;
else if (m == 18) p[7] = 1;
else if (m == 19) p[1] = p[5] = p[6] = 1;
else if (m == 20) p[3] = 1;
printf(“p(x) = “);
n = 1;
for (i = 0; i <= m; i++) {
n *= 2;
printf(“%1d“ p[i]); //输出多项式p(x)
}
printf(“\n“);
n = n / 2 - 1;
ninf = (n + 1) / 2 - 1;
do {
printf(“输入BCH码的码长 (%d < 码长 <= %d): “ ninf n); //输入BCH码的码长
scanf(“%d“ &length);
} while ( !((length <= n)&&(length>ninf)) );
}
/*
* generate_gf()功能:
* 生成域GF(2 * *m)的不可约多项式p(X)系数p[0]. . p[m].
* 查找表:
* 从指数到多项式形式; j=alpha^i;
* 从多项式到指数形式:alpha^i] = i;
* α=2 是 GF(2**m)的原始数据
*/
void generate_gf()
{
register int i mask; //定义mask(掩码)
mask = 1;
alpha_to[m] = 0;
for (i = 0; i < m; i++) { //从指数到多项式形式; j=alpha^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++) { //从多项式到指数形式:alpha^i] = 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;
}
/*
* 计算二进制BCH码的生成多项式.
* 首先生成周期数组和阶层 2**m - 1 cycle[][] = (i 2*i 4*i ... 2^l*i).
* 然后确定哪些周期集合包含的 (d-1)
* 连续整数 {1..(d-1)}. 本原产生式产生了。
* 为线性形
评论
共有 条评论