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

📄 wcdmampathchannel.cpp

📁 用matlab程序实现WCDMA系统的仿真
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include <malloc.h>
#include "mex.h"
#include <math.h>
#include "matrix.h"
#include <stdlib.h>

#define CHIPS_PER_FRAME  38400
#define CHIPS_PER_FADE_SAMPLES 400


void MPathChannel(double *, double *, unsigned long, double *, double *, unsigned long,
				  double *, double *, unsigned long, unsigned long *,unsigned long, double *, 
				  double *, unsigned long, unsigned long, unsigned long, double *, double *,
				  unsigned long);

void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
/**************************************************************************************
* void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
*
*
* Copyright 2002 The Mobile and Portable Radio Research Group
*
* Gateway function for WCDMAMPathChannel.  Supports that passing of seven input parameters
* and one output parameter.  The seven input parameters are
*		SigLast				ComplexVector containing the signal associated with the 
*							previous frame (i.e., the frame from the last iteration
*		SigCurrent			Complex Vector containing the signal asociated with the 
*							current frame
*		SigNext				Complex Vector Contatining the signal associated with the
*							next frame
*		MultipathDelay		Real Valued Vector containing the delays (in # of samples)
*							associated with each multipath component
*		FadingAmplitudes	Complex matrix containing the fading signal for each multipath
*							Component.  Each column corresponds to a multipath component and
*							contains 3*CHIPS_PER_FRAME/CHIPS_PER_FADE_SAMPLES (usually 
*							288 elements).  These elements are interpolated to create 
*							a fading signal for each sample
*		TxPulseLength		Length of transmitter pulse shaping filter 
*		SamplesPerChip		Oversampling factor.  The # of signal samples per chip
*
* The one output parameter is the output signal from the multipath channel
***************************************************************************************/


