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

📄 mealy.c

📁 这是一个c++编写的WCDMA链路采用RAKE接收的方针源代码
💻 C
字号:
/* | | Copyright disclaimer: |   This software was developed at the National Institute of Standards |   and Technology by employees of the Federal Government in the course |   of their official duties. Pursuant to title 17 Section 105 of the |   United States Code this software is not subject to copyright |   protection and is in the public domain. | |   We would appreciate acknowledgement if the software is used. |*//* | Project:     WCDMA simulation environment | Module:      Convolutional encoder | Author:      C. Britton Rorabaugh | Date:        January 12, 1999 | | History: |              January 12, 1999 Tommi Makelainen |                      Modified Rorabaugh's example code |			to rate 1/3 code with constraint length |			K=9 (i.e. length of memory shift register). | */#include <stdlib.h>#include <math.h>#include <ctype.h>#include <string.h> #include <stdio.h>#include "utility.h"   #include "mealy.h"#include "errormsg.h"/* ------------------------------------------------------------------ *//* * Function:  MealyEncoder_R1o3_Init * Desc.:     Initializes Mealy encoder for R=1/3, K=9 convolutional code. * */void MealyEncoder_R1o3_Init(          MealyEncoder* this,  /* IN/OUT: encoder data */          int num_stages,      /* IN: levels in trellis */          int gen_poly_1,      /* IN: gen. polynomial 1 */          int gen_poly_2,      /* IN: gen. polynomial 2 */          int gen_poly_3       /* IN: gen. polynomial 3 */ 		        ){  int shift_register;  int num_states;  int current_state, input;  int output_1, output_2, output_3, output;  int input_bit;  num_states = IntPower(2, num_stages-1);  this->Max_Input = 1;  this->Max_State = num_states-1;  for(current_state=0; current_state<num_states; current_state++) {      for(input=0; input<=1; input++) {	shift_register = current_state;	input_bit = input<<(num_stages-1);	shift_register +=input_bit;	output_1 = Parity(gen_poly_1 & shift_register);	output_2 = Parity(gen_poly_2 & shift_register);	output_3 = Parity(gen_poly_3 & shift_register);	output = (output_1<<2) + (output_2<<1) + output_3;	this->Output_Symbol[current_state][input] = output;	this->Next_State[current_state][input] = shift_register>>1;	printf("state = %d  input = %d  out = %d  next = %d\n", current_state,			input, output, this->Next_State[current_state][input]);      } /* end of input loop  */  } /* end of current_state loop */  return;} /* MealyEncoder_R1o3_Init *//* ------------------------------------------------------------------ *//* * Function:  MealyEncoder_R1o2_Init * Desc.:     Initializes Mealy encoder for R=1/2,K=9 convolutional code. * */void MealyEncoder_R1o2_Init(           MealyEncoder* this, /* IN/OUT: encoder data */	   int num_stages,     /* IN: convolutional encoder memory length */	   int gen_poly_1,     /* IN: gen. polynomial 1 */	   int gen_poly_2)     /* IN: gen. polynomial 2 */{  int shift_register;  int num_states;  int current_state, input;  int output_1, output_2, output;  int input_bit;  num_states = IntPower(2, num_stages-1);  this->Max_Input = 1;  this->Max_State = num_states-1;  for(current_state=0; current_state<num_states; current_state++) {      for(input=0; input<=1; input++) {	shift_register = current_state;	input_bit = input<<(num_stages-1);	shift_register +=input_bit;	output_1 = Parity(gen_poly_1 & shift_register);	output_2 = Parity(gen_poly_2 & shift_register);	output = (output_1<<1) + output_2;	this->Output_Symbol[current_state][input] = output;	this->Next_State[current_state][input] = shift_register>>1;	printf("state = %d  input = %d  out = %d  next = %d\n", current_state,			input, output, this->Next_State[current_state][input]);      } /* end of input loop  */  } /* end of current_state loop */  return;};/* ------------------------------------------------------------------ *//* * Function:  MealyEncoder_GetNextState * Desc.:     Get the next state in the trellis. * */int MealyEncoder_GetNextState(	MealyEncoder* this,				int current_state,				int input){  if (input< 0 || input > this->Max_Input) {     printf("MealyEncoder::GetNextState, bad value for argument 'input'\0");  }  if (current_state < 0 || current_state > this->Max_State) {     printf(	"MealyEncoder::GetNextState, bad value for argument 'current_state'\0");  }  return(this->Next_State[current_state][input]);}; /* ------------------------------------------------------------------ *//* * Function:  MealyEncoder_GetOutput * Desc.:     Get the output for the state transition. * */int MealyEncoder_GetOutput(          MealyEncoder* this,    /* IN: encoder status information */          int current_state,     /* IN: current status in trellis */          int input)             /* IN: input bit to shift register */{  if (input<0 || input >this->Max_Input) {	printf("in MealyEncoderOutput, bad value for argument 'input'\0");  }  if (current_state < 0 || current_state > this->Max_State) {	printf(   	"MealyEncoderOutput, bad value for argument 'current_state'\0");  }  return(this->Output_Symbol[current_state][input]);} /* MealyEncoder_GetOutput *//* ------------------------------------------------------------------ *//* * Function:  MealyEnc_InByte_GetOutput * Desc.:     Get the output byte for an input byte. * */int MealyEnc_InByte_GetOutput(	MealyEncoder* this,				int current_state,				int input[],				int output[]){  int i;#define BYTE_IN_BITS 8  for (i=0; i < BYTE_IN_BITS; i++) {    output[i] = this->Output_Symbol[current_state][ input[i] ];  }  return(0);}; /* ------------------------------------------------------------------ *//* * Function:  MealyEncoder_GetTransitionTrigger * Desc.:     Get an input that can create transition from *            'previous_state' to 'current_state'. * */int MealyEncoder_GetTransitionTrigger(          MealyEncoder* this,     /* IN: encoder status info */          int previous_state,     /* IN: previous state in trellis */          int current_state)      /* IN: current state in trellis */{  int i;  if (previous_state < 0 || previous_state > this->Max_State)    printf(       "in MealyEncoderOutput, bad value for argument 'previous_state'\0");  if (current_state < 0 || current_state > this->Max_State)    printf(   	"in MealyEncoderOutput, bad value for argument 'current_state'\0");  for(i=0; i<=1; i++) {	if(this->Next_State[previous_state][i] == current_state) {		return(i);	}  }             printf("Trigger not found for desired transition");  return(-1);} /* MealyEncoder_GetTransitionTrigger *//* ------------------------------------------------------------------ */

⌨️ 快捷键说明

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