⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 generate_trellis_nsc.c

📁 这是和BCH码有关的源程序,前面提交过turbo码了,所以很有必要再加些BCH码的了,呵呵
💻 C
字号:
// ------------------------------------------------------------------------
//         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 <stdio.h>
#include <math.h>
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<n2; j++)
    fscanf(fp1, "%x", &g2[j][0]);
  fclose(fp1);

  NUMSTATWO = 1;
  for (i=0;i<m2;i++) NUMSTATWO *= 2;
  OUT_SYM = n2;
  NUM_TRANS = 1;
  for (i=0;i<k2;i++) NUM_TRANS *= 2;

  fp2 = fopen(name2,"w");

  fprintf(fp2, "%d %d\n", n2, m2);
  fprintf(fp2, "%d %d %d\n", NUMSTATWO, OUT_SYM, NUM_TRANS);
  for (j=0; j<n2; j++)
    fprintf(fp2, "%x\n", g2[j][0]);

  k = OUT_SYM - 1;

  for (memory2=0; memory2<NUMSTATWO; memory2++)
    {
      for (data2=0; data2<2; data2++)  // This works only for k2 = 1
	{
	  fprintf(fp2,"%2d %2d", memory2, data2 );
	  // Encoding 
	  encoder2();
	  fprintf(fp2, " %2d", state);

	  // Convert output to +1,-1 format
	  for (i=k; i >=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<n2; i++)
   {
     result = 0;
     for (j=m2; j>=0; j--)
       result ^= ( ( temp & g2[i][0] ) >> j ) & 1;
     output = ( output<<1 ) ^ result;
   }
  state = temp & (NUMSTATWO-1);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -