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

📄 receiverclass.cpp

📁 用matlab程序实现WCDMA系统的仿真
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	ComplexNumber *DespreadSignal;	//Pointer to the array that contains the output of the despreader
	ComplexNumber *ChannelEstimates;//Pointer to the array that contains the channel estimates
//	FILE *fp;
	unsigned k;						//Loop counter

	//Filter the Incoming Signal
	FilteredSignal = Filter(IncomingSignal,SignalLength,CHIPS_PER_FRAME);

	/******************************************************************
	fp=fopen("FilteredSignal.txt","w");
	for (k=0;k<CHIPS_PER_FRAME;k++) 
		fprintf(fp,"%g %g\n",(FilteredSignal+k)->real,(FilteredSignal+k)->imaginary);
	fclose(fp);
	/*********************************************************************************/

	//Descramble the Filtered Signal
	Descramble(FilteredSignal,ScrambleCode);

//	fp=fopen("DescrambledSignal.txt","w");
//	for (k=0;k<CHIPS_PER_FRAME;k++) 
//		fprintf(fp,"%g %g\n",(FilteredSignal+k)->real,(FilteredSignal+k)->imaginary);
//	fclose(fp);


	//Despread the Descrambled Signal
	DespreadSignal = DespreadFrame(Format,FilteredSignal);
	free(FilteredSignal);

	/*********************************************************************
	fp=fopen("DespreadSignal.txt","w");
	unsigned SF,fee;
	SF = Format.SF;
	fee=38400/SF;
	for (k=0;k<fee;k++) 
		fprintf(fp,"%g %g\n",(DespreadSignal+k)->real,(DespreadSignal+k)->imaginary);
	fclose(fp);
	/***********************************************************************/

	//Obtain Channel Estimates
	ChannelEstimates=ChannelEstimator(Format,DespreadSignal);

	/*********************************************************************
	fp=fopen("ChannelEstimates.txt","w");
	for (k=0;k<15;k++) 
		fprintf(fp,"%g %g\n",(ChannelEstimates+k)->real,(ChannelEstimates+k)->imaginary);
	fclose(fp);
	/***********************************************************************/

	//Apply Channel Estimates to Despread Signal
	ApplyChannelEstimates(Format, DespreadSignal, ChannelEstimates);
	free (ChannelEstimates);

	/**************************************************************************
	fp=fopen("ModifiedDespreadSignal.txt","w");
	for (k=0;k<150;k++) 
		fprintf(fp,"%g %g\n",(DespreadSignal+k)->real,(DespreadSignal+k)->imaginary);
	fclose(fp);
	/***************************************************************************/
	return(DespreadSignal);
}

int * ReceiverClass::STTDReceiver(ComplexNumber *IncomingSignal,
								  unsigned SignalLength)
