📄 convenc.c
字号:
/* | Project: WCDMA simulation environment | Module: Convolutional encoder | Author: Tommi Makelainen | Date: January 12, 1999 | | History: | January 12, 1999 Tommi Makelainen | Modified C. Britton Rorabaugh's example code | to rate 1/3 and 1/2 codes with constraint length | K=9 (i.e. length of memory shift register). | | 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. | */#include <stdlib.h>#include <math.h>#include <ctype.h>#include <string.h> #include <stdio.h>#include "utility.h" #include "mealy.h"#include "errormsg.h"#include "config_wcdma.h"/* ------------------------------------------------------------------- *//* * Function: wcdma_R1o3_k9_conv_init * Desc.: Extract given single bit value from a given byte. * * Note: * Generator polynomial are handled as bit masks. */void wcdma_R1o3_k9_conv_init( MealyEncoder* this, /* IN: data store for transitions */ int num_stages, /* IN: length of shift register */ int gen_poly_1, /* IN: gen. polynomial for output 1 */ int gen_poly_2, /* IN: gen. polynomial for output 2 */ int gen_poly_3 /* IN: gen. polynomial for output 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;#ifdef WCDMA_DEBUG_OUTPUT printf("state = %d input = %d out = %d next = %d\n", current_state, input, output, this->Next_State[current_state][input]);#endif /* WCDMA_DEBUG_OUTPUT */ } /* end of input loop */ } /* end of current_state loop */ return;};/* ------------------------------------------------------------------- *//* * Function: wcdma_R1o3_k9_conv_enc * Desc.: Perform convolutional encoding for input vector. * * Note: */int wcdma_R1o3_k9_conv_enc( MealyEncoder* this, /* IN: encoder data */ int input_size, /* IN: input vector len */ int input[], /* IN: input data */ int output[], /* OUT: output data */ int tail[]) /* OUT: tail bits */{ int i, current_state, out_index, tail_len, index; current_state = 0; for (i=0; i < input_size; i++) { index = input[i]; output[i] = this->Output_Symbol[current_state][index]; current_state = this->Next_State[current_state][index]; out_index = i; } tail_len = CONVOLUTION_TAIL_LEN; for (i=0; i < tail_len; i++) { /* tail[i] = 0; */ tail[i] = (current_state >> i) & 0x1; } return(0);}; /* ------------------------------------------------------------------- *//* * Function: wcdma_R1o2_k9_conv_init * Desc.: Initialize convolutional coder 1/2 memory length 9. * * Note: * Generator polynomial are handled as bit masks. */void wcdma_R1o2_k9_conv_init( MealyEncoder* this, /* IN: data store for transitions */ int num_stages, /* IN: length of shift register */ int gen_poly_1, /* IN: gen. polynomial for output 1 */ int gen_poly_2 /* IN: gen. polynomial for output 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;#ifdef WCDMA_DEBUG_OUTPUT printf("state = %d input = %d out = %d next = %d\n", current_state, input, output, this->Next_State[current_state][input]);#endif /* WCDMA_DEBUG_OUTPUT */ } /* end of input loop */ } /* end of current_state loop */ return;};/* ------------------------------------------------------------------- *//* * Function: wcdma_R1o2_k9_conv_enc * Desc.: Perform convolutional encoding 1/2 for input vector. * * Note: */int wcdma_R1o2_k9_conv_enc( MealyEncoder* this, /* IN: encoder data */ int input_size, /* IN: input vector len */ int input[], /* IN: input data */ int output[], /* OUT: output data */ int tail[]) /* OUT: tail bits */{ int i, current_state, out_index, tail_len, index; current_state = 0; for (i=0; i < input_size; i++) { index = input[i]; output[i] = this->Output_Symbol[current_state][index]; current_state = this->Next_State[current_state][index]; out_index = i; } tail_len = CONVOLUTION_TAIL_LEN; for (i=0; i < tail_len; i++) { tail[i] = (current_state >> i) & 0x1; } return(0);}; /* ------------------------------------------------------------------- */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -