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

📄 rscodeyanjiu.txt

📁 也是我从网上找到的源码 供大家分享 希望有所新发现
💻 TXT
📖 第 1 页 / 共 2 页
字号:
/* have now found q such that d[u]!=0 and u_lu[q] is maximum */
/* store degree of new elp polynomial */
            if (l[u]>l[q]+u-q)  l[u+1] = l[u] ;
            else  l[u+1] = l[q]+u-q ;
/* form new elp(x) */
  //          for (i=0; i<NN-KK; i++)    elp[u+1][i] = 0 ;
   for (i=0; i<9; i++)    elp[u+1][i] = 0 ;
            for (i=0; i<=l[q]; i++)
              if (elp[q][i]!=-1)
                elp[u+1][i+u-q] = alpha_to[(d[u]+NN-d[q]+elp[q][i])%NN] ;
            for (i=0; i<=l[u]; i++)
              { elp[u+1][i] ^= elp[u][i] ;
#ifdef PS
 omega[u][i]=elp[u][i];
#endif
                elp[u][i] = index_of[elp[u][i]] ;  /*convert old elp value to index*/
              }
          }
        u_lu[u+1] = u-l[u+1] ;
/* form (u+1)th discrepancy */
        if (u<NN-KK)    /* no discrepancy computed on last iteration */
          {
            if (s[u+1]!=-1)
                   d[u+1] = alpha_to[s[u+1]] ;
            else
              d[u+1] = 0 ;
            for (i=1; i<=l[u+1]; i++)
              if ((s[u+1-i]!=-1) && (elp[u+1][i]!=0))
                d[u+1] ^= alpha_to[(s[u+1-i]+index_of[elp[u+1][i]])%NN] ;
            d[u+1] = index_of[d[u+1]] ;    /* put d[u+1] into index form */
          }
      } while ((u<NN-KK) && (l[u+1]<=TT)) ;
//------------------------------------------------------------------------------------------------------------------
      u++ ;
      if (l[u]<=TT)         /* can correct error *///*****************************************
       {
/* put elp into index form */
    
         for (i=0; i<=l[u]; i++)   elp[u][i] = index_of[elp[u][i]] ;
/* find roots of the error location polynomial */
         for (i=1; i<=l[u]; i++)
           reg[i] = elp[u][i] ;
         count = 0 ;
         for (i=1; i<=NN; i++)
          {  q = 1 ;
             for (j=1; j<=l[u]; j++)
              if (reg[j]!=-1)
                { reg[j] = (reg[j]+j)%NN ;
                  q ^= alpha_to[reg[j]] ;
                } ;
             if (!q)        /* store root and error location number indices */
              { root[count] = i;
                loc[count] = NN-i ;
                count++ ;
              };
          } ;
         if (count==l[u])    /* no. roots = degree of elp hence <= TT errors */
          {
/* form polynomial z(x) */
           for (i=1; i<=l[u]; i++)        /* Z[0] = 1 always - do not need */
            { if ((s[i]!=-1) && (elp[u][i]!=-1))
                 z[i] = alpha_to[s[i]] ^ alpha_to[elp[u][i]] ;
              else if ((s[i]!=-1) && (elp[u][i]==-1))
                      z[i] = alpha_to[s[i]] ;
                   else if ((s[i]==-1) && (elp[u][i]!=-1))
                          z[i] = alpha_to[elp[u][i]] ;
                        else
                          z[i] = 0 ;
              for (j=1; j<i; j++)
                if ((s[j]!=-1) && (elp[u][i-j]!=-1))
                   z[i] ^= alpha_to[(elp[u][i-j] + s[j])%NN] ;
#ifdef PS
zx[i]=z[i];
#endif
              z[i] = index_of[z[i]] ;         /* put into index form */
            } ;
  /* evaluate errors at locations given by error location numbers loc[i] */
           for (i=0; i<NN; i++)
             { err[i] = 0 ;
               if (recd[i]!=-1)        /* convert recd[] to polynomial form */
                 recd[i] = alpha_to[recd[i]] ;
               else  recd[i] = 0 ;
             }
           for (i=0; i<l[u]; i++)    /* compute numerator of error term first */
            { err[loc[i]] = 1;       /* accounts for z[0] */
              for (j=1; j<=l[u]; j++)
                if (z[j]!=-1)
                  err[loc[i]] ^= alpha_to[(z[j]+j*root[i])%NN] ;
              if (err[loc[i]]!=0)
               { err[loc[i]] = index_of[err[loc[i]]] ;
                 q = 0 ;     /* form denominator of error term */
                 for (j=0; j<l[u]; j++)
                   if (j!=i)
                     q += index_of[1^alpha_to[(loc[j]+root[i])%255]] ;
                 q = q % NN ;
                 err[loc[i]] = alpha_to[(err[loc[i]]-q+NN)%NN] ;
                 recd[loc[i]] ^= err[loc[i]] ;  /*recd[i] must be in polynomial form */
               }
            }
          }
         else    /* no. roots != degree of elp => >TT errors and cannot solve */
   {  err_flag=2;
           for (i=0; i<NN; i++)        /* could return error flag if desired */
     {if (recd[i]!=-1)        /* convert recd[] to polynomial form */
                 recd[i] = alpha_to[recd[i]] ;
               else  recd[i] = 0 ;     /* just output received codeword as is */
     }
   }
       }
     else         /* elp has degree has degree >TT hence cannot solve *///********************
  {
   err_flag=2;
       for (i=0; i<NN; i++)       /* could return error flag if desired */
    { 
     if (recd[i]!=-1)        /* convert recd[] to polynomial form */
            recd[i] = alpha_to[recd[i]] ;
          else  recd[i] = 0 ;     /* just output received codeword as is */
    }
  }
    }
   else       /* no non-zero syndromes => no errors: output received codeword */
    for (i=0; i<NN; i++)
       if (recd[i]!=-1)        /* convert recd[] to polynomial form */
         recd[i] = alpha_to[recd[i]] ;
       else  recd[i] = 0 ;
 }
void main(void)
{
 register int i;
 int acterr_num,err_pos[NN];
// int goon=1;
 /* generate the Galois Field GF(2**MM) */
 generate_gf() ;
#ifdef DEBUG
 printf("Look-up tables for GF(2**%2d)\n",MM);
 printf("i   alpha_to[i]     index_of[i]\n");
 for (i=0; i<=NN; i++)
 printf("%d\t%d\t\t%d\n",i,alpha_to[i],index_of[i]);
 printf("\n\n") ;
// for(i=0; i<9;i++)
//  printf("%x",pp[i]);
#endif
 
 /*compute the generator polynomial*/
 gen_poly();
#ifdef DEBUG
 printf("the generator polynomial g(x)(index form)=\n");
 printf(" i  gg[i]\n");
 for(i=NN-KK;i>=0;i--)
 printf(" %d  %d\n",i,gg[i]);
#endif
 do{
 printf("Reed-Solomon code is (%d,%d) over F(%d).\n",NN,KK,(1<<MM));
 printf("This pragramm can correct %d errors, and delect %d errors.\n",TT,2*TT);
 printf("\n");
 printf("Please determine the number of the actual errors: ");
 scanf("%d",&acterr_num);
 printf("Please determine the position of the actual errors\n");
 printf("(total %d ,range from 0 to %d): ",acterr_num,NN-1);
 for(i=0;i<acterr_num;i++)
  scanf("%d",&err_pos[i]);
 printf("\n");
 /*generate the random data*/
/* srand(unsigned(time(NULL)));
 for(i=0;i<KK;i++)
  data[i]=rand()&NN;
*/
 //input the data manully
 
 
#ifdef PS
 for (i=0;i<KK;i++)
 data[i]=KK-i;
#else
for (i=0;i<KK;i++)
 data[i]=KK-i;
#endif

 printf("The to be transmitted data is:\n");
 for(i=0;i<KK;i++)
  printf("%d  ",data[i]);
 printf("\n\n");
 encode_rs();
 /*form the transmitted code,with parity plus data.*/
 for(i=0;i<NN-KK;i++)
  recd[i]=bb[i];
 for(i=NN-KK;i<NN;i++)
  recd[i]=data[i-NN+KK];
 printf("Encoded data is:\n");
 for(i=0;i<NN;i++)
  printf("%d ",recd[i]);
 printf("\n\n");
 printf("The recieved code with errors is:\n");
 for(i=0;i<acterr_num;i++)
//-------------------------------------------------------- 
#ifdef PS   
 recd[err_pos[i]]=(recd[err_pos[i]]^16)%(NN+1);
 //for (i=0;i<8;i++)
 //only one error
 for (i=0;i<7;i++)
  recd[254-i]=16;
// for (i=0;i<247;i++)
//  recd[i] = 0;
/*
 recd[254]=55;
 recd[253]=55;
 recd[252]=55;
 recd[251]=55;
 
 recd[246]=111;
 recd[245]=111;
 recd[244]=111;
 recd[243]=111;
*/ 
 //recd[240]=66;
#else
 recd[err_pos[i]]=(recd[err_pos[i]]^rand())%(NN+1);
#endif
//----------------------------------------------------------
 for(i=0;i<NN;i++)
  printf("%d ",recd[i]);
 printf("\n\n");
//**************************************************** 
 for(i=0;i<NN;i++)
  recd[i]=index_of[recd[i]];
 decode_rs();
 switch(err_flag)
 {
 case(0):
  printf("This code has been correctly transmitted.\n\n");
  break;
 case(1):
  printf("This code can be corrected.\n\n");
  break;
 case(2):
  printf("This code cannot be corrected,\n");
  printf("while the number of errors is greater than TT\n\n");
  break;
 }
 printf("The result of the decoding is :\n");
 for(i=0;i<NN;i++)
 printf("%d ",recd[i]);
 printf("\n\n");
 printf("The correct information is maybe:\n");
 for(i=NN-KK;i<NN;i++)
 printf("%d  ",recd[i]);
 printf("\n\n");
   
 printf("Press ESC to EXIT, press any other key to CONTINUE...\n");
 
 
 }while(_getch()!=27);
}
///////////////////////////////////////////////////////////////////////////////
//C code end
 
///////////////////////////////////////////////////////////////////////////////////////////////   
if you want to get the detailed file, contact with me via EastDragonInc@hotmail.com 

⌨️ 快捷键说明

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