/**************************************************************************************
* int * ReceiverClass::STTDReceiver(ComplexNumber *IncomingSignal, unsigned SignalLength)
*
* Copyright 2002 The Mobile and Portable Radio Research Group
*
* The function implements a RAKE receiver for an STTD coded signal.  The number of fingers on the receiver
* equals the number of multipath components in the channel, and each finger is exactly 
* tuned to the delay of the multipath components (i.e., the receiver has perfect knowledge
* of the multipath delays.  Each finger performs the following operations:  matched filter,
* descramble, despread, channel estimate, and soft STTD decoding. The output of each finger 
* is then a soft decoded estimate of the transmitted signal.  These estimates are then 
* summed.  The resultant combined signal is then sent to a detector
* to extract the transmitted symbols
*
* Returns	An array that contains the decoded bits in the "data fields". 
*			Note that TFCI, TCP, and Pilot bits are not returned
*
* Parameters
*	IncomingSignal	ComplexNumber *		Array that contains the receiver input 
*										(channel output) for the given radio frame
*	SignalLength	unsigned			Length of the signal sample
***************************************************************************************/
{
	unsigned k,j;	//Loop counters
	ComplexNumber *IncomingSignalComponent;	//That portion of the incoming signal that contains
											//the complete transmitted signal record for a givn
											//multipath component
	ComplexNumber *RakeFingerOutputPtr,*TempRakeFingerOutputPtr;	//Pointer and temporary pointer
																	//to the output of one finger
																	//of the RAKE receiver
	ComplexNumber *CombinedOutputPtr,*TempCombinedOutputPtr;		//Pointer and temporary pointer
																	//to the resultant signal when	
																	//the outputs of each RAKE figner 
																	//is linearly combined
	unsigned SymbolsPerFrame;		//Number of symbols in a given frame
	unsigned *DelayPtr;				//Temporary Pointer to the array that contains the multipath delays in chips

	
	//Determine the number of symbols in a frame
	SymbolsPerFrame = DPCH_Format.ActualSlotsPerFrame * (DPCH_Format.BitsPerSlot >> 1);
	//Allocate array for the receiver output
	CombinedOutputPtr = (ComplexNumber *) calloc(SymbolsPerFrame,sizeof(ComplexNumber));
	if (CombinedOutputPtr == NULL)
	{
		printf("\nMemory allocation to CombinedOutputPtr failed--exiting\n");
		return(NULL);
	}
	
	DelayPtr = Delays;
	//Process each figner of the RAKE receiver
	for (k=0; k<MultiPathComponents; k++)
	{
		//Extract that portion of the incoming signal that contains the complete transmitted signal
		//record for the given multipath component
		IncomingSignalComponent = IncomingSignal + *DelayPtr++;

		/*************************************************************
		//Debug Code
		fp = fopen("IncomingSignal.txt","w");
		for (j=0; j<SignalLength; j++)
			fprintf(fp,"%g %g\n",(IncomingSignalComponent+k)->real,(IncomingSignalComponent+k)->imaginary);
		fclose(fp);
		/*************************************************************/

		//Process one figuer of the RAKE reciever
		RakeFingerOutputPtr = STTDRakeFinger(DPCH_Format,IncomingSignalComponent,TransmittedSignalLength);

		//Combine RAKE finger output with the output of all the other RAKE fingers that have been proceed to date
		TempRakeFingerOutputPtr = RakeFingerOutputPtr;
		TempCombinedOutputPtr = CombinedOutputPtr;
		for (j=0; j<SymbolsPerFrame; j++)
			*TempCombinedOutputPtr++ = ComplexAdd(*TempCombinedOutputPtr,*TempRakeFingerOutputPtr++);
		free(RakeFingerOutputPtr);
	}
	//Detect data bits
	DataBits = DetectBits(DPCH_Format,CombinedOutputPtr);

/**********************************************************
	//Debug Code
	fp = fopen("ReceivedData.txt","w");
	for (k=0;k<((DPCH_Format.Ndata1+DPCH_Format.Ndata2)*15);k++)
		fprintf(fp,"%d\n",*(DataBits+k));
	fclose(fp);
/**********************************************************/

	return(DataBits);
}

ComplexNumber * ReceiverClass::STTDRakeFinger(DPCH_FormatStructure Format,ComplexNumber *IncomingSignal,unsigned SignalLength)
/********************************************************************************************************
* ComplexNumber * ReceiverClass::STTDRakeFinger(DPCH_FormatStructure Format,ComplexNumber *IncomingSignal,unsigned SignalLength)
*
* Copyright 2002 The Mobile and Portable Radio Research Group
*
* This funciton implements one finger of a "STTD" RAKE receiver.  Specifically, the function performs
* the following oeprations
*		Matched Filters and decimates the incoming singal
*		Descrambles the signal
*		Despreads the signal
*		Estimates the channels using the Pilot symbols.  These estimates are performed on a 
*			slot-by-slot basis
*		Performs soft STTD coding using the despread signal and the channel estimates
*		Returns the resultant signal
* Note that this prepares the signal for maximal ratio combining in the calling funciton
*
* Returns	An array of type ComplexNumber that contains the weighted, despread signal
*
* Parameters
*	Input
*		Format			DPCH_FormatStructure	Contains the formatting information for the desired channel
*		IncomingSignal	ComplexNumber *			Array that contains the incoming signal for the finger
*		SignalLength	unsigned				Length of the incoming signal
*********************************************************************************************************/
{
	ComplexNumber *FilteredSignal;	//Pointer to the array that contains the output of the 
									//receiver matched fitler
	ComplexNumber *DespreadSignal;	//Pointer to the array that contains the output of the despreader
	ComplexNumber *ChannelEstimates;//Pointer to the array that contains the channel estimates
	ComplexNumber *DecodedSignal;	//Pointer to the array that contains the decoded signal
	//FILE *fp;
	unsigned k;						//loop counter

	//Filter the Incoming Signal
	FilteredSignal = Filter(IncomingSignal,SignalLength,CHIPS_PER_FRAME);

	/******************************************************************
	fp=fopen("FilteredSignal.txt","w");
	for (k=0;k<CHIPS_PER_FRAME;k++) 
		fprintf(fp,"%g %g\n",(FilteredSignal+k)->real,(FilteredSignal+k)->imaginary);
	fclose(fp);
	/*********************************************************************************/

	//Descramble the Filtered Signal
	Descramble(FilteredSignal,ScrambleCode);

	/******************************************************************
	fp=fopen("DescrambledSignal.txt","w");
	for (k=0;k<CHIPS_PER_FRAME;k++) 
		fprintf(fp,"%g %g\n",(FilteredSignal+k)->real,(FilteredSignal+k)->imaginary);
	fclose(fp);
	/*********************************************************************************/


	//Despread the Descrambled Signal
	DespreadSignal = DespreadFrame(Format,FilteredSignal);
	free(FilteredSignal);

	/******************************************************************
	fp=fopen("DespreadSignal.txt","w");
	for (k=0;k<150;k++) 
		fprintf(fp,"%g %g\n",(DespreadSignal+k)->real,(DespreadSignal+k)->imaginary);
	fclose(fp);
	/*********************************************************************************/

	//Obtain Channel Estimates
	ChannelEstimates = STTDChannelEstimator(Format,DespreadSignal);

	//Peform STTD Soft Decode

	DecodedSignal = STTDSoftDecode(Format,ChannelEstimates,DespreadSignal);
	/******************************************************************
	fp=fopen("DecodedSignal.txt","w");
	for (k=0;k<150;k++) 
		fprintf(fp,"%g %g\n",(DecodedSignal+k)->real,(DecodedSignal+k)->imaginary);
	fclose(fp);
	/*********************************************************************************/

	//free channel estimate array
	free(ChannelEstimates);
	//free array containing despreaded signal
	free(DespreadSignal);

	//free array containing the soft decoded symbols
	return(DecodedSignal);
}


ComplexNumber * ReceiverClass::Filter(ComplexNumber *SignalPtr,unsigned IncomingSignalLength,unsigned FilteredSignalSamples)
/*************************************************************************************************
*ComplexNumber * ReceiverClass::Filter(ComplexNumber *SignalPtr,
*									   unsigned IncomingSignalLength,
*									   unsigned FilteredSignalSamples)*
*
* Copyright 2002 The Mobile and Portable Radio Research Group
*
*This function filters and decimates the incoming complex-valued signal with the FIR impulse 
*reponse stored in PulseShape.  The decimation rate is equal to SamplesPerChip.  Decimation is simply
*performed by filtering every SamplesPerChip'th output sample.  The "delay" and "tail" due to the 
*filtering is removed
*This fuction works on matrix of signal data, where each column in the the matrix is a  
*different signal
*
*Returns	A poiter to an array of type ComplexNumber that contains the values of the filtered
*			and decimated signal
*
*Parameters
*   Input
*      SignalPtr			ComplexNumber	Pointer to array of length NumSamples that stores the 
*										    signal values
*      IncomingSignalLength	unsigned		Length of incoming signal
*
*   Output
*      FilteredSignalSamples      unsigned     legnth of filtered signal
*
**************************************************************************************************/
{
	ComplexNumber *FilteredSignalPtr;	//Pointer to the array that contains the values fo the 
										//filtered and ecimated signal

	unsigned k1,k2;						//Loop counters
	unsigned PaddedLength;				//Length of signal array, included the necessary zero padding
//	double *InphasePaddedPtr,*QuadPaddedPtr;
	ComplexNumber *SigPtr;				//Temporary pointer to the signal array.  Used to determine the 
										//what elements of the incoming signal are to be included for
										//the filtering of a particular value
	ComplexNumber *FilterSigPtr;		//Temporary pointer to the filtered signal array
	ComplexNumber *FilterTmpPtr;		//Another temporary pointer to the filtered signal array
	ComplexNumber *TmpPtr;				//Temporary pointer to the signal array.  used to perform the 
										//Actuall filtering (i.e., multiplication with the pulse shape)
	double *PulseTmpPtr;				//Temporary pointer to the array that contains the pulse shape
	unsigned loopstart;					//Looping parameter.  Used to determine the start of a given for loop

	PaddedLength = IncomingSignalLength + 2 * PulseLength;
	//Allocated memory for filtered signal
	FilteredSignalPtr = (ComplexNumber *) calloc(FilteredSignalSamples,sizeof(ComplexNumber));
	if (FilteredSignalPtr == NULL)
	{
		printf("Memory Allocation to FilteredSignalPtr failed!--returning\n");

⌨️ 快捷键说明

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