📄 s_channel.c
字号:
/* | Project: WCDMA simulation environment | Module: | Author: Maarit Melvasalo | Date: February 1999 | | History: | March 18, 1999 Maarit Melvasalo | Channel memory vector changed to mode were | several different vectors can be memorized | | May 3, 1999 Maarit Melvasalo | Channel model changed | | Abstract: | | USER GIVEN PARAMETERS | | 1: B = the number of real input chips | 2: HR = channel amplitudes | 3: HD = channel delays | 4: HP = channel probabilities (for random channel only) | 5: snr =signal to noise ration | 6: noise power | 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 | input chips from Q | | Outputs: | output chips from I (multipath + noise) | current channel amplitude taps | current delay taps | output chips from Q (multipath + noise) | | DEPENDS ON FILES | channel.c | channel_real_input.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_channel#define S_FUNCTION_LEVEL 2#include <math.h>#include "simstruc.h"#include "channel.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 4/* Number of user given parameters/**/ #define NPARAMS 9 /* Input and Output Size parameters /**/#define B_PARAM(S) ssGetSFcnParam(S,0) #define nInputs (int_T)(mxGetPr(B_PARAM(S))[0]) /* Channel amplitudes*/#define HR_PARAM(S) ssGetSFcnParam(S,1) /* Channel delay taps*/#define HD_PARAM(S) ssGetSFcnParam(S,2) /* Number of channel taps */ #define nTaps (int_T) (mxGetM(HR_PARAM(S))) /* Number of channel impulses */ #define nImpulse (int_T) (mxGetN(HR_PARAM(S))) /*Channel impulse probalilities*/#define prob_PARAM(S) ssGetSFcnParam(S,3) /*NOTE that nImpulse = mxGetN(prob_PARAM(S) /**//*Signal to noise ratio*/#define snr_PARAM(S) ssGetSFcnParam(S,4) #define power_PARAM(S) ssGetSFcnParam(S,5) /* Length of the spreading code/**/#define code_PARAM(S) ssGetSFcnParam(S,6) #define nC (int_T)(mxGetPr(code_PARAM(S))[0]) /* Number of slots in each frame /**/#define SLOTS(S) ssGetSFcnParam(S,7)#define nSlots (int_T)(mxGetPr(SLOTS(S))[0]) /* Input type : integers / real /**/#define inTYPE(S) ssGetSFcnParam(S,8)/* Pointers to Input Ports */#define UI(element) (*uIPtrs[element]) #define UQ(element) (*uQPtrs[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){/* 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, nInputs); ssSetInputPortDirectFeedThrough(S, 0, 1); ssSetInputPortDirectFeedThrough(S, 1, 1); if (!ssSetNumOutputPorts(S, NOUTPUTS)) return; ssSetOutputPortWidth(S, 0, nInputs); ssSetOutputPortWidth(S, 1, MAX_CHANNEL_TAPS); ssSetOutputPortWidth(S, 2, MAX_CHANNEL_TAPS); ssSetOutputPortWidth(S, 3, nInputs); /* Initialize number of sample times and simulink work vectors /**/ ssSetNumSampleTimes(S, 1); ssSetNumIWork(S, nTaps * nImpulse + 1); ssSetNumRWork(S, nTaps); /* 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);} /* Function: mdlInitializeSampleTimes ========================================= * Abstract: * Specify the sample time */static void mdlInitializeSampleTimes(SimStruct *S){ ssSetSampleTime(S, 0, td); ssSetOffsetTime(S, 0, 0.0);}#define MDL_INITIALIZE_CONDITIONS/* Function: mdlInitializeConditions ======================================== * Abstract: * Stores the channel data to memory * And defines the used channel type * CONSTANT / RANDOM /INTERPOLATING * Allocates space formemory chips */static void mdlInitializeConditions(SimStruct *S){ int_T *iwork = ssGetIWork(S); real_T *rwork = ssGetRWork(S); real_T *hrpr = mxGetPr(HR_PARAM(S)); real_T *hdpr = mxGetPr(HD_PARAM(S)); real_T *impulse_prob = mxGetPr(prob_PARAM(S)); real_T n_prob = mxGetN(prob_PARAM(S)); real_T snr = mxGetPr(snr_PARAM(S))[0]; real_T power = mxGetPr(power_PARAM(S))[0]; int_T type = mxGetPr(inTYPE(S))[0]; int_T i, tmp, steps; int_T impulse_size = (int_T)mxGetN(prob_PARAM(S)); real_T prob[nImpulse]; for (i = 0; i < nTaps * nImpulse; i++){ iwork[i] = (int_T) hdpr[i]; } tmp = 0; /* nFrames = Number of blocks send to channel for interpolating channel. nFrames = 0 for Random channel /**/ if ( n_prob > 1) { steps = 0; /* Redefine the size of the probability vector if it is not correct/**/ for (i = 0; i < ( min(impulse_size,nImpulse)); i++){ prob[i] = impulse_prob[i]; } if (impulse_size > nImpulse) prob[nImpulse-1] = 1; if (impulse_size < nImpulse) { prob[nImpulse-1] = 1; } } else steps = ((int_T) ((ssGetTFinal(S) - ssGetTStart(S)) * nSlots + 1)) ; if (type == 1) iwork[nTaps*nImpulse] = wcdma_channel_init(hrpr, iwork, nTaps, nImpulse, prob, steps, snr,power,nC);/**/ else iwork[nTaps*nImpulse] = wcdma_channel_init_double(hrpr, iwork, nTaps, nImpulse, prob, steps, snr,power,nC); }/* Function: mdlOutputs ======================================================= * Abstract: * Calculates the sum of multipath compoments * and adds noise. * If channel is not constant the channel is updated * after each slot (= sample time for this s-function) * Return value: * Returns I and Q chips (noise and multipath added) * and the used channel and delay taps */static void mdlOutputs(SimStruct *S, int_T tid){ real_T *yI = ssGetOutputPortRealSignal(S,0); real_T *channel = ssGetOutputPortRealSignal(S,1); real_T *delay = ssGetOutputPortRealSignal(S,2); real_T *yQ = ssGetOutputPortRealSignal(S,3); InputRealPtrsType uIPtrs = ssGetInputPortRealSignalPtrs(S,0); InputRealPtrsType uQPtrs = ssGetInputPortRealSignalPtrs(S,1); int_T type = mxGetPr(inTYPE(S))[0]; int_T *iwork = ssGetIWork(S); real_T *rwork = ssGetRWork(S); int_T dataI[nInputs]; int_T dataQ[nInputs]; real_T real_dataI[nInputs]; real_T real_dataQ[nInputs]; int_T lp; /* If the channel allocation was succesfull/**/ if (iwork[nTaps*nImpulse] > -1){ /* If input is integer type /**/ if (type == 1){ /* Save the input chips to integer vector /**/ for (lp = 0; lp < nInputs; lp++){ dataI[lp]=(int_T)UI(lp); dataQ[lp]=(int_T)UQ(lp); } lp = wcdma_channel (dataI,dataQ,nInputs, iwork[nTaps*nImpulse],rwork,iwork,yI,yQ); /**/ } else { /* Input data is real valued /**/ for (lp = 0; lp < nInputs; lp++){ real_dataI[lp] = UI(lp); real_dataQ[lp] = UQ(lp); } lp = wcdma_channel_double(real_dataI,real_dataQ,nInputs, iwork[nTaps*nImpulse],rwork,iwork,yI,yQ); } /* Return the channel and delay taps /**/ for(lp = 0; lp<nTaps; lp++){ channel[lp] = rwork[lp]; delay[lp] = iwork[lp]; } } }/* Function: mdlTerminate ===================================================== * Free the memory */static void mdlTerminate(SimStruct *S){ int_T *iwork = ssGetIWork(S); int_T type = mxGetPr(inTYPE(S))[0]; int_T tmp; if (type == 1) tmp = wcdma_channel_free(iwork[nTaps*nImpulse]); else tmp = wcdma_channel_free_double(iwork[nTaps*nImpulse]);}#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 + -