{
	const mxArray *tprhs;
	unsigned i;
	unsigned long mexSigLastLength,mexSigCurrentLength,mexSigNextLength,mrows,ncols;
	double *mexRealSigLast,*mexImagSigLast;				//Signal Associated with Previous Frame
	double *mexRealSigCurrent,*mexImagSigCurrent;		//Signal Associated with current Frame
	double *mexRealSigNext,*mexImagSigNext;				//Signal Associated with Next Frame
	double *mexDelayDouble,*mexTempDelayDouble;			//Stores Multipath Delay
	unsigned long *mexDelay,*mexTempDelay,mexDelayLength; //Stores Multipath Delay in integer form
	unsigned long mexMaxDelay,TempVar;					//Stores maximum multipath delay 
	double *mexRealAmplitudes,*mexImagAmplitudes;		//Stores Fading signal
	unsigned long mexTxPulseLength;						//Length of Transmitter Pulse
	unsigned long mexSamplesPerChip;					//Oversample factor
	unsigned long mexMultipathSignalLength;				//Length of channel output
	double *mexRealMpathSignal,*mexImagMpathSignal;		//Stores Channel output
	unsigned long mexAmplitudeLength;					//Length of Fading amplitude for each multipath components
	char ErrorString[100];								//Character String for error messages

	
	
	//Check for the proper number of input and output arguments
	if (nrhs != 7) mexErrMsgTxt("\nExactly SEVEN input arguemnts are required!!\n");
	else if (nlhs != 1 ) mexErrMsgTxt("\nExactly ONE output arguement is required!!\n");

	
	//SigLast
	//Must be a complex vector
	tprhs = *prhs;
	mrows = mxGetM(tprhs);
	ncols = mxGetN(tprhs);
	if ( !mxIsDouble(tprhs) || !mxIsComplex(tprhs) || (mrows ==1 && ncols ==1) || (mrows >1 && ncols >1))
		mexErrMsgTxt("\nSigLast must be a complex-valued vector\n");
	if (mrows > ncols) mexSigLastLength = (unsigned long) mrows;
	else mexSigLastLength = (unsigned long) ncols;
	mexRealSigLast = mxGetPr(tprhs);
	mexImagSigLast = mxGetPi(tprhs);
	
	//SigCurrent
	//Must be a complex vector
	tprhs = *(prhs+1);
	mrows = mxGetM(tprhs);
	ncols = mxGetN(tprhs);
	if ( !mxIsDouble(tprhs) || !mxIsComplex(tprhs) || (mrows ==1 && ncols ==1) || (mrows >1 && ncols >1))
		mexErrMsgTxt("\nSigCurrent must be a complex-valued vector\n");
	if (mrows > ncols) mexSigCurrentLength = (unsigned long ) mrows;
	else mexSigCurrentLength = (unsigned long) ncols;
	mexRealSigCurrent = mxGetPr(tprhs);
	mexImagSigCurrent = mxGetPi(tprhs);

	//SigNext
	//Must be a complex vector
	tprhs = *(prhs+2);
	mrows = mxGetM(tprhs);
	ncols = mxGetN(tprhs);
	if ( !mxIsDouble(tprhs) || !mxIsComplex(tprhs) || (mrows ==1 && ncols ==1) || (mrows >1 && ncols >1))
		mexErrMsgTxt("\nSigNext must be a complex-valued vector\n");
	if (mrows > ncols) mexSigNextLength = (unsigned long) mrows;
	else mexSigNextLength = (unsigned long) ncols;
	mexRealSigNext = mxGetPr(tprhs);
	mexImagSigNext = mxGetPi(tprhs);

	//Multipath Delay
	//Must be a real vauled, double vector or scalar
	tprhs = *(prhs+3);
	mrows = mxGetM(tprhs);
	ncols = mxGetN(tprhs);
	if ( !mxIsDouble(tprhs) || mxIsComplex(tprhs) || (mrows >1 && ncols >1))
		mexErrMsgTxt("\n mexDelays must be a real-valued vector\n");
	if (mrows > ncols) mexDelayLength = (unsigned long) mrows;
	else mexDelayLength = (unsigned long) ncols;
	mexDelayDouble = mxGetPr(tprhs);

	mexDelay = (unsigned long *) mxCalloc(mexDelayLength,sizeof(unsigned long));
	mexMaxDelay = 0;
	mexTempDelayDouble = mexDelayDouble;
	mexTempDelay = mexDelay;
	for (i=0; i<mexDelayLength; i++)
	{
		TempVar = (unsigned long) *mexTempDelayDouble++;
		if ( TempVar > mexMaxDelay) mexMaxDelay = TempVar;
		*mexTempDelay++ = TempVar;
	}
	

	//Fading Amplitudes
	//Must be a double, complex and CHIPS_PER_FRAME/CHIPS_PER_FADE_SAMPLES x MexDelayLength matrix
	mexAmplitudeLength = 3*CHIPS_PER_FRAME/CHIPS_PER_FADE_SAMPLES;
	tprhs = *(prhs+4);
	mrows = mxGetM(tprhs);
	ncols = mxGetN(tprhs);
	if ( !mxIsDouble(tprhs) || !mxIsComplex(tprhs) )
		mexErrMsgTxt("\nAmpliutudes must be complex \n");
	if (mrows !=  mexAmplitudeLength)
	{
		sprintf(ErrorString,"\nAmplitudes must have %d rows \n",mexAmplitudeLength);
		mexErrMsgTxt(ErrorString);
	}
	if (ncols != mexDelayLength)
		mexErrMsgTxt("\nAmplitudes must have one column for every multipath component\n");
	mexRealAmplitudes = mxGetPr(tprhs);
	mexImagAmplitudes = mxGetPi(tprhs);

	//Transmitter PulseLength 
	//Must be a scalar
	tprhs = *(prhs+5);
	mrows = mxGetM(tprhs);
	ncols = mxGetN(tprhs);
	if ( !mxIsDouble(tprhs) || mxIsComplex(tprhs) || !(mrows ==1 && ncols ==1))
		mexErrMsgTxt("\nTxPulselength must be a real-valued scalar\n");
	mexTxPulseLength = (unsigned long) mxGetScalar(tprhs);

	//Samples per Chip
	//Must be a scalar
	tprhs = *(prhs+6);
	mrows = mxGetM(tprhs);
	ncols = mxGetN(tprhs);
	if ( !mxIsDouble(tprhs) || mxIsComplex(tprhs) || !(mrows ==1 && ncols ==1))
		mexErrMsgTxt("\nSamples per chip must be a real-valued scalar\n");
	mexSamplesPerChip = (unsigned long) mxGetScalar(tprhs);
		
	//Allocate output Array for channel output
	mexMultipathSignalLength = mexSigCurrentLength + mexMaxDelay;
	*plhs = mxCreateDoubleMatrix(1,mexMultipathSignalLength,mxCOMPLEX);
	mexRealMpathSignal = mxGetPr(*plhs);
	mexImagMpathSignal = mxGetPi(*plhs);

	//Call Multipath channel function
	MPathChannel(mexRealSigLast, mexImagSigLast,mexSigLastLength,
				  mexRealSigCurrent, mexImagSigCurrent, mexSigCurrentLength,
				  mexRealSigNext, mexImagSigNext, mexSigNextLength,
				  mexDelay,mexDelayLength,
				  mexRealAmplitudes,mexImagAmplitudes,mexAmplitudeLength,
				  mexTxPulseLength, mexSamplesPerChip,
				  mexRealMpathSignal, mexImagMpathSignal, mexMultipathSignalLength);

	mxFree(mexDelay);

}



