• xqz%265334
    了解作者
  • Others
    开发工具
  • 13KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 2
    下载次数
  • 2018-06-10 06:00
    上传日期
一个用c编的RS编码的程序,采用BERLEKAMP-MASSEY S 算法,输入m,以及信噪比,可得到生成多项式和误码率等
943456.zip
  • rs_bm.opt
    47.5KB
  • rs_bm.plg
    632B
  • t0rs_bm.c
    20KB
  • 0Crs_bm.dsw
    535B
  • rs_bm.ncb
    33KB
  • Kk93rs_bm.dsp
    3.3KB
内容介绍
/* ------------------------------------------------------------------ // // The Reed-Somolon code is specified by the finite field, the length // (length <= 2^m-1), the number of redundant symbols (length-k), and // the initial zero of the code, init_zero, such that the zeros are: // init_zero, init_zero+1, ..., init_zero+length-k-1 // // ERRORS AND ERASURES CORRECTION WITH BERLEKAMP-MASSEY'S ALGORITHM // // ------------------------------------------------------------------ */ #include <math.h> #include <stdio.h> #include <float.h> #include <limits.h> #include <stdlib.h> #define MAX_RANDOM LONG_MAX /* Maximum value of random() */ int i; int m, n, length, k, t, t2, d, red; int init_zero; int p[10]; int alpha_to[1024], index_of[1024], g[1024]; int recd[1024], data[1024], b[1024]; int numerr, errpos[512], errval[512], decerror; int biterror, error; char filename[40], name2[40]; int numera; int era[512], eraval[512]; void read_p(void); void generate_gf(void); void gen_poly(void); void encode_rs(void); void bpsk_awgn(void); void decode_rs(void); int weight(int word); main(int argc, char *argv[]) { /* Command line processing */ if (argc != 5) { printf("\nSimulation of RS codes \n"); printf("Usage: %s m length red init_zero \n", argv[0]); printf(" - m is the order of GF(2^m)\n"); printf(" - length is the length of the RS code\n"); printf(" - red = length - dimension\n"); printf(" - init_zero = inital zero of the code\n"); exit(0); } sscanf(argv[1],"%d", &m); sscanf(argv[2],"%d", &length); sscanf(argv[3],"%d", &red); sscanf(argv[4],"%d", &init_zero); k = length - red; t = red/2; t2 = 2*t; read_p(); /* Read m */ generate_gf(); /* Construct the Galois Field GF(2^m) */ printf("--> This is an RS(%d,%d,%d) code over GF(2^%d), t = %d\n", length, k, red+1, m, t); printf(" with zeros: "); for (i=0;i<t2;i++) printf("%d ", init_zero+i); printf("\n\n"); gen_poly(); /* Compute the generator polynomial of RS code */ /* Randomly generate DATA */ for (i = 0; i < k; i++) data[i] = (random(0xffff)>>10) % n; encode_rs(); /* encode data */ /* Codeword is c(X) = data(X)*X**(length-k)+ b(X) */ for (i = 0; i < length - k; i++) recd[i] = b[i]; for (i = 0; i < k; i++) recd[i + length - k] = data[i]; for (i = 0; i < length; i++) recd[i] = 0; /* Introduce errors and erasures at will ... */ /* CHANNEL NOISE: Read errors and erasures */ printf("Number of errors, e: "); scanf("%d", &numerr); if (numerr) for (i=0; i<numerr; i++) { printf("position: "); scanf("%d", &errpos[i]); /* as power of alpha */ printf("value: "); scanf("%d", &errval[i]); /* as vector */ recd[errpos[i]] ^= errval[i]; } printf("Number of erasures, b: "); scanf("%d", &numera); if (numera) for (i=0; i<numera; i++) { printf("position: "); scanf("%d", &era[i]); /* as power of alpha */ printf("value: "); scanf("%d", &eraval[i]); /* as vector */ recd[era[i]] ^= eraval[i]; } printf("\n\nRec ="); for (i=0; i<length; i++) { printf("%4d ", index_of[recd[i]]); } printf("\n "); for (i=0; i<length; i++) { printf("%4d ", recd[i]); } printf("\n"); decode_rs(); /* DECODE received codeword recv[] */ /* DECODING ERRORS? we compare only the data portion */ decerror = 0; biterror = 0; for (i = length-k; i < length; i++) if (data[i-length+k] != recd[i]) { decerror++; biterror += weight(data[i-length+k]- recd[i]); } } void read_p() /* Read m, the degree of a primitive polynomial p(x) used to compute the // Galois field GF(2**m). Get precomputed coefficients p[] of p(x). Read // the code length. */ { int i, ninf; printf("\nSimulation of RS codes \n"); for (i=1; i<m; 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[3] = 1; /* else if (m == 4) p[1] = 1; // Commented out to match example p. 68 */ 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("Primitive polynomial of GF(2^%d), (LSB first) p(x) = ",m); n = 1; for (i = 0; i <= m; i++) { n *= 2; printf("%1d", p[i]); } printf("\n"); n = n / 2 - 1; } void generate_gf() /* generate GF(2^m) from the irreducible polynomial p(X) in p[0]..p[m] // // lookup tables: log->vector form alpha_to[] contains j=alpha**i; // vector form -> log 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; #ifdef PRINT_GF printf("Table of GF(%d):\n",n); printf("----------------------\n"); printf(" i\tvector \tlog\n"); printf("----------------------\n"); for (i=0; i<=n; i++) printf("%4d\t%4x\t%4d\n", i, alpha_to[i], index_of[i]); #endif } void gen_poly() /* Compute the generator polynomial of the t-error correcting, length // n=(2^m -1) Reed-Solomon code from the product of (X+alpha^i), for // i = init_zero, init_zero + 1, ..., init_zero+length-k-1 */ { register int i,j; g[0] = alpha_to[init_zero]; /* <--- vector form of alpha^init_zero */ g[1] = 1; /* g(x) = (X+alpha^init_zero) */ for (i=2; i<=length-k; i++) { g[i] = 1; for (j=i-1; j>0; j--) if (g[j] != 0) g[j] = g[j-1]^ alpha_to[(index_of[g[j]]+i+init_zero-1)%n]; else g[j] = g[j-1]; g[0] = alpha_to[(index_of[g[0]]+i+init_zero-1)%n]; } /* convert g[] to log form for quicker encoding */ for (i=0; i<=length-k; i++) g[i] = index_of[g[i]]; #ifdef PRINT_POLY printf("Generator polynomial (independent term first):\ng(x) = "); for (i=0; i<=length-k; i++) printf("%5d", g[i]); printf("\n"); #endif } void encode_rs() /* Compute the 2t parity symbols in b[0]..b[2*t-1] // data[] is input and b[] is output in polynomial form. // Encoding is done by using a feedback shift register with connections // specified by the elements of g[]. */ { register int i,j; int feedback; for (i=0; i<length-k; i++) b[i] = 0; for (i=k-1; i>=0; i--) { feedback = index_of[data[i]^b[length-k-1]]; if (feedback != -1) { for (j=length-k-1; j>0; j--) if (g[j] != -1) b[j] = b[j-1]^alpha_to[(g[j]+feedback)%n]; else b[j] = b[j-1]; b[0] = alpha_to[(g[0]+feedback)%n]; } else { for (j=length-k-1; j>0; j--) b[j] = b[j-1]; b[0] = 0; } } } int elp[1026][1024] ; void decode_rs(
评论
    相关推荐
    • hsbh.rar
      一个用c编的RS编码的程序,采用BERLEKAMP-MASSEY S 算法,输入m,以及信噪比,可得到生成多项式和误码率等
    • USB-COM(HL340).rar
      usb转串口,找了很久才找到,现在别的地方很难下到,要不用不了,我这个可以用 HL340D 的
    • NAND FLASH的读写程序.rar
      Nand flash 读写程序 C语言代码,可以给U盘开发者参考 可以读写三星各种型号的Nand flash芯片
    • USB_2.0.rar
      USB2.0开发例程,基于51单片机,包括pc端程序
    • 串口温度数据采集并实时显示.rar
      串口温度数据采集并实时显示 读串口数据的原理是,只要当有数据向串口发数据来时,计算机就会自动将其数据写到一个特定的缓冲区,我们只要写程序去读那个特定的缓冲区就可以了. 有数据向串口发过来时,程序可以将数据接收到,接收的数据是字符型的,那么将数据转化为数字型的,再将这个数据的大小作为画图的某一个点的纵坐标,横坐标为数据的序号.将这些点用线连起来就是一个曲线图了,这个就是图形显示基本原理. 查看原来的数据的原理也是这样的,不同的地方就是,数据是从文件中来,同样的也是将多个数据分成一个一个的,然后这一个数据的大小就是画图的某一个点的纵坐标,横坐标同样为数据的序号,再将这些点用线连起来就是曲线图. 图形能移动的原理,是我们首先改变的只是数据,图形并没有变,但图形的形式是由这些数据来确定的,当数据发生变化后,我们通过刷新显示区来变化的.
    • gps.rar
      GPS应用程序设计,内含GPS卫星原理、方法及详细源代码
    • MSCOMM32.OCX.rar
      串口编程控件MSCOMM32.OCX mscomm32.ocx是微软提供的串口通讯开发控件。支持串口通讯的软件大部分都是使用这个控件来实现串口通讯功能的。 安装方法:请您把它复制到系统目录下,对于windows9x系列(win95、win98、winme)是x:\windows\system\,对于 windowsNT、windows2000、windowsXP系列是x:\winnt\system32\。然后打开一个命令行提示符窗口(MSDOS方式窗口), 用"cd x:\windows\system\"命令或者"cd x:\winnt\system32\"切换到系统目录下,再执行"regsvr32 mscomm32.ocx"这个命令。
    • VSer.rar
      虚拟串口的完整源代码,包括注释和开发日志。据说市值5万人民币!
    • USB-shujucaiji.rar
      USB数据采集系统论文-自己的毕业设计论文,花了很长时间做的,内容十分详细,包括核心代码和开发环境的设置。
    • wmserial.zip
      基于消息的Windows串口通讯例子