📄 s_deinterleaver.c
字号:
/* | Project: WCDMA simulation environment | Module: | Author: | Date: MAy 24, 1999 | | History: | May 23, 1999 Maarit Melvasalo | Interleaver separated from channel coding | see s_chcoding.c | June 2, 1999 Maarit Melvasalo | Sample time changed | | File : s_deinterleaver.c | Abstract: | | USER GIVEN PARAMETERS | | 1: B = Number of bits in a frame | 2: COL = Number of colums for interleaver | 3: nFrames = Number of frames in a block | 4: inter_mode = Inter interleaver mode | | Inputs: | received soft bits | | Outputs: | deinterleaved soft bits | Flag indicating if inputdata is valid or not | DEPENDS ON FILES | interleaving.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_deinterleaver #define S_FUNCTION_LEVEL 2#include <math.h>#include "simstruc.h"#include "tmwtypes.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 4 /* Input and Output Size parameters /**/#define B_PARAM(S) ssGetSFcnParam(S,0) #define bits_frame (int_T)(mxGetPr(B_PARAM(S))[0]) /* Number of rows for block deinterleaver/**/ #define ROW_PARAM(S) ssGetSFcnParam(S,1) /* Number of frames in one block/**/#define frame(S) ssGetSFcnParam(S,2)#define nFrames (int_T)(mxGetPr(frame(S))[0]) /* Inter frame interleaver mode flag */#define inter_mode(S) ssGetSFcnParam(S,3) /* Pointer to Input Port */#define U(element) (*uPtrs[element]) #define F(element) (*fPtrs[element]) /* 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; } ssSetNumContStates(S, 0); /* Initialize the input and output port sizes/**/ if (!ssSetNumInputPorts(S, NINPUTS)) return; ssSetInputPortWidth(S, 0, nFrames*bits_frame); ssSetInputPortWidth(S, 1,nSide); ssSetInputPortDirectFeedThrough(S, 0, 1); ssSetInputPortDirectFeedThrough(S, 1, 1); if (!ssSetNumOutputPorts(S, NOUTPUTS)) return; ssSetOutputPortWidth(S, 0, nFrames*bits_frame); ssSetOutputPortWidth(S, 1,nSide); /* Initialize number of sample times and simulink work vectors /**/ ssSetNumSampleTimes(S, 1); ssSetNumIWork(S, 3); /* To Speeds up the simulations/**/ ssSetSFcnParamNotTunable(S,0); ssSetSFcnParamNotTunable(S,1); ssSetSFcnParamNotTunable(S,2); ssSetSFcnParamNotTunable(S,3); /* Take care when specifying exception free code - see sfuntmpl.doc */ ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE);}/* 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: * For block deinterleaver calculate number of colums */static void mdlInitializeConditions(SimStruct *S){ int_T rows = (int_T)(mxGetPr(ROW_PARAM(S))[0]); int_T *iwork = ssGetIWork(S); real_T mode = mxGetPr(inter_mode(S))[0]; int_T cols; if ( mode <2 ){ iwork[0] = rows; if(rows > 0) { cols = (nFrames * bits_frame) / rows; if (rows * cols == nFrames*bits_frame){ iwork[1] = cols; } /*If there is something wrong with the rows /**/ else iwork[0] = 0; } }}/* Function: mdlOutputs ======================================================= * Abstract: * Performs for the given block (nFrames * bits_in_frame * block interleaving or multistage interleaving * Depending on the mode parameter * * NOTE: Inputs and outputs are real number, i.e. soft bits */static void mdlOutputs(SimStruct *S, int_T tid){ real_T *y = ssGetOutputPortRealSignal(S,0); real_T *flag = ssGetOutputPortRealSignal(S,1); InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0); InputRealPtrsType fPtrs = ssGetInputPortRealSignalPtrs(S,1); int_T *iwork = ssGetIWork(S); real_T mode = mxGetPr(inter_mode(S))[0]; int_T i; real_T inputs[nFrames*bits_frame]; flag[0] = F(0);; /* If previous block had an output /**/ if(F(0) > 0) { /* Move the input bits to a vector /**/ for (i = 0; i < nFrames*bits_frame; i++) inputs[i] = U(i); /* If the Block interleaver is selected /**/ if ( mode <2 ){ if(iwork[0] > 0) wcdma_block_float_deinterleaver(iwork[0],iwork[1], inputs, y); } /* If the Multistage interleaver is selected /**/ else { wcdma_interframe_double_deinterleaver( (nFrames*bits_frame),bits_frame,inputs,y); } }}/* Function: mdlTerminate ===================================================== * Abstract: * No termination needed, but we are required to have this routine. */static void mdlTerminate(SimStruct *S){}#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 + -