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

📄 wcdmampathchannel.cpp

📁 用matlab程序实现WCDMA系统的仿真
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/ respectively.  Then the output of this function will be a vector of length 
/ "FrameSampleLength + MaxDelay" (note that MaxDelay=10).  To construct the first multipath component, 
/ we must use that portion of the combined signal that corresponds to the entire current frame and 
/ 10 samples from the next frame.  We then must create the fading signal.  This is accomplished by 
/ extracting the appropriate fading coefficients and then applying them to the signal in a peicewise 
/ constant fashion.  We believe that this provides the best trade-off betwee accuracy and speed.  Currently,
/ one fading signal point correponds to 400 chipping intervals.  the resuting signal is then stored 
/ in multipath vector (*RealMpathSignalptr, *ImagMpathSignalptr).
/ 
/ To construct the second multipath comontent, which has a delay of 10, we must use 10 samples for the 
/ last portion of the previous frame and then the entire current frame.  this will account for the 
/ delay and the inter-symbol interference associated with the delay.  The fading signal is constructed
/ in a similar manner.  The fading signal is then multiplied to the multipath component.  This 
/ component is then combined with the first multipath component to create the channel output.
/
/ Paramters
/	Input
/		*RealSigLastptr			Pointer to the real valued signal points associated with the previous
/								frame
/		*ImagSigLastptr			Pointer to the imaginary valued signal points associated with the 
/								previous frame
/		NSigLast				Length of signal associated with previous frame
/		*RealSigCurrentptr		Pointer to the real valued signal points associated with the current
/								frame
/		*ImagSigCurrentptr		Pointer to the imaginary valued signal points associated with the 
/								current frame
/		NSigCurrent				Length of signal associated with current frame
/		*RealSigNextptr			Pointer to the real valued signal points associated with the next 
/								frame
/		*ImagSigNextptr			Pointer to the imaginary valued signal points associated with the 
/								next frame
/		NSigNext				Length of signal associated with next frame
/		*DelaysPtr				Pointer to unsigned valued array containing the delay of each
/								multipath component in terms of sample point
/		NDelays					Number of multipath components in channel
/		*RealAmplitudesPtr		Pointer to real valued fading coefficients for each multipath 
/								component.  This array contains AmplitudeLength*NDelays elements,where
/								AmplitudeLength is defined below
/		*ImagAmplitudesPtr		Pointer to imaginary valued fading coefficients for each multipath 
/								component.  This array contains AmplitudeLength*NDelays elements,where
/								AmplitudeLength is defined below
/		AmplitudeLenth			The Number of fading amplitudes for each multipath component.
/		TxPulseLength			Length of the pulse shaping filter used at the transmitter
/		SamplesPerChip			Number of signal samples points per chip duration 
/								(over sampling factor)
/
/	Output
/		*RealMpathSignalptr		Pointer to the real valued portion of the multipath channel response
/		*ImagMpathSignalptr		Pointer to the imaginary valued portion of the multipath channel 
/								response
/		NMpathSignal			Length of multipath channel response = FrameSampleLength+MaxDelay		
/
******************************************************************************************************/

