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

📄 s_chcoding.c

📁 这是一个c++编写的WCDMA链路采用RAKE接收的方针源代码
💻 C
字号:
/* | Project:     WCDMA simulation environment | Module:       | Author:       | Date:        February, 1999 | | History: |              March 11,  1999 Maarit Melvasalo  |                      Comments added  |		March 18, 1999 Maarit Melvasalo  |			Added possibility to use more than one encoder |			at the same time.  |              May 10, 1999  Maarit Melvasalo  |                      Cleaning up |              May 23, 1999 Maarit Melvasalo |                      Interleaver separated from channel coding |                      see s_interleaver.c * *  File    : s_chcoding.c *  Abstract: * * USER GIVEN PARAMETERS * * 1: B   = Size of real input vector (= packet size)  * 2: gen_poly_1  = generator polynomials for 3GPP FDD mode convolutional coder * 3: coder type * 4: coding gain  * 5: tail length  * 6: Number of frames in input block * * Inputs: *        Uncoded input bits with CRC bits *        Length of the input vector  *                * Outputs:  *        Decoded bits with CRC bits         * * DEPENDS ON FILES  *            chcoding.c  *            metrics.c  *            convenc.c  *            mealy.c   *            bitroutines.c *            conversions.c   *            utility.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. | */#define S_FUNCTION_NAME s_chcoding#define S_FUNCTION_LEVEL 2#include <math.h>#include <stdio.h>#include <string.h>#include "config_wcdma.h"#include "wcdma_simulink.h"#include "mealy.h"#include "simstruc.h"#include "tmwtypes.h"/* USER GIVEN PARAMETERS AND DEFINITIONS /**//*Number of inputs and outputs/**/#define NINPUTS   2#define NOUTPUTS  2/* Number of user given parameters/**/  #define NPARAMS 6  /* Pointers to Input Ports */#define U(element) (*uPtrs[element])        #define N(element) (*nPtrs[element])        /* Input and Output Size parameters /**/#define B_PARAM(S) ssGetSFcnParam(S,0)           /* Generator polynomials for 3GPP FDD mode convolutional coder/**/ #define gen_poly_PARAM(S) ssGetSFcnParam(S,1) /* Channel coding type and coding ratio and tail length /**/#define coder_type(S) ssGetSFcnParam(S,2)   #define coding_gain(S) ssGetSFcnParam(S,3)  #define tail_length(S) ssGetSFcnParam(S,4)  #define nGain (int_T)(mxGetPr(coding_gain(S))[0]) #define nTail (int_T)(mxGetPr(tail_length(S))[0]) /* Number of frames in one block/**/#define frame(S) ssGetSFcnParam(S,5)   #define nFrames (int_T)(mxGetPr(frame(S))[0]) /* input and output vector sizes/**/#define nInputs (int_T)(mxGetPr(B_PARAM(S))[0])   #define nOutputs nInputs * nGain            /* Sampletime -- defined in config_cdma /**/#define td  nFrames *TD_FRAME              /*===================================================================* * S-function methods * *===================================================================*//* Function: mdlInitializeSizes =============================================== * Abstract: *    The sizes information is used by Simulink to determine the S-function *    block's characteristics (number of inputs, outputs, states, etc.). */static void mdlInitializeSizes(SimStruct *S){ /* Number of expected parameters */  ssSetNumSFcnParams(S, NPARAMS);   if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S))  {      return; }   /* Initialize the input and output port sizes/**/     if (!ssSetNumInputPorts(S, NINPUTS)) return;    ssSetInputPortWidth(S, 0, nInputs);    ssSetInputPortWidth(S, 1, 1);    ssSetInputPortDirectFeedThrough(S, 0, 1);    ssSetInputPortDirectFeedThrough(S, 1, 1);    if (!ssSetNumOutputPorts(S, NOUTPUTS)) return;    ssSetOutputPortWidth(S, 0, nOutputs);    ssSetOutputPortWidth(S, 1, nTail);   /* Initialize number of sample times and simulink work vectors /**/    ssSetNumSampleTimes(S, 1);    ssSetNumIWork(S, nTail + 1); /* last is the encoder instant number/**/    /* To Speeds up the simulations/**/    ssSetSFcnParamNotTunable(S,0);     ssSetSFcnParamNotTunable(S,1);     ssSetSFcnParamNotTunable(S,2);      ssSetSFcnParamNotTunable(S,3);      ssSetSFcnParamNotTunable(S,4);      ssSetSFcnParamNotTunable(S,5);      /* Take care when specifying exception free code - see sfuntmpl.doc */    ssSetOptions(S, 0); }   /* Function: mdlInitializeSampleTimes ========================================= * Abstract: *    Specifiy the sample time */static void mdlInitializeSampleTimes(SimStruct *S){  ssSetSampleTime(S, 0, td);     ssSetOffsetTime(S, 0, 0.0);}#define MDL_INITIALIZE_CONDITIONS/* Function: mdlInitializeConditions ======================================== * Abstract: *         initializes the tail vector *         Initializes the encoder *         Returns the encoder instance number */static void mdlInitializeConditions(SimStruct *S){    InputRealPtrsType nPtrs = ssGetInputPortRealSignalPtrs(S,1);    int_T             *iwork = ssGetIWork(S);    int_T             cType = (int_T)(mxGetPr(coder_type(S))[0]);     real_T            *gen_polys = mxGetPr(gen_poly_PARAM(S));    int_T             i,decission;    int_T             nPoly = (int_T)(mxGetN(gen_poly_PARAM(S)));    int_T             polys[10];    int_T             size = (int_T)N(0);    for (i = 0; i < nTail; i++){      iwork[i] = 0;    }    for (i = 0; i < nPoly; i++){      polys[i] = (int_T)gen_polys[i];    }    /*        hard decission  has been set here        /**/    decission = 0;    iwork[nTail]  =           wcdma_chcoding_init(cType,decission,nGain,polys,size);    /*        if encoder initialization was not succesfull       iwork[nTail] == -1 /**/}/* Function: mdlOutputs ======================================================= * Abstract: * *  */static void mdlOutputs(SimStruct *S, int_T tid){    real_T            *y    = ssGetOutputPortRealSignal(S,0);    real_T            *tail    = ssGetOutputPortRealSignal(S,1);    InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0);    InputRealPtrsType nPtrs = ssGetInputPortRealSignalPtrs(S,1);    int_T             cType = (int_T)(mxGetPr(coder_type(S))[0]);     int_T             out[nOutputs];     int_T             data[nInputs];     int_T             *iwork = ssGetIWork(S);    int_T             lp;    int_T             size = (int_T)N(0);    /* if encoder initialization was succesfull/**/    if( iwork[nTail] > -1 ){       for (lp = 0; lp < size; lp++){	data[lp] = (int_T)U(lp);      }            lp = wcdma_chcoding_enc(cType, nGain, data, size, out, iwork, iwork[nTail]);		             /* int inputs[],	/* input bit vector */                             /* int nInputs,	/* input vector size */      /* int cols,	/* rows in block interleaver */      /* int rows,	/* columns in block interleaver */      /* int outputs[],	/* output bit vector */      /* int tail[])	/* tail bits */      /* int instance_no) /* number of channel coder */      for (lp = 0; lp < nGain * size; lp++){  	y[lp] = out[lp];      }      /* Tail is given out separately /**/      for (lp = 0; lp < nTail; lp++){ 	tail[lp] = iwork[lp];      }    } }/* Function: mdlTerminate ===================================================== * Abstract: *    At the end of simulation the encoder init is freed. */static void mdlTerminate(SimStruct *S){  int_T             *iwork = ssGetIWork(S);     int_T tmp;  if( iwork[nTail] > -1)    tmp = wcdma_chcoding_free(iwork[nTail]);/**/}#ifdef  MATLAB_MEX_FILE    /* Is this file being compiled as a MEX-file? */#include "simulink.c"      /* MEX-file interface mechanism */#else#include "cg_sfun.h"       /* Code generation registration function */#endif

⌨️ 快捷键说明

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