📄 s_chdecoding.c
字号:
/* | Project: WCDMA simulation environment | Module: | Author: | Date: February, 1999 | | History: | March 11, 1999 Maarit Melvasalo | Comments added | May 10, 1999 Maarit Melvasalo | Cleaning up | May 27, 1999 Maarit Melvasalo | Deinterleaver separated from channel decoding | see s_deinterleaver.c * * File : s_chdecoding.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 * 7: soft_prob_0 = probabilities for 0 value * 8: soft_prob_1 = probabilities for 1 value * * Inputs: * Coded recieved bits with CRC bits * Flag indicating if inputdata is valid or not * * Outputs: * Decoded bits with CRC bits * Flag indicating if inputdata is valid or not * * DEPENDS ON FILES * chdecoding.c * metrics.c * convenc.c * interleaver.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_chdecoding#define S_FUNCTION_LEVEL 2#include <math.h>#include "mealy.h"#include "simstruc.h"#include "tmwtypes.h"#include "convenc.h"#include "config_wcdma.h"#include "wcdma_simulink.h"/* USER GIVEN PARAMETERS AND DEFINITIONS /**//*Number of input and output ports/**/#define NINPUTS 2#define NOUTPUTS 2/* Number of user given parameters/**/ #define NPARAMS 8 /* Pointers to Input Ports */#define S(element) (*softPtrs[element]) #define F(element) (*fPtrs[element]) /* Input and Output Size parameters /**/#define IN_SIZE(S) ssGetSFcnParam(S,0) #define nInputs (int_T)(mxGetPr(IN_SIZE(S))[0]) /* Generator polynomials for 3GPP FDD mode convolutional coder/**/ #define gen_poly_PARAM(S) ssGetSFcnParam(S,1) #define nPoly (int_T) (mxGetN(gen_poly_PARAM(S))) /* 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]) /*number of outputs/**/#define nOutputs (int_T)((nInputs-nTail)/nGain) /* Probability parameters for hard and soft decission /**/#define soft_prob_0_PARAM(S) ssGetSFcnParam(S,6) #define soft_prob_1_PARAM(S) ssGetSFcnParam(S,7) /* length of the probability vector*/#define nSoftProbs (int_T)(mxGetN(soft_prob_0_PARAM(S))) /* 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, nSide); ssSetInputPortDirectFeedThrough(S, 0, 1); ssSetInputPortDirectFeedThrough(S, 1, 1); if (!ssSetNumOutputPorts(S, NOUTPUTS)) return; ssSetOutputPortWidth(S, 0, nOutputs ); ssSetOutputPortWidth(S, 1, nSide ); /* Initialize number of sample times and simulink work vectors /**/ ssSetNumSampleTimes(S, 1); ssSetNumIWork(S, nTail + 1); ssSetNumPWork(S, 1); /* To Speeds up the simulations/**/ ssSetSFcnParamNotTunable(S,0); ssSetSFcnParamNotTunable(S,1); ssSetSFcnParamNotTunable(S,2); ssSetSFcnParamNotTunable(S,3); ssSetSFcnParamNotTunable(S,4); ssSetSFcnParamNotTunable(S,5); ssSetSFcnParamNotTunable(S,6); ssSetSFcnParamNotTunable(S,7); /* Take care when specifying exception free code - see sfuntmpl.doc */ ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE); /* do not use mxCalloc or mexErrMsgTxt functions */} /* 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)); real_T *soft_prob_0 = mxGetPr(soft_prob_0_PARAM(S)); real_T *soft_prob_1 = mxGetPr(soft_prob_1_PARAM(S)); int_T i,tmp, decission; int_T polys[nPoly]; 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_chdecoding_init( cType,nGain,nInputs-nTail,decission,polys,soft_prob_0,soft_prob_1,nSoftProbs);}/* Function: mdlOutputs ======================================================= * Abstract: * */static void mdlOutputs(SimStruct *S, int_T tid){ real_T *y = ssGetOutputPortRealSignal(S,0); real_T *flag = ssGetOutputPortRealSignal(S,1); InputRealPtrsType softPtrs = ssGetInputPortRealSignalPtrs(S,0); InputRealPtrsType fPtrs = ssGetInputPortRealSignalPtrs(S,1); int_T cType = (int_T)(mxGetPr(coder_type(S))[0]); int_T out[nOutputs]; int_T hard[nInputs]; int_T *iwork = ssGetIWork(S); int_T lp,i; real_T soft[nInputs]; /*if there is output from previous block/**/ if( iwork[nTail] > -1 && F(0) >0 ){ /* Make the hard decission for the soft bits obtained from previous block /**/ for (i = 0; i < nInputs; i++){ hard[i] = (S(i) > 0 ? 1 : 0) ; soft[i] = S(i); } for (i = 0; i < nTail; i++){ iwork[i] = hard[i + nInputs - nTail]; } i = wcdma_chdecoding_dec(cType, nGain, hard, nInputs - nTail, soft, out, iwork, iwork[nTail]); for (i=0; i < nOutputs; i++){ y[i] = (real_T)out[i]; } } flag[0] = F(0);}/* Function: mdlTerminate ===================================================== * Abstract: * No termination needed, but we are required to have this routine. */static void mdlTerminate(SimStruct *S){ int_T *iwork = ssGetIWork(S); int_T tmp; if( iwork[nTail] > -1) wcdma_chdecoding_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 + -