// ------------------------------------------------------------------------ // // File: generate_trellis_rsc.c // Date: April 1, 2002 // Description: Generate trellis of a rate-1/n recursive convolutional code // // NOTE: The input file should contain the generator polynomials as // denominator followed by numerator in the following row. // // ------------------------------------------------------------------------ // 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 int k2=1, n2, m2; // Code parameters int memory2, state; // memory contents before and after encoding int data2, output; // data bit and corresponding output bits void encoder2(void); // Encoder int g2[10][10]; int NUMSTATWO, NUMSTATWO2, OUT_SYM, NUM_TRANS; main(int argc, char *argv[]) { register int i, j, k, psk_label; char name1[40], name2[40]; FILE *fp1, *fp2; // Command line processing if (argc != 3) { printf("Usage %s file_input_parameters file_output\n", argv[0]); exit(0); } sscanf(argv[1],"%s", name1); sscanf(argv[2],"%s", name2); fp1 = fopen(name1,"r"); fscanf(fp1,"%d %d", &n2, &m2); for (j=0; j %x\n", i, g2[i][0]); for (memory2=0; memory2=0; i--) if ( (output >> i) & 1 ) fprintf(fp2,"-1 "); else fprintf(fp2," 1 "); fprintf(fp2,"\n"); } } /* end for memory2 */ fclose(fp2); } void encoder2() { /* Recursive systematic convolutional encoder, rate 1/n2 (fixed k_2=1) */ register int i, j, result, temp; output = data2; temp = 0; for (j=(m2-1); j>=0; j--) temp ^= ( ( memory2 & g2[0][0] ) >> j ) & 1; temp ^= data2; temp = ((memory2<<1) ^ temp) & (NUMSTATWO2-1); result = 0; for (j=m2; j>=0; j--) result ^= ( ( temp & g2[1][0] ) >> j ) & 1; output = ( output<<1 ) ^ result; state = temp & (NUMSTATWO-1); }