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

📄 chcoding.c

📁 这是一个c++编写的WCDMA链路采用RAKE接收的方针源代码
💻 C
字号:
/* | Project:     WCDMA simulation environment | Module:      Channel coding combinary block. | Author:      Tommi Makelainen  | Date:        February 11, 1999 | | History: |              February 11, 1999 Tommi Makelainen |                      Initial version. |		March 18, 1999 Tommi Makelainen |			Added possibility to use more than one encoder |			at the same time.  |		May 23, 1999 Tommi Makelainen |			Extracted interleaver. |                      Added possibility to have many types |                      of channel coding methods (conv. or Turbo). | | 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 <stdio.h>#include <math.h>#include "conversions.h"#include "bitroutines.h"#include "config_wcdma.h"#include "mealy.h"#include "errormsg.h"#include "metrics.h"#include "convenc.h"#include "interleaver.h"static enum instance_state chenc_alloc_list[MAX_CH_CODERS];static MealyEncoder *encoders[MAX_CH_CODERS];static int *conv_symbols[MAX_CH_CODERS];static int *conv_bits[MAX_CH_CODERS];static int instance_count = 0;static int general_init_flag = FALSE;/* * generator polynomials for 3GPP FDD mode convolutional coder *   gen_poly_1 = 0x16f;  557 octal *   gen_poly_2 = 0x1b3;  663 octal *   gen_poly_3 = 0x1c9;  711 octal *//* -------------------------------------------------------------------- *//* * Function:    wcdma_chcoding_init * Desc.:       Channel encoding initialization. * * Returns:     => 0 allocated instance number, -1 if no free encoders. * * Note: *              Generator polynomials are given as bit masks, *              i.e. 0x5 = 101 in binary = x^2 + 1 in polynomial form. */int wcdma_chcoding_init(int coder_type,    /* IN: 1=conv., 2=turbo */                        int metric_type,   /* IN: 0=hard, 1=soft */                        int coding_ratio,  /* IN: 2 = 1/2 or 3 = 1/3 */                        int gen_polys[],   /* IN: generator polynomials */                        int input_size)    /* IN: size of input vector */{    int instance;    if (coder_type == 1) { /* convolution */        if (coding_ratio == 2) {            instance = wcdma_convcoding_init(coding_ratio, metric_type,                       gen_polys[0], gen_polys[1], gen_polys[2], input_size);        } else if (coding_ratio == 3) {            instance = wcdma_convcoding_init(coding_ratio, metric_type,                       gen_polys[0], gen_polys[1], gen_polys[2], input_size);        }    } else if (coder_type == 2) { /* turbo */        printf("Turbo coding is not available.\n");        return(-1);    } else {        return(-1);    }    return(instance);} /* wcdma_chcoding_init *//* -------------------------------------------------------------------- *//* * Function:    wcdma_convcoding_init * Desc.:       Convolutional coding initialization. * * Returns:     => 0 allocated instance number, -1 if no free encoders. * * Note: *              Generator polynomials are given as bit masks, *              i.e. 0x5 = 101 in binary = x^2 + 1 in polynomial form. */int wcdma_convcoding_init(int coding_ratio,  /* IN: 2 = 1/2, 3 = 1/3 */                          int metric_type,   /* IN: 0=hard, 1=soft */                          int gen_poly_1,    /* IN: 1st generator polynomial */                          int gen_poly_2,    /* IN: 2nd generator polynomial */                          int gen_poly_3,    /* IN: 3rd generator polynomial */                          int input_size)    /* IN: size of input vector */{    int num_encode_stages;    int *conv_output_symbs, *conv_output_bits;    int instance, i;    MealyEncoder *encoder;    /*     * Allocate new channel coder data structures.     */    if (instance_count < MAX_CH_CODERS) {      /*       * If first call, initialize static data.       */      if (general_init_flag == FALSE) {          for (i=0; i < MAX_CH_CODERS; i++) {              chenc_alloc_list[i] = FREE_INSTANCE;          } /* for */          general_init_flag = TRUE;      } /* if general_init_flag */      /*       * Find first free instance number.       */      instance = -1;      for (i=0; i < MAX_CH_CODERS; i++) {          if (chenc_alloc_list[i] == FREE_INSTANCE) {              instance = i;              break;          }      }      if (instance == -1) return(-1); /* no free instances */      /*       * Allocated memory for convolutional encoder data.       */      encoder = (MealyEncoder*)calloc(1, sizeof(MealyEncoder));      /*       * Calculate all possible state transitions.       */      num_encode_stages = CONVOLUTION_TAIL_LEN+1;      if (coding_ratio == 2) {          wcdma_R1o2_k9_conv_init (encoder, num_encode_stages, gen_poly_1,                                  gen_poly_2);      } else if (coding_ratio == 3) {          wcdma_R1o3_k9_conv_init (encoder, num_encode_stages, gen_poly_1,                                  gen_poly_2, gen_poly_3);      } else {          printf("wcdma_convcoding_init: Coding ratio %d is not available.\n",                 coding_ratio);          return(-1);      }      /*       * Allocated memory for temporary convolution encoder outputs.       */      conv_output_symbs = (int*)calloc(input_size, sizeof(int));      conv_output_bits  = (int*)calloc(coding_ratio*input_size, sizeof(int));      /*       * Store instance data.       */      encoders[instance] = encoder;      conv_symbols[instance] = conv_output_symbs;      conv_bits[instance] = conv_output_bits;      instance_count++;      chenc_alloc_list[instance] = INSTANCE_IN_USE;      return(instance);    } else {      /* maximum number of channel coder structures already reserved */      return(-1);    }}/* -------------------------------------------------------------------- *//* * Function:    wcdma_chcoding_enc * Desc.:       Convolutional coding block * * Note: * 		Tail vector is 8 bits long. */int wcdma_chcoding_enc(int coder_type,  /* IN: 1=conv., 2=turbo */                       int coding_ratio,/* IN: 2 = 1/2 or 3 = 1/3 */                       int inputs[],	/* IN: input bit vector */                       int nInputs,	/* IN: input vector size */                       int outputs[],	/* OUT: output bit vector */                       int tail[],	/* OUT: tail bits */                       int instance_no) /* IN: number of channel coder */{    int i, j;    int *conv_output_symbs, *conv_output_bits;    MealyEncoder *encoder;    if (coder_type == 1) {        encoder = encoders[instance_no];        conv_output_symbs = conv_symbols[instance_no];        conv_output_bits = conv_bits[instance_no];        if (coding_ratio == 2) {            wcdma_R1o2_k9_conv_enc(encoder, nInputs,                                   inputs, conv_output_symbs, tail);            j = 0;            for (i=0; i < nInputs; i++) {                outputs[j++] = ((char)conv_output_symbs[i] >> 1) & 0x1;                outputs[j++] = ((char)conv_output_symbs[i] >> 0) & 0x1;            }                    } else if (coding_ratio == 3) {            wcdma_R1o3_k9_conv_enc(encoder, nInputs,                                   inputs, conv_output_symbs, tail);            j = 0;            for (i=0; i < nInputs; i++) {                outputs[j++] = ((char)conv_output_symbs[i] >> 2) & 0x1;                outputs[j++] = ((char)conv_output_symbs[i] >> 1) & 0x1;                outputs[j++] = ((char)conv_output_symbs[i] >> 0) & 0x1;            }        } /* if coding_ratio */    } else if (coder_type == 2) {        printf("Turbo coding is not available.\n");        return(-1);    }    return(0);}/* -------------------------------------------------------------------- *//* * Function:    wcdma_chcoding_free * Desc.:       Convolutional coding and interleaving clear function. * * Note: */int wcdma_chcoding_free(int instance_no){    free(encoders[instance_no]);    free(conv_symbols[instance_no]);    free(conv_bits[instance_no]);    chenc_alloc_list[instance_no] = FREE_INSTANCE;    instance_count--;    return(0);}/* -------------------------------------------------------------------- */

⌨️ 快捷键说明

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