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

📄 wer_chernoff.c

📁 详细讲述纠错码的书籍
💻 C
字号:
// ------------------------------------------------------------------------
// File: WER_Chernoff.c
//
// CHERNOFF BOUND on the error performance of a linear code with
// BPSK modulation over a flat Rayleigh fading channel. NO CSI.
// ------------------------------------------------------------------------
// 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>
#include <float.h>
#include <limits.h>

main(int argc, char *argv[])
{

  int    iter,i,i1,j,n,k,dimension,n_max,level;
  double ii1,init_snr,final_snr,inc_snr,eb_no_db,es_no,P1,P2;
  double sum,sum1,sum2,sumj,aux,beta,rate,c1,jaux,d12;
   
  int d_hi[128];
  double d_h[128],n_d[128],fade[128];
  char name1[40],name2[40];
   
  double delta1,delta2,average,sed,prod;
   
  FILE *fp,*fp1;

  // Command line processing
  if (argc != 8)
    {
      printf("Usage: %s length(n) dimension(k) file_weight_dist bound_file init_snr final_snr inc_snr\n",argv[0]);
      exit(0);
    }

  sscanf(argv[1],"%d", &n);
  sscanf(argv[2],"%d", &k);
  sscanf(argv[3],"%s", name1);
  sscanf(argv[4],"%s", name2);
  sscanf(argv[5],"%lf", &init_snr);
  sscanf(argv[6],"%lf", &final_snr);
  sscanf(argv[7],"%lf", &inc_snr);

  rate = (float) k / (float) n;

  fp1 = fopen(name1,"r");

  n_max = 0;
  while(fscanf(fp1,"%d %lf\n",&d_hi[n_max],&n_d[n_max])!=EOF)
    n_max++;
  fclose(fp1);

  printf("Weight distribution:\n");
  for (i=0; i<n_max; i++)
    printf("%d %lf\n", d_hi[i], n_d[i]);
  printf("\n");

  fp = fopen(name2,"w");
  for (i=0;i<n_max;i++)
    d_h[i] = (double) d_hi[i];

  // Union bound without CSI
  for (eb_no_db = init_snr; eb_no_db<=final_snr; eb_no_db+=inc_snr)
    {
      es_no = pow(10.0,(eb_no_db/10.0));   /* snr per bit */
      es_no = es_no*rate;                  /* snr per symbol */
      sum = 0.0;
      for (i=0;i<n_max;i++)
      {
        // sum += ( (n_d[i]/2.0) * pow( (1.0/(2.0*es_no)), d_h[i]) ); // Wilson
        sum += ( n_d[i] * pow( (1.0/es_no), d_h[i]) ); // Biglieri
      }
      printf("%f\t%e\n",eb_no_db,sum);
      fprintf(fp, "%f\t%e\n",eb_no_db,sum);
      fflush(stdout);
      fflush(fp);
    }

 }


⌨️ 快捷键说明

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