// ------------------------------------------------------------------------ // File: generate_trellis_nsc.c // Date: April 1, 2002 // Description: Generate trellis data of a rate-1/n convolutional encoder // of memory m // ------------------------------------------------------------------------ // 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, OUT_SYM, NUM_TRANS; main(int argc, char *argv[]) { register int i, j, k, signal; 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=0; i--) { if ( (output >> i) & 1 ) signal = -1; // if bit = 1 else signal = +1; // if bit = 0 fprintf(fp2," %2d", signal); } fprintf(fp2,"\n"); } } fclose(fp2); } void encoder2() { /* Conventional convolutional encoder, rate 1/n */ register int i, j, result, temp; temp = memory2; output = 0; temp = (temp<<1) ^ ( data2 & 0x01 ); for (i=0; i=0; j--) result ^= ( ( temp & g2[i][0] ) >> j ) & 1; output = ( output<<1 ) ^ result; } state = temp & (NUMSTATWO-1); }