void MPathChannel(double *RealSigLastptr, double *ImagSigLastptr, unsigned long NSigLast,
				  double *RealSigCurrentptr, double *ImagSigCurrentptr, unsigned long NSigCurrent,
				  double *RealSigNextptr, double *ImagSigNextptr, unsigned long NSigNext,
				  unsigned long *DelaysPtr,unsigned long NDelays,
				  double *RealAmplitudesPtr,double *ImagAmplitudesPtr,unsigned long AmplitudeLength,
				  unsigned long TxPulseLength, unsigned long SamplesPerChip,
				  double *RealMpathSignalptr, double *ImagMpathSignalptr, unsigned long NMpathSignal)
/*****************************************************************************************************
/void MPathChannel(double *RealSigLastptr, double *ImagSigLastptr, unsigned long NSigLast,
/				  double *RealSigCurrentptr, double *ImagSigCurrentptr, unsigned long NSigCurrent,
/				  double *RealSigNextptr, double *ImagSigNextptr, unsigned long NSigNext,
/				  unsigned long *DelaysPtr,unsigned long NDelays,
/				  double *RealAmplitudesPtr,double *ImagAmplitudesPtr,unsigned long AmplitudeLength,
/				  unsigned long TxPulseLength, unsigned long SamplesPerChip,
/				  double *RealMpathSignalptr, double *ImagMpathSignalptr, unsigned long NMpathSignal)
/
/
/ Copyright 2002 The Mobile and Portable Radio Research Group
/
/ The funciton simulates the behavior of a specular multipath channel on the signal associated with 
/ the current frame (RealSigCurrentptr & ImagSigCurrentptr).  The signal associated with the previous 
/ frame (RealSigLastptr & ImagSigLastptr) and the next frame (RealSigNextptr & ImagSigNextptr) are 
/ included so that their signal points can be incorporated as reauired when the delays are incorporated.
/ These signals are placed into one large array caled *CombinedRealSigPtr and *CombinedImagSigPtr.
/ We call this signal the "combined signal".  The combined signal contains three frames of signal points
/ 
/ The number of multipath components is eaqual to the NDelays.  For each multipath component, we must
/ (1) determine the fading coefficients associated with that component, (2)apply the fading to 
/ that signal in a piecewise constant fashion, and (5) combine the result with the result from the 
/ other multipath components.
/
/ As an example, consider the case where we have two multipath components with at delay of 0 and 10 

⌨️ 快捷键说明

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