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

📄 prob_dec_error_rs.c

📁 详细讲述纠错码的书籍
💻 C
字号:
// ------------------------------------------------------------------------
// File: prob_dec_error_rs.c
//
// Compute various probabilities of decoding errors for an RS code
// ------------------------------------------------------------------------
// 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 <values.h>

  int i;
  int N,T,m;         /* Length, error correction and bits/symbol */
  double q;          /* Size of Galois field */
  double pb;         /* Input bit error probability */
  double ps;         /* Input symbol error probability */
  double pbo;        /* Output bit error probability */
  double pe;
  double comb2(double a, double b);
  double fact(double a);

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

  if (argc != 6)
    {
    printf("Usage: %s <m> <q> <N> <T> <Pb>\n", argv[0]);
    exit(1);
    }
  else
    {
    sscanf(argv[1], "%d", &m);
    sscanf(argv[2], "%lf", &q);
    sscanf(argv[3], "%d", &N);
    sscanf(argv[4], "%d", &T);
    sscanf(argv[5], "%lf", &pb);
    }

/*
  m = 6;
  q = 64;
  N = 63;
  T = 8;
  pb = 0.362;
*/

  /* Symbol error probability */
  ps = 1.0 - pow((1.0-pb), m);
  printf("Symbol error probability = %e\n", ps);

  /* Output bit error probability */
  pbo = 0.0;
  for (i = T+1; i<=N; i++)
  pbo +=((double)(i+T)/(double)N)*comb2(N,i)*pow(ps,i)*pow(1.0-ps,N-i);
  pbo *= (pow(2.0,m-1.0)/(pow(2.0,m)-1));
  printf("Output BER (approximation) = %e\n", pbo);
  
  /* Approximated probability of a decoding error */
  pe = 0.0;
  for (i=0; i<=T; i++)
    pe += comb2(N,i) * pow(q-1,i);  /* Volume of decoding sphere */
  pe *= pow(q,-2.0*T);
/*
  pe *= pow(q,-N)*(pow(q,(N-2.0*T))-1.0);
*/
  printf("P(E) ~ %e\n", pe);

}

double fact(double a)
{
    double i,tot;
    tot = 1.0;
    for (i=a;i>0.001;i=i-1.0)
    {
        tot = tot * i;
    }
    return(tot);
}

double comb2(double a,double b)
{
    double z,tot;
        if (a<b)
           return(1.0);
    if (b > (a-b))
    {
       tot = 1.0/fact(a-b);
       for (z=a;z>b;z=z-1.0)
       {
          tot = tot * z;
       }
    }
    else
    {
       tot = 1.0/fact(b);
       for (z=a;z>a-b;z=z-1.0)
       {
          tot = tot * z;
       }
    }
    return(tot);
}

⌨️ 快捷键说明

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