{
	unsigned long i,k,j,LoopStop;
	double *CombinedRealSigPtr,*CombinedImagSigPtr;			//Pointers to the array that stores the combined signal
	double *TempCombinedRealSigPtr,*TempCombinedImagSigPtr;	//Temporary Pointers to combined signal array
	unsigned long NCombinedSig;								//Length of Combined signal array

	//Temporary pointers for signal frames
	double *TempRealSigLastptr, *TempImagSigLastptr;		//Temporary pointers for RealSigLastptr and ImagSigLastptr
	double *TempRealSigCurrentptr, *TempImagSigCurrentptr;	//Temporary pointers for RealSigCurrentptr and ImagSigCurrentptr
	double *TempRealSigNextptr, *TempImagSigNextptr;		//Temporary pointers for RealSigNextptr and ImagSigNextptr

	//Temporary pointers for multipath channel parameters
	unsigned long *TempDelaysPtr;							//Temporary pointers for DelaysPtr
	unsigned long MaxDelay;									//Stores the largest values in DelaysPtr
	
	//Temporary pointers for output array
	double *TempRealMpathSignalptr, *TempImagMpathSignalptr;//Temporary pointers for RealMpathSignalptr and ImagMpathSignalptr

	unsigned long FrameBegin;		//Determines the location of the beginning of the first frame in the Combined Signal
	unsigned long FrameEnd;			//Determines the location of the end of the first frame in the Combined Signal
	unsigned long FrameSampleLength;//Number of signal samples per frame

	double increment;				//Number of abcissa values between fading signal data points.  Note that the fading 
									//Signal data are stored in RealAmplitudesPtr and ImagAmplitudesPtr
	unsigned long Increment;				//Number of abcissa values between fading signal data points.  Note that the fading 
									//Signal data are stored in RealAmplitudesPtr and ImagAmplitudesPtr
	unsigned long PreSigFadeRatio;
	unsigned long PostSigFadeRatio;
	unsigned long PreRemainingSamples;
	unsigned long PostRemainingSamples;
	unsigned long faa;
	double *TempRealFadeptr, *TempImagFadeptr;  //Pointers and temporary pointers to the interpolated
																			//fading coefficients
	double *RealAmpBeginPtr,*ImagAmpBeginPtr;
	unsigned long FadeSamplesPerFrame;	//The number of fade samples allocated for each frame

	MaxDelay=0;
	TempDelaysPtr=DelaysPtr;
	FrameSampleLength = SamplesPerChip * CHIPS_PER_FRAME;
	FrameBegin = (TxPulseLength + 1) >> 1;
	FrameEnd = FrameBegin - 1 + FrameSampleLength ;
	FadeSamplesPerFrame = CHIPS_PER_FRAME / CHIPS_PER_FADE_SAMPLES;


	/******************************************************************
	/* Create a combined Signal which contains the previous frame the 
	/* current frame and the future frame
	*/
	NCombinedSig = NSigLast + NSigCurrent + NSigNext - 2*(TxPulseLength - SamplesPerChip);
	CombinedRealSigPtr = (double *) mxCalloc(NCombinedSig,sizeof(double));
	if (CombinedRealSigPtr  == NULL) mexErrMsgTxt("\nMemory Allocation failed for CombinedRealSigPtr\n");

	CombinedImagSigPtr = (double *) mxCalloc(NCombinedSig,sizeof(double));
	if (CombinedImagSigPtr == NULL) mexErrMsgTxt("\nMemory Allocation failed for CombinedImagSigPtr\n");

	TempCombinedRealSigPtr = CombinedRealSigPtr;
	TempCombinedImagSigPtr = CombinedImagSigPtr;
	TempRealSigLastptr = RealSigLastptr;
	TempImagSigLastptr = ImagSigLastptr;
	LoopStop = NSigLast - TxPulseLength + SamplesPerChip;
	for (i=0; i<LoopStop; i++)
	{
		*TempCombinedRealSigPtr++ = *TempRealSigLastptr++;
		*TempCombinedImagSigPtr++ = *TempImagSigLastptr++;
	}

	TempRealSigCurrentptr = RealSigCurrentptr;
	TempImagSigCurrentptr = ImagSigCurrentptr;
	for (i=0; i<NSigCurrent; i++)
	{
		*TempCombinedRealSigPtr++ = *TempRealSigCurrentptr++;
		*TempCombinedImagSigPtr++ = *TempImagSigCurrentptr++;
	}

	TempRealSigNextptr = RealSigNextptr + TxPulseLength-SamplesPerChip;
	TempImagSigNextptr = ImagSigNextptr + TxPulseLength-SamplesPerChip;
	for (i=0; i<LoopStop; i++)
	{
		*TempCombinedRealSigPtr++ = *TempRealSigNextptr++;
		*TempCombinedImagSigPtr++ = *TempImagSigNextptr++;
	}

	/* Combined Signal Created
	/******************************************************************/

	for (i=0;i<NDelays;i++)
	{
		if (*TempDelaysPtr > MaxDelay) MaxDelay = *TempDelaysPtr++;
		else TempDelaysPtr++;
	}


	increment = (double) FrameSampleLength * (double) 3.0 / (double) AmplitudeLength; //Abcissa increment between data points
	Increment = (unsigned long) increment;
//	RemainingSamples = NMpathSignal % Increment;
															
	TempDelaysPtr = DelaysPtr;
	for (i=0;i<NDelays;i++)
	{
		//Determine the number of fading coefficients need from the previous frame
//		PriorInterpPoints = (unsigned long) ceil((double) *TempDelaysPtr / increment);
//		PriorInterpPoints = (unsigned long) floor((double) *TempDelaysPtr / increment);

		PreSigFadeRatio = (FrameBegin - 1 + *TempDelaysPtr) / Increment;
		PostSigFadeRatio = (NMpathSignal - FrameEnd - *TempDelaysPtr) / Increment;

		PreRemainingSamples = (FrameBegin - 1 + *TempDelaysPtr) - (PreSigFadeRatio * Increment);
		PostRemainingSamples = (NMpathSignal - FrameEnd - *TempDelaysPtr) - (PostSigFadeRatio * Increment);

		RealAmpBeginPtr = RealAmplitudesPtr + FadeSamplesPerFrame + AmplitudeLength*i - PreSigFadeRatio-1;
		ImagAmpBeginPtr = ImagAmplitudesPtr + FadeSamplesPerFrame + AmplitudeLength*i - PreSigFadeRatio-1;

		//Determine the number of fading coefficients need from the next frame


		TempRealFadeptr = RealAmpBeginPtr ;
		TempImagFadeptr = ImagAmpBeginPtr ;
		TempCombinedRealSigPtr = CombinedRealSigPtr + FrameSampleLength - *TempDelaysPtr;
		TempCombinedImagSigPtr = CombinedImagSigPtr + FrameSampleLength - *TempDelaysPtr;
		TempRealMpathSignalptr = RealMpathSignalptr;
		TempImagMpathSignalptr = ImagMpathSignalptr;

		for (j = 0; j < PreRemainingSamples; j++)
		{
			*TempRealMpathSignalptr++ += (*TempCombinedRealSigPtr * *TempRealFadeptr)
				- (*TempCombinedImagSigPtr * *TempImagFadeptr);
			*TempImagMpathSignalptr++ += (*TempCombinedRealSigPtr++ * *TempImagFadeptr)
				+ (*TempCombinedImagSigPtr++ * *TempRealFadeptr);
		}
		TempRealFadeptr++;
		TempImagFadeptr++;

		faa = FadeSamplesPerFrame + PreSigFadeRatio + PostSigFadeRatio;
		for (j=0; j < faa; j++)
		{
			for (k=0; k < Increment; k++)
			{
				*TempRealMpathSignalptr++ += (*TempCombinedRealSigPtr * *TempRealFadeptr)
					- (*TempCombinedImagSigPtr * *TempImagFadeptr);
				*TempImagMpathSignalptr++ += (*TempCombinedRealSigPtr++ * *TempImagFadeptr)
					+ (*TempCombinedImagSigPtr++ * *TempRealFadeptr);
			}
			TempRealFadeptr++;
			TempImagFadeptr++;
		}

		for (j = 0; j < PostRemainingSamples; j++)
		{
			*TempRealMpathSignalptr++ += (*TempCombinedRealSigPtr * *TempRealFadeptr)
				- (*TempCombinedImagSigPtr * *TempImagFadeptr);
			*TempImagMpathSignalptr++ += (*TempCombinedRealSigPtr++ * *TempImagFadeptr)
				+ (*TempCombinedImagSigPtr++ * *TempRealFadeptr);
		}

		TempDelaysPtr++;
	}
	
	mxFree(CombinedRealSigPtr);
	mxFree(CombinedImagSigPtr);

}

⌨️ 快捷键说明

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