/* GLOBECOM PAPER SCHEME # 1 * File: main_4_2_0.c * Date: August 17, 1996 * ---------------------------------------------------------------------- * Simulation of block coded 8PSK modulation using BCH codes of length 64 * To achieve graceful degradation over a satellite (AWGN) channel * (for the 5th Mini-Conference in Communication Theory, GLOBECOM'96) * ---------------------------------------------------------------------- * * C_1 : (64,18,22) BCH code * C_2 : (64,45, 8) BCH code * C_3 : (64,63, 2) code * * Ordered statistics soft-decision decoding of the BCH codes, from Marc * Fossorier routines. * * Order-4 soft-decision of C1 : BCH(64,18,22) * Order-2 soft-decision of C2 : BCH(64,45, 8) * Order-0 soft-decision of C3 : BCH(64,63, 2) */ // ------------------------------------------------------------------------ // 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 #include #include "def3.h" /* #define NO_NOISE /* */ /* #define PRINT_DETAILS /* */ /* #define DEBUG /* */ #define WATCHIT /* */ #define n 64 /* Code length */ #define k1 18 /* Dimension first code */ #define k2 45 /* Dimension second code */ #define k3 63 /* Dimension third code */ #define RATE 1.96875 /* R = (18+51+63)/64 */ #define MAXRAND LONG_MAX /* for random number generation */ #define NUMSIM 1000 /* no. simulations per 100 codewords */ #define INIT 12.0 #define LIMIT 13.0 #define INC 0.5 /* Constant used in preprocessing for third stage */ #define SQR2 0.7071067812 /* sqrt(2)/2 */ main() { unsigned iloop, inner; unsigned int codeword1[n], codeword2[n], codeword3[n]; unsigned int mess_one, mess_three; unsigned int message1[k1], message2[k2], message3[k3]; unsigned int seed; unsigned int word[n], estimate1[n], estimate2[n], estimate3[n]; unsigned int result, ytest; int error1, error2, error3; int G1[k1][n]; /* Generator matrix of BCH (64,18,22) */ int G2[k2][n]; /* Generator matrix of BCH (64,45, 8) */ int G3[k3][n]; /* Generator matrix of BCH (64,63, 2) */ double rx[n], ry[n], rx3[n], ry3[n]; double amp; double pi = M_PI; double error_one =0.0, error_two = 0.0, error_three = 0.0; double q[2][8]; double rndm, u1, u2, s, x1, x2, aux, br; double snr, pe, pe1, pe2, pe3; register int i,j; int fflush(); long int count_even = 0, count_odd = 0; /* Variables for soft-decision based on ordered statistics. */ double out_D[N]; /* Decoded word: {-1,1} --> {0,1} */ double out_D2[N]; /* Decoded word: {-1,1} --> {0,1} */ double out_D3[N]; /* Decoded word: {-1,1} --> {0,1} */ void order4_dec(); /* Order-4 decoding of C1 : BCH(64,18,22) */ void order2_dec2(); /* Order-2 decoding of C2 : BCH(64,45, 8) */ void order0_dec3(); /* Order-0 decoding of C3 : BCH(64,63, 2) */ /* data file pointers */ FILE *fp1, *fp2, *fp3; /* READ GENERATOR MATRIX OF BCH(64,18,22) CODE */ fp1 = fopen("generator_641822.data","r"); printf("\nGenerator matrix of BCH(64,18,22):\n"); for (i=0; i BLOCK PARTITIONING (BP) Label: (b1,b2,b3) b1: Selects right/left half plane b2: Selects upper/lower half plane b3: Selects signal in a quadrant | 100 o | o 000 | 101 o | o 001 | ----------------------- | 111 o | o 011 | 110 o | o 010 | */ q[0][0]=amp*cos(3.0*pi/8.0); q[1][0]=amp*sin(3.0*pi/8.0); /* 000 3pi/8 */ q[0][1]=amp*cos(pi/8.0); q[1][1]=amp*sin(pi/8.0); /* 001 pi/8 */ q[0][2]=amp*cos(3.0*pi/8.0); q[1][2]=-amp*sin(3.0*pi/8.0); /* 010 -3pi/8 */ q[0][3]=amp*cos(pi/8.0); q[1][3]=-amp*sin(pi/8.0); /* 011 - pi/8 */ q[0][4]=-amp*cos(3.0*pi/8.0); q[1][4]=amp*sin(3.0*pi/8.0); /* 100 5pi/8 */ q[0][5]=-amp*cos(pi/8.0); q[1][5]=amp*sin(pi/8.0); /* 101 7pi/8 */ q[0][6]=-amp*cos(3.0*pi/8.0); q[1][6]=-amp*sin(3.0*pi/8.0); /* 110 -5pi/8 */ q[0][7]=-amp*cos(pi/8.0); q[1][7]=-amp*sin(pi/8.0); /* 111 -7pi/8 */ for (iloop=0; iloop>10)&01; /* BCH (64,18,22) codeword */ for (j=k1; j>10)&01; /* BCH (64,45,8) codeword */ for (j=k2; j>10)&01; if (codeword3[j]) count_odd++; else count_even++; } /* BCH (64,63,2) codeword */ for (j=k3; j= 1 ); x1 = u1 * sqrt( (-2.0*log(s))/s ); x2 = u2 * sqrt( (-2.0*log(s))/s ); br = sqrt(x1*x1 + x2*x2); /* Rayleigh fading component */ #else br = 1.0; do { rndm = (double)(random())/MAXRAND; u1 = rndm * 2 - 1.0; rndm = (double)(random())/MAXRAND; u2 = rndm * 2 - 1.0; s = u1 * u1 + u2 * u2; } while( s >= 1 ); x1 = u1 * sqrt( (-2.0*log(s))/s ); /* Gaussian component */ x2 = u2 * sqrt( (-2.0*log(s))/s ); /* Gaussian component */ /* Received (complex) signal */ aux = 2.0 * (double)word[j] * pi / 8.0 ; rx[j] = br * q[0][word[j]] + x1 ; /* */ ry[j] = br * q[1][word[j]] + x2 ; /* */ #endif #ifdef NO_NOISE rx[j] = q[0][word[j]] ; /* */ ry[j] = q[1][word[j]] ; /* */ #endif /* Save received symbols for third stage decoding */ rx3[j] = rx[j]; ry3[j] = ry[j]; #ifdef DEBUG printf("%1d%1d%1d: rx[%d]=%lf, ry[%d]=%lf\n", codeword1[j],codeword2[j],codeword3[j], j,rx[j],j,ry[j]); #endif } /* ******************************************************************** ORDERED STATISTICS DECODING ******************************************************************** */ /* ------------- FIRST STAGE ------------ */ /* Order-4 soft-decision decoding of C1 : BCH(64,18,22) */ order4_dec(G1,rx,out_D); /* Map {+1,-1} ---> {1,0} (2*bit - 1) */ for (j=0; j {1,0} using (2*bit - 1) */ for (j=0; j {1,0} (2*bit - 1) */ for (j=0; j