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

📄 receiverclass.cpp

📁 WCDMA的仿真程序,分别用C和MATLAB两种语言仿真
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	NumPilotSymbols = (Format.NPilot >> 1);
	//Determine the postion of th efirst pilot symbol in any given slot
	PilotPositionInSlot = (Format.BitsPerSlot >> 1) - NumPilotSymbols;
	//Determine the number slots per frame
	SlotsPerFrame = Format.ActualSlotsPerFrame;

	//Get the correct Pilot Symbols
	switch (Format.NPilot)
	{
		case 2:
			PilotPtr = (ComplexNumber *) Npilot2;
//			Pilot2Ptr = (ComplexNumber *) N2Pilot2;
			break;
		case 4:
			PilotPtr = (ComplexNumber *) Npilot4;
//			Pilot2Ptr = (ComplexNumber *) N4Pilot2;
			break;
		case 8:
			PilotPtr = (ComplexNumber *) Npilot8;
//			Pilot2Ptr = (ComplexNumber *) N8Pilot2;
			break;
		case 16:
			PilotPtr = (ComplexNumber *) Npilot16;
//			Pilot2Ptr = (ComplexNumber *) N16Pilot2;
			break;
	}

	//Initialize the Channel Estimate Vector
	ChannelEstimatePtr = (ComplexNumber *) calloc(2*SlotsPerFrame,sizeof(ComplexNumber));
	if (ChannelEstimatePtr == NULL)
	{
		printf("Memory allocation for ChannelEstimatePtr failed--exiting\n");
		return(NULL);
	}

	//Now Perform the channel Estimates--One estimate per Slot
	//The estimates are obtained by dividing the despread symbol by the known pilot symbol
	//for that particular location.  Then for each slot, these estimates are averaged
	TempChannelEstimatePtr = ChannelEstimatePtr;
	TempDespreadSignalPtr = DespreadSignal;
	TempPilotPtr = PilotPtr;
	if (NumPilotSymbols==1)
	{
		for (k=0; k<SlotsPerFrame; k++)
		{
			TempDespreadSignalPtr += (PilotPositionInSlot - 1);
			r0 = *TempDespreadSignalPtr++;
			r1 = *TempDespreadSignalPtr++;
			s1 = *TempPilotPtr++;
			TempEstimate0.real = 0.0;
			TempEstimate0.imaginary = 0.0;
			TempEstimate1.real = 0.0;
			TempEstimate1.imaginary = 0.0;


			//Since we only have one pilot symbol (and two are really need to performe the estimation)
			//The estimate is obtained by averaging four channel estimates, where each is conditioned on the 
			//previous symbol location being one of four possible values ({1,1},{1,-1}, {-1,1}, {-1,-1})
			for (j=0; j<4; j++)
			{
				s0 = Sdata[j];
				fee = ComplexMultiply(Conjugate(s0),r0);
				foo = ComplexMultiply(Conjugate(s1),r1);
				TempEstimate0 = ComplexAdd(TempEstimate0,ComplexRealMultiply(0.25,ComplexAdd(fee,foo)));
				fee = ComplexMultiply(s0,r1);
				foo = ComplexMultiply(s1,r0);
				TempEstimate1 = ComplexAdd(TempEstimate1,ComplexRealMultiply(0.25,ComplexAdd(fee,foo)));
			}
			*TempChannelEstimatePtr++ = ComplexRealDivide(TempEstimate0,(double) (4 * SF));
			*TempChannelEstimatePtr++ = ComplexRealDivide(TempEstimate1,(double) (4 * SF));
		}

	}
	else if (NumPilotSymbols == 2)
	{
		for (k=0; k<SlotsPerFrame; k++)
		{
			//The pilot symbols associated with the 2nd transmitted antenna are nothing more
			//than the STTD coded version of the pilot symbols associated with the 1st Tx antenna
			//This fact is exploited in the decoding process
			TempDespreadSignalPtr += PilotPositionInSlot;
			s0 = *TempPilotPtr++;
			s1 = *TempPilotPtr++;
			r0 = *TempDespreadSignalPtr++;
			r1 = *TempDespreadSignalPtr++;
			fee = ComplexMultiply(Conjugate(s0),r0);
			foo = ComplexMultiply(Conjugate(s1),r1);
			TempEstimate0 = ComplexRealMultiply(0.25,ComplexAdd(fee,foo));
			fee = ComplexMultiply(s0,r1);
			foo = ComplexMultiply(s1,r0);
			TempEstimate1 = ComplexRealMultiply(0.25,ComplexSubtract(fee,foo));

			*TempChannelEstimatePtr++ = ComplexRealDivide(TempEstimate0, (double)  SF);
			*TempChannelEstimatePtr++ = ComplexRealDivide(TempEstimate1, (double)  SF);
		}
	}
	else if (NumPilotSymbols == 4)
	{
		for (k=0; k<SlotsPerFrame; k++)
		{
			TempDespreadSignalPtr += PilotPositionInSlot;
			s = *TempPilotPtr++;
			s0 = *TempPilotPtr++;
			TempPilotPtr++;
			s1 = *TempPilotPtr++;
			r0 = *TempDespreadSignalPtr++;
			r1 = *TempDespreadSignalPtr++;
			r2 = *TempDespreadSignalPtr++;
			r3 = *TempDespreadSignalPtr++;

			//Use orthogonal Pilot symbol sequence (Positions 0 and 2)
			fee = ComplexAdd(r0,r2);
			foo = ComplexRealMultiply(2.0,s);
			TempEstimate0 = ComplexDivide(fee,foo);
			fee = ComplexSubtract(r0,r2);
			TempEstimate1 = ComplexDivide(fee,foo);


			//Use the STTD Coded Pilot Symbol sequence (Positions 1 and 3)
			fee = ComplexMultiply(Conjugate(s0),r1);
			foo = ComplexMultiply(Conjugate(s1),r3);
			TempEstimate0 = ComplexAdd(TempEstimate0,ComplexRealMultiply(0.25,ComplexAdd(fee,foo)));
			fee = ComplexMultiply(s0,r3);
			foo = ComplexMultiply(s1,r1);
			TempEstimate1 = ComplexAdd(TempEstimate1,ComplexRealMultiply(0.25,ComplexAdd(fee,foo)));

			//Average the estiamtes
			*TempChannelEstimatePtr++ = ComplexRealDivide(TempEstimate0, (double)  2 * SF);
			*TempChannelEstimatePtr++ = ComplexRealDivide(TempEstimate1, (double)  2 * SF);
		}
	}
	else if (NumPilotSymbols == 8)
	{
		for (k=0; k<SlotsPerFrame; k++)
		{
			TempDespreadSignalPtr += PilotPositionInSlot;
			r0 = *TempDespreadSignalPtr++;
			r1 = *TempDespreadSignalPtr++;
			r2 = *TempDespreadSignalPtr++;
			r3 = *TempDespreadSignalPtr++;
			r4 = *TempDespreadSignalPtr++;
			r5 = *TempDespreadSignalPtr++;
			r6 = *TempDespreadSignalPtr++;
			r7 = *TempDespreadSignalPtr++;
			s = *TempPilotPtr++;

			//Use orthogonal Pilot symbol sequence--Positions 0 and 2
			fee = ComplexAdd(r0,r2);
			foo = ComplexRealMultiply(2.0,s);
			TempEstimate0 = ComplexDivide(fee,foo);
			fee = ComplexSubtract(r0,r2);
			TempEstimate1 = ComplexDivide(fee,foo);

			//Use orthogonal Pilot symbol sequence--Positions 4 and 6
			fee = ComplexAdd(r4,r6);
			foo = ComplexRealMultiply(2.0,s);
			TempEstimate0 = ComplexAdd(TempEstimate0,ComplexDivide(fee,foo));
			fee = ComplexSubtract(r4,r6);
			TempEstimate1 = ComplexAdd(TempEstimate1,ComplexDivide(fee,foo));

			//Use the STTD Coded Pilot Symbol sequence (Positions 1 and 3)
			s0 = *TempPilotPtr++;
			TempPilotPtr++;
			s1 = *TempPilotPtr++;
			TempPilotPtr++;
			fee = ComplexMultiply(Conjugate(s0),r1);
			foo = ComplexMultiply(Conjugate(s1),r3);
			TempEstimate0 = ComplexAdd(TempEstimate0,ComplexRealMultiply(0.25,ComplexAdd(fee,foo)));
			fee = ComplexMultiply(s0,r3);
			foo = ComplexMultiply(s1,r1);
			TempEstimate1 = ComplexAdd(TempEstimate1,ComplexRealMultiply(0.25,ComplexAdd(fee,foo)));

			//Use the STTD Coded Pilot Symbol sequence (Positions 5 and 7)
			s0 = *TempPilotPtr++;
			TempPilotPtr++;
			s1 = *TempPilotPtr++;
			TempPilotPtr++;
			fee = ComplexMultiply(Conjugate(s0),r1);
			foo = ComplexMultiply(Conjugate(s1),r3);
			TempEstimate0 = ComplexAdd(TempEstimate0,ComplexRealMultiply(0.25,ComplexAdd(fee,foo)));
			fee = ComplexMultiply(s0,r3);
			foo = ComplexMultiply(s1,r1);
			TempEstimate1 = ComplexAdd(TempEstimate1,ComplexRealMultiply(0.25,ComplexAdd(fee,foo)));

			//Average the estimates
			*TempChannelEstimatePtr++ = ComplexRealDivide(TempEstimate0, (double)  4 * SF);
			*TempChannelEstimatePtr++ = ComplexRealDivide(TempEstimate1, (double)  4 * SF);
		}
	}
	else
	{
		printf("Number of Pilot bits must be 2,4,8. or 16! Current value is %d---exiting\n",NumPilotSymbols << 1);
		return(NULL);
	}

	return(ChannelEstimatePtr);

}

ComplexNumber * ReceiverClass::STTDSoftDecode(DPCH_FormatStructure Format,ComplexNumber *ChannelEstimates,ComplexNumber* DespreadSignal)
/******************************************************************************************************************************
* ComplexNumber * ReceiverClass::STTDSoftDecode(DPCH_FormatStructure Format,ComplexNumber *ChannelEstimates,ComplexNumber* DespreadSignal)
*
* Copyright 2002 The Mobile and Portable Radio Research Group
*
* The function performs the soft STTD decoding.  Let h0 and h1 be the channel estimates from Tx antenna 0 and Tx antenna 1 
* to the receiver.  Let r0 and r1 be the first and second depsreaded signal values in a particualr slot.  Then the soft 
* decoded value for the first symbol in the slot, s0, is
*      ((conj(h0) * r0) + (h1 * conj(r1)))/((conj(h0) * h0) (conj(h1) * h1))
* and the solft decoded value for the second symbol, s1, is
*      ((conj(h0) * r1) - (h1 * conj(r0)))/((conj(h0) * h0) (conj(h1) * h1))
* 
* Then the third and fourth despread signal values are assigned to r0 and r1, respectively and the decoding continues.
*
* Note that this procedure will correctly decode all of the data bits.  However, when the Number of Pilot bits per slot 
* (NPilot) is 8 or 16, it will not correctly decode the pilot bits.  This is because, the pilot symbols are not simply STTD 
* encoded version of each other.  Rather, the pilot bits on the second antenna use a combination of STTD encoding and 
* orthogonal encondeing
*
* Returns	A ComplexNumber array that contains the soft decoded output
*
* Parameters
*	Format			DPCH_FormatStructure	Contains the format information of the desired frame
*	DespreadSignal	ComplexNumber *			Contains the despread symbol values
*	ChannelEstimate	ComplexNumber *			Contains the Channel Estimates
*******************************************************************************************************************************/
{
	ComplexNumber *DecodedSignalPtr, *TempDecodedSignalPtr;	//Pointer and temporary pointer to the array that contains
															//the decoded signal
	ComplexNumber *TempDespreadSignal;			//Temporary pointer to the array that contains the despread signal
	ComplexNumber *TempChannelEstimates;		//Temporary pointer to the array that contains the channel estimates
	ComplexNumber r0,r1;		//Despread Signal Values
	ComplexNumber h0,h1;		//ChannelEstimates for the Given Frame
	ComplexNumber fee,foo;		//Temporary storage (general use)
	unsigned SF;				//Spreading factor
	unsigned j,k;				//loop counters
	unsigned IterationsPerSlot;	//The number of decoding iterations required for a slot (=0.5 * # of symbols per slot)
	unsigned SymbolsPerSlot;	//The number of symbols in a slot
	unsigned SlotsPerFrame;		//The number of slots per frame
	unsigned SymbolsPerFrame;	//The number of symbols in a given frame

	//Get the spreading factor
	SF = Format.SF;
	//Get the number of symbols in a given slot
	SymbolsPerSlot = Format.BitsPerSlot >> 1;
	//Get the number of symples for the entire frame
	SymbolsPerFrame = SymbolsPerSlot * Format.ActualSlotsPerFrame;
	//Get the number of slots for the entire frame
	SlotsPerFrame = Format.ActualSlotsPerFrame;
	//Compute the number of decoding iterations per slot
	IterationsPerSlot = SymbolsPerSlot >> 1;

	//Allocate Output Array
	DecodedSignalPtr = (ComplexNumber *) calloc(SymbolsPerFrame,sizeof(ComplexNumber));
	if (DecodedSignalPtr == NULL)
	{
		printf("\nMemory allocation for DecodedSignalPtr failed--exiting\n");
		return(NULL);
	}

	//Assign Temporary Pointers
	TempChannelEstimates = ChannelEstimates;
	TempDespreadSignal = DespreadSignal;
	TempDecodedSignalPtr = DecodedSignalPtr;
	//Perform the decoding
	for (k=0; k<SlotsPerFrame; k++)
	{
		//Get ChannelEstimates
		h0 = *TempChannelEstimates++;
		h1 = *TempChannelEstimates++;

		//Now go through all of the symbols in the slot
		for (j=0; j<IterationsPerSlot; j++)
		{
			r0 = *TempDespreadSignal++;
			r1 = *TempDespreadSignal++;

			fee = ComplexMultiply(Conjugate(h0),r0);
			foo = ComplexMultiply(h1,Conjugate(r1));
			*TempDecodedSignalPtr++ = ComplexAdd(fee,foo);

			fee = ComplexMultiply(Conjugate(h0),r1);
			foo = ComplexMultiply(h1,Conjugate(r0));
			*TempDecodedSignalPtr++ = ComplexSubtract(fee,foo);
		}
	}
	return(DecodedSignalPtr);
}

⌨️ 快捷键说明

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