// ------------------------------------------------------------------------ // File: bound_pe.c // // Union bound on the word error probability of a binary linear code with // transmission over a binary symmetric 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 #include #define NMAX 1024 // Maximum code length main(argc,argv) int argc; char **argv; { int n; int t; double a[NMAX+1]; // Weight distribution double p, Pc; int i; double nd, id; double fact(double a); double comb(double a, double b); char name1[80], name2[80]; FILE *fp1,*fp2; if (argc != 4) { printf("Usage: %s n t file_Pe\n", argv[0]); exit(1); } sscanf(argv[1], "%d", &n); sscanf(argv[2], "%d", &t); sscanf(argv[3], "%s", name1); fp1 = fopen(name1,"w"); p = 1.0e-05; while (p<0.5) { Pc = 0.0; for (i=0; i<=t; i++) { nd = (double) n; id = (double) i; Pc += comb(nd,id) * pow(p,id)*pow((1.0-p),(nd-id)); } fprintf(fp1,"%e %e\n", p, 1.0-Pc); p += 1.0e-05; } } 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 comb(double a,double b) { double z,tot; if (a (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); }