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

📄 wd_linear_code.c

📁 error correction code
💻 C
字号:
// ------------------------------------------------------------------------
// File: WD_linear_code.c
//
// Compute the weight distribution of a linear block code
// from its generator matrix.
// ------------------------------------------------------------------------
// This program is complementary material for the book:
//
// R.H. Morelos-Zaragoza, The Art of Error Correcting Coding, Wiley, 2002.
//
// ISBN 0471 49581 6
//
// This and other programs are available at http://the-art-of-ecc.com
//
// You may use this program for academic and personal purposes only. 
// If this program is used to perform simulations whose results are 
// published in a journal or book, please refer to the book above.
//
// The use of this program in a commercial product requires explicit
// written permission from the author. The author is not responsible or 
// liable for damage or loss that may be caused by the use of this program. 
//
// Copyright (c) 2002. Robert H. Morelos-Zaragoza. All rights reserved.
// ------------------------------------------------------------------------
#include <stdio.h>
#include <math.h>

main()
{
   int i, j, l, n, k, g[63][64];
   long ii, iifinal, weight[64], sum, tot;
   char name1[40],name2[40];
   FILE *fp1,*fp2;
   
   printf("Compute the weight distribution of a linear code\n");
   printf("    by Robert H. Morelos-Zaragoza (c) 1997\n");
   printf("------------------------------------------------\n");
   printf("INPUT file name, N, K and OUTPUT file name?\n");
   scanf("%s %d %d %s", name1, &n, &k, name2);
   
   fp1 = fopen(name1,"r");
   printf("\nGenerator matrix of (%d,%d) code:\n",n,k);
   for (i=0; i < k; i++) 
   {   
      for (j=0; j < n; j++)
         {
         fscanf(fp1,"%1d",&g[i][j]);
         printf("%1d",g[i][j]);
         }
      printf("\n");
   }
   printf("\n");
   fclose(fp1);
   
   fp2 = fopen(name2,"w");
   fprintf(fp2,"%d\n",k);
   
   for (i=0; i<=n; i++)
      weight[i] = 0;               

   iifinal = 1;
   for (i=0; i<k; i++)
     iifinal *= 2;

   for (ii=0;ii<iifinal;ii++)
   {
      sum = 0;
      for (j=0; j<n; j++)
      {
         tot = 0;
         for (l=0; l<k; l++)
           tot = tot + ((ii>>l) & g[l][j]);
         tot = tot % 2;
         sum = sum + tot;
      }
      weight[sum]++;
   }   

   printf("\n i  \tW[i]\n");
   printf("-------------\n");
   for (i=0; i <= n; i++)
     if (weight[i] != 0)
       {
       fprintf(fp2,"%d\t%ld\n", i,weight[i]);
       printf("%3d\t%ld\n", i,weight[i]);
       }
   fclose(fp2);
}

⌨️ 快捷键说明

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