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

📄 generate_trellis_rsc.c

📁 实现了二进制卷积码的viterbi硬判
💻 C
字号:
// ------------------------------------------------------------------------
//
//         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 <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, 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<n2; j++)
    fscanf(fp1, "%x", &g2[j][0]);
  fclose(fp1);

  NUMSTATWO = 1;
  for (i=0;i<m2;i++) NUMSTATWO *= 2;
  NUMSTATWO2 = 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 (i=0; i<2; i++) printf("%d --> %x\n", i, g2[i][0]);
  for (memory2=0; memory2<NUMSTATWO; memory2++)
    {
      for (data2=0; data2<2; data2++)
	{
	  fprintf(fp2,"%2d %2d", memory2, data2 );
	  /* Encoding */
	  encoder2();
	  fprintf(fp2, " %2d  ", state);
	  for (i=k; i >=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);
}

⌨️ 快捷键说明

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