📄 s_rake.c
字号:
/* | Project: WCDMA simulation environment | Module: | Author: Maarit Melvasalo | Date: February 1999 | | History: | February 18, 1999 Maarit Melvasalo | Initial version | | | May 3, 1999 Maarit Melvasalo | Rake model totally changed | * Abstract: * * USER GIVEN PARAMETERS * * 1: B = the number of real input chips * 7: code length (used to calcutate noise per chip) * 8: nSlot = number od slot in a frame (used for sample timing) * * Inputs: * input chips (from I or Q) * current channel amplitude taps * current delay taps * number of relevant cahnnel taps * * Outputs: * Despread symbols * * DEPENDS ON FILES * rake.c * rake_supp.c * spreading.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_rake#define S_FUNCTION_LEVEL 2#include <math.h>#include "simstruc.h"#include "tmwtypes.h"#include "config_wcdma.h"#include "rake.h"#include "wcdma_simulink.h"/* USER GIVEN PARAMETERS AND DEFINITIONS /**//*Number of input and output ports/**/#define NINPUTS 4#define NOUTPUTS 2/* Number of user given parameters/**/ #define NPARAMS 7/* Input and Output Size parameters /**/#define P_size(S) ssGetSFcnParam(S,0)#define inRake (int_T)(mxGetPr(P_size(S))[0])/* Number of Pilot bits to be remoced/**/#define PILOT(S) ssGetSFcnParam(S,1)#define nPilot (int_T)(mxGetPr(PILOT(S))[0])/* Number of Finger used in RAKE/**/#define F_number(S) ssGetSFcnParam(S,2)#define nFin (int_T)(mxGetPr(F_number(S))[0])/* Threshold value for finger /**/#define F_thresh(S) ssGetSFcnParam(S,3)#define fin_tres mxGetPr(F_thresh(S))[0]/* spreading code/**/#define C_code(S) ssGetSFcnParam(S,4) #define nCode mxGetN(C_code(S))/* spreading factor/**/#define SF_P(S) ssGetSFcnParam(S,5) #define SF (int_T)(mxGetPr(SF_P(S))[0])/*Number of slots in a frame/**/#define SLOTS(S) ssGetSFcnParam(S,6)#define nSlots (int_T)(mxGetPr(SLOTS(S))[0]) /* Define outputprot sizes /**/#define outRake (int_T)((2 * inRake )/nCode ) - 2 * nPilot/* Pointers to Input Ports */#define Rin(element) (*RPtrs[element])#define HR(element) (*hrPtrs[element])#define HD(element) (*hdPtrs[element])#define L(element) (*lenPtrs[element])/* Sampletime -- defined in config_cdma /**/#define td TD_FRAME / (real_T)nSlots /*====================* * 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){ ssSetNumSFcnParams(S, NPARAMS);/* Number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { return; } /* Initialize the input and output port sizes/**/ if (!ssSetNumInputPorts(S, NINPUTS)) return; ssSetInputPortWidth(S, 0, inRake); ssSetInputPortWidth(S, 1, MAX_CHANNEL_TAPS); ssSetInputPortWidth(S, 2, MAX_CHANNEL_TAPS); ssSetInputPortWidth(S, 3, 1); ssSetInputPortDirectFeedThrough(S, 0, 1); ssSetInputPortDirectFeedThrough(S, 1, 1); ssSetInputPortDirectFeedThrough(S, 2, 1); ssSetInputPortDirectFeedThrough(S, 3, 1); if (!ssSetNumOutputPorts(S, NOUTPUTS)) return; ssSetOutputPortWidth(S, 0,outRake); ssSetOutputPortWidth(S, 1,nSide); /* channel /**/ /* Initialize number of sample times and simulink work vectors /**/ ssSetNumSampleTimes(S, 1); ssSetNumIWork(S, nCode + 1); ssSetNumRWork(S, MAX_FINGER); /* To Speeds up the simulations/**/ ssSetSFcnParamNotTunable(S,0); /* speeds up simulations*/ ssSetSFcnParamNotTunable(S,1); /* number of output bits and delay*/ ssSetSFcnParamNotTunable(S,2); ssSetSFcnParamNotTunable(S,3); ssSetSFcnParamNotTunable(S,4); ssSetSFcnParamNotTunable(S,5); /* Take care when specifying exception free code - see sfuntmpl.doc */ ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE); /* do not use mxCalloc or mexErrMsgTxt functions */} static void mdlInitializeSampleTimes(SimStruct *S){ ssSetSampleTime(S, 0, td); ssSetOffsetTime(S, 0, 0.0);}#define MDL_INITIALIZE_CONDITIONS/* Function: mdlInitializeConditions ======================================== * Abstract: */static void mdlInitializeConditions(SimStruct *S){ int_T *iwork = ssGetIWork(S); real_T *cpr = mxGetPr(C_code(S)); int_T i; /* and nCode elements indicating the code */ for (i = 0; i < nCode; i++){ iwork[ i ] = (int_T)cpr[i]; } /*initialization of the rake and saving the instance to memory/**/ iwork[ nCode ] = wcdma_rake_init(nPilot * SF, fin_tres, nFin); /**/ }static void mdlOutputs(SimStruct *S, int_T tid){ real_T *y = ssGetOutputPortRealSignal(S,0); real_T *side = ssGetOutputPortRealSignal(S,1); InputRealPtrsType RPtrs = ssGetInputPortRealSignalPtrs(S,0); InputRealPtrsType hrPtrs = ssGetInputPortRealSignalPtrs(S,1); InputRealPtrsType hdPtrs = ssGetInputPortRealSignalPtrs(S,2); InputRealPtrsType lenPtrs = ssGetInputPortRealSignalPtrs(S,3); int_T *iwork = ssGetIWork(S); real_T *rwork = ssGetRWork(S); real_T chan[MAX_CHANNEL_TAPS]; real_T data[inRake]; real_T out[outRake]; int_T delay[MAX_CHANNEL_TAPS]; int_T len,delay_int,i; int_T instance = iwork[nCode]; int_T nTaps = (int_T)L(0);/**/ for(i=0; i<nTaps; i++){ delay[i] = (int_T)HD(i); chan[i] = HR(i); } for(i = 0; i< inRake; i++){ data[i] = Rin(i); } i = wcdma_rake_receiver(instance,data,inRake,iwork, nCode,SF,delay,chan,nTaps,&len,&delay_int,out); side[0] = len; /* output the actual length of the output vector /**/ if(len>0){ for(i = 0; i<len; i++){ y[i] = out[i]; }}}static void mdlTerminate(SimStruct *S){ int_T *iwork = ssGetIWork(S); int_T instance = iwork[nCode]; int_T tmp; tmp = wcdma_rake_free(instance);}#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 + -