⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rs.c

📁 RS译码器的C源代码,采用了BM算法
💻 C
字号:
/*  * Reed Solomon Encoder/Decoder  * * (c) Henry Minsky (hqm@ua.com), Universal Access 1991-1995 */#include <stdio.h>#include <ctype.h>#include "ecc.h"/* Encoder parity bytes */int pBytes[MAXDEG];/* Decoder syndrome bytes */int synBytes[MAXDEG];/* generator polynomial*/ 
//int genPoly[MAXDEG*2]={79,44,81,100,49,183,56,17,232,187,126,104,31,103,52,118,1};
//int genPoly[MAXDEG*2]={228,231,214,81,113,204,19,169,10,244,117,219,130,12,160,151,195,170,150,151,251,218,245,166,149,183,109,176,148,218,21,161,240,25,15,71,62,5,17,32,157,194,73,195,218,14,12,122,1};

int genPoly[MAXDEG*2]={106,117,43,201,70,139,47,64,127,181,48,25,230,85,31,157,156,123,88,44,149,223,165,36,127,46,142,212,233,71,149,88,165,227,80,105,44,72,147,55,60,85,70,132,229,230,217,155,38,112,43,174,169,136,23,60,186,63,198,205,135,171,40,159,1};

int DEBUG = FALSE;static void compute_genpoly (int nbytes, int genpoly[]);

/* Initialize lookup tables, polynomials, etc. */voidinitialize_ecc (){  /* Initialize the galois field arithmetic tables */    init_galois_tables();
    /* Compute the encoder generator polynomial */ //compute_genpoly(NPAR, genPoly);
    
 
   
}voidzero_fill_from (unsigned char buf[], int from, int to){  int i;  for (i = from; i < to; i++) buf[i] = 0;}/* debugging routines */voidprint_parity (void){   int i;  printf("Parity Bytes: ");  for (i = 0; i < NPAR; i++)     printf("[%d]:%x, ",i,pBytes[i]);  printf("\n");}voidprint_syndrome (void){   int i;  printf("Syndrome Bytes: ");  for (i = 0; i < NPAR; i++)     printf("[%d]:%x, ",i,synBytes[i]);  printf("\n");}/* Append the parity bytes onto the end of the message */void build_codeword (unsigned char msg[], int nbytes, unsigned char dst[]){  int i;	  for (i = 0; i < nbytes; i++) dst[i] = msg[i];	  for (i = 0; i < NPAR; i++) {    dst[i+nbytes] = pBytes[NPAR-1-i];  }}	/********************************************************** * Reed Solomon Decoder  * * Computes the syndrome of a codeword. Puts the results * into the synBytes[] array. */ void decode_data(unsigned char data[], int nbytes){  int i, j, sum;  for (j = 0; j < NPAR;  j++) {    sum	= 0;    for (i = 0; i < nbytes; i++) {      sum = data[i] ^ gmult(gexp[j+1], sum);    }    synBytes[j]  = sum;  }}/* Check if the syndrome is zero */int check_syndrome (void){  int i, nz = 0;  for (i =0 ; i < NPAR; i++) {    if (synBytes[i] != 0) nz = 1;  }  return nz;}/*void debug_check_syndrome (void){	  int i;	  for (i = 0; i < 15; i++) {    printf(" inv log S[%d]/S[%d] = %d\n", i, i+1, 	   glog[gmult(synBytes[i], ginv(synBytes[i+1]))]);  }}/* Create a generator polynomial for an n byte RS code.  * The coefficients are returned in the genPoly arg. * Make sure that the genPoly array which is passed in is  * at least n+1 bytes long. *//*static void compute_genpoly (int nbytes, int genpoly[]){
int i, tp[256], tp1[256];	  ///* multiply (x + a^n) for n = 1 to nbytes  nbytes==NPAR*/ /*zero_poly(tp1);  tp1[0] = 1;  for (i = 1; i <= nbytes; i++) {    zero_poly(tp);    tp[0] = gexp[i];		/* set up x+a^n */  /*tp[1] = 1;	      mult_polys(genpoly, tp, tp1);
	copy_poly(tp1, genpoly);
  }

   for(i=0;i<MAXDEG*2;i++)
   printf("the value of genpoly is: \"%d\"\n", genpoly[i]);
       }
/* Simulate a LFSR with generator polynomial for n byte RS code.  * Pass in a pointer to the data array, and amount of data.  * * The parity bytes are deposited into pBytes[], and the whole message * and parity are copied to dest to make a codeword. *  */void encode_data (unsigned char msg[], int nbytes, unsigned char dst[]){  int i, LFSR[NPAR+1],dbyte, j;	  for(i=0; i < NPAR+1; i++) LFSR[i]=0;  for (i = 0; i < nbytes; i++) {    dbyte = msg[i] ^ LFSR[NPAR-1];    for (j = NPAR-1; j > 0; j--) {      LFSR[j] = LFSR[j-1] ^ gmult(genPoly[j], dbyte);    }    LFSR[0] = gmult(genPoly[0], dbyte);  }  for (i = 0; i < NPAR; i++)     pBytes[i] = LFSR[i];	  build_codeword(msg, nbytes, dst);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -