📄 bound_awgn_ebno.c
字号:
// ------------------------------------------------------------------------
// File: bound_awgn_ebno.c
//
// Union bound on the probability of a bit error for a linear code
// with soft-decision decoding and binary transmission over an
// AWGN channel
// ------------------------------------------------------------------------
// 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(argc,argv)
int argc;
char **argv;
{
double delta1,delta2,nn,nn2,nn3;
int iter,i,i1,j,n,k,k2,k3,dimension,n_max,n_max2,n_max3;
double ii1,init,final,inc,eb_no_db,es_no,P1,P2;
double sum,sum1,sum2,sum3,aux,beta,rate,c1,jaux,d12;
int d_hi[64];
double d_h[64],n_d[64];
int d_hi2[64];
double d_h2[64],n_d2[64];
char name1[40],name2[40];
int d_hi3[64];
double d_h3[64],n_d3[64];
double Q(double a);
double erfc( double x );
FILE *fp,*fp1,*fp2,*fp11,*fp22,*fp33;
if (argc != 8)
{
printf("Usage: %s n k wdfile file_bound init_SNR final_SNR inc_SNR\n",
argv[0]);
exit(1);
}
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);
sscanf(argv[6], "%lf", &final);
sscanf(argv[7], "%lf", &inc);
rate = (double) k / (double) n;
fp1 = fopen(name1,"r");
fp11 = fopen(name2,"w");
n_max = 0;
while(fscanf(fp1,"%d %lf\n",&d_hi[n_max],&n_d[n_max])!=EOF)
{
n_max++;
}
fclose(fp1);
#ifdef DEBUG
printf("Weight distribution (scrambled):\n");
for (i=0; i<n_max; i++)
printf("%d %lf\n", d_hi[i], n_d[i]);
#endif
printf("\nEb/No \tPb\n");
for (i=0;i<n_max;i++)
d_h[i] = (double) d_hi[i];
/* Compute the union bound */
for (eb_no_db = init; eb_no_db<=final; eb_no_db+=inc)
{
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 += ( (d_h[i]/n) * n_d[i] // <--- Uncomment this for Pb
sum += ( n_d[i] // <--- Uncomment this for Pe
* Q ( sqrt( 2.0 * es_no * d_h[i] ) ) );
}
printf("%lf\t%e\n",eb_no_db,sum);
fprintf(fp11,"%lf\t%e\n",eb_no_db,sum);
}
}
double Q(double a)
{
double erfc( double x );
return(0.5*erfc(a/sqrt(2.0)));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -