// ------------------------------------------------------------------------ // File: simulation313.c // // Simulation of a repetition code 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 #include #define MAXRAND LONG_MAX // Maximum value of random() #define N 3 // Code length #define TWOTTN 3 // Equal to 2^{N-1}-1 main(int argc, char *argv[]) { long seed; double init_p, final_p, inc_p; double sim, num_sim; double p; int codeword[N], received[N], decoded[N]; double error; int i, info, estimate, onescount; FILE *fp; char name[80]; if (argc != 7) { printf("Usage: %s seed init_p final_p inc_p num_sim output_file\n", argv[0]); exit(0); } sscanf(argv[1],"%ld", &seed); sscanf(argv[2],"%lf", &init_p); sscanf(argv[3],"%lf", &final_p); sscanf(argv[4],"%lf", &inc_p); sscanf(argv[5],"%lf", &num_sim); sscanf(argv[6],"%s", &name); fp = fopen(name,"w"); srandom(seed); p = init_p; while (p < final_p) { error = 0.0; sim = 0.0; while (sim < num_sim) { // SOURCE: Generate random symbols info = (random()>>10) % 2; // ENCODER: Encode information if (info) { for (i=0; i N/2) { estimate = 1; for (i=0; i