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

📄 transmitterclass.cpp

📁 用matlab程序实现WCDMA系统的仿真
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/	Input/Output
/		FrameBufferPtr	ComplexNumber *			The first half of the array contains 
/												the unSTTD coded symbols (input 
/												portion).  The second half the array
/												(output portion) is a STTD coded 
/												version of the first half
/************************************************************************************/
{
	//*****************************************************************
	//Declare and define pilot bits for the second antenna
	const int N2Pilot2[30] =	{1,-1,
								-1,1,
								-1,-1,
								-1,1,
								1,1,
								1,-1,
								1,-1,
								1,1,
								-1,-1,
								1,-1,
								-1,-1,
								1,1,
								1,1,
								-1,1,
								-1,1};
	const int N4Pilot2[60] =	{1,-1,-1,1,
								-1,1,-1,1,
								-1,-1,-1,1,
								-1,1,-1,1,
								1,1,-1,1,
								1,-1,-1,1,
								1,-1,-1,1,
								1,1,-1,1,
								-1,-1,-1,1,
								1,-1,-1,1,
								-1,-1,-1,1,
								1,1,-1,1,
								1,1,-1,1,
								-1,1,-1,1,
								-1,1,-1,1};
	const int N8Pilot2[120] =	{-1,-1,1,1,1,1,-1,1,
								-1,-1,1,1,1,1,1,-1,
								-1,-1,-1,-1,1,1,1,1,
								-1,-1,-1,1,1,1,1,-1,
								-1,-1,-1,-1,1,1,-1,-1,
								-1,-1,1,1,1,1,-1,1,
								-1,-1,-1,1,1,1,-1,1,
								-1,-1,-1,1,1,1,-1,-1,
								-1,-1,1,1,1,1,1,1,
								-1,-1,1,-1,1,1,-1,1,
								-1,-1,-1,-1,1,1,1,1,
								-1,-1,1,-1,1,1,-1,-1,
								-1,-1,-1,1,1,1,-1,-1,
								-1,-1,1,-1,1,1,1,-1,
								-1,-1,1,-1,1,1,1,-1};
	const int N16Pilot2[240] =	{-1,-1,1,1,1,1,-1,1,-1,-1,1,1,1,1,-1,1,
								-1,-1,1,1,1,1,1,-1,-1,-1,-1,1,1,1,-1,1,
								-1,-1,-1,-1,1,1,1,1,-1,-1,-1,1,1,1,-1,-1,
								-1,-1,-1,1,1,1,1,-1,-1,-1,1,1,1,1,1,1,
								-1,-1,-1,-1,1,1,-1,-1,-1,-1,1,-1,1,1,-1,1,
								-1,-1,1,1,1,1,-1,1,-1,-1,-1,-1,1,1,1,1,
								-1,-1,-1,1,1,1,-1,1,-1,-1,1,-1,1,1,-1,-1,
								-1,-1,-1,1,1,1,-1,-1,-1,-1,-1,1,1,1,-1,-1,
								-1,-1,1,1,1,1,1,1,-1,-1,1,-1,1,1,1,-1,
								-1,-1,1,-1,1,1,-1,1,-1,-1,1,-1,1,1,1,-1,
								-1,-1,-1,-1,1,1,1,1,-1,-1,1,1,1,1,-1,1,
								-1,-1,1,-1,1,1,-1,-1,-1,-1,1,1,1,1,1,-1,
								-1,-1,-1,1,1,1,-1,-1,-1,-1,-1,-1,1,1,1,1,
								-1,-1,1,-1,1,1,1,-1,-1,-1,-1,1,1,1,1,-1,
								-1,-1,1,-1,1,1,1,-1,-1,-1,-1,-1,1,1,-1,-1};
	const int N4Pilot2A[60] =	{1,-1,-1,1,
								-1,1,1,-1,
								-1,-1,1,1,
								-1,1,1,-1,
								1,1,-1,-1,
								1,-1,-1,1,
								1,-1,-1,1,
								1,1,-1,-1,
								-1,-1,1,1,
								1,-1,-1,1,
								-1,-1,1,1,
								1,1,-1,-1,
								1,1,-1,-1,
								-1,1,1,-1,
								-1,1,1,-1};

	//Pilot bits for the second antenna declared and defined
	//*****************************************************************
	ComplexNumber *Antenna1Ptr;		//Pointer to the symbol sequence for antenna1
	ComplexNumber *Antenna2Ptr;		//Pointer to the symbol sequence for antenna2 (the STTD coded antenna)
	ComplexNumber *Antenna1NextPtr;	//Points to the symbol sequence in antenna 1.  However, this pointer is
									//always one symbol ahead of *Antenna1Ptr
	unsigned j,k;					//Loop Counters
	int *PilotPtr,*TempPilotPtr;	//Pointer and temporary pointer to the appropriate pilot symbol array
	unsigned NumIterations;			//Tracks the number of iterations in a given loop
	unsigned NumPilotIterations;	//Tracks the number of iterations in the loop associated with the pilot bits
	int result1,result2;			//Used to determine the result of string comparison operatons


	//Identify the correct collection of Pilot bits
	if (format.NPilot == 2) PilotPtr = (int *) N2Pilot2;
	else if (format.NPilot == 4) PilotPtr = (int *) N4Pilot2;
	else if (format.NPilot == 8) PilotPtr = (int *) N8Pilot2;
	else if (format.NPilot == 16) PilotPtr = (int*) N16Pilot2;
	else
	{
		printf("\nformat.NPilot = %d is incorrect. NPilot must be 2,4,8, or 16--Exiting\n",format.NPilot);
		return(-1);
	}
	result1 = strcmp(format.format,"2B ");
	result2 = strcmp(format.format,"3B ");
	if ( (result1 == 0) || (result2 == 0)) PilotPtr = (int *) N4Pilot2A;

	Antenna1Ptr=FrameBufferPtr;	//Have Antenna1Ptr point to the begining of the symbol array which is destined
								//to antenna 1
	Antenna1NextPtr = FrameBufferPtr+1;	//Have Antenna1NextPtr point to second symbol in the array destined
										//to antenna1
	Antenna2Ptr = FrameBufferPtr + SymbolsPerFrame;	//Have Antenna2Ptr point to the begining of the 
													//symbol array for antenna2.  This is located in
													//the second  half of FrameBufferPtr
	TempPilotPtr = PilotPtr;	//Temporary pointer for the pilot bits

	//***********************************************************************************
	//The STTD codding approad is the same for all case EXCEPT for the case where SF=512 and  
	//for the case where the number of pilot bits per slot (NPilot) is 2.
	if (format.SF == 512)
	{
		//If the Spreading Factor is 512, then there are no bits in the data1 field
		//and we can proceed to the next field, which is the TPC field.  the two bits are not coded,
		//but the next four bits are.  The last four bits, which are Pilot bits, are then derived
		//from one N4Pilot2 array.  Note that the even numberd bits are in the inphase portion of the symbol
		//and the odd numbered bits are in the quadrature portion of the symbol.  This function
		//will apply the STTD coding on a symbol-by-symbol basis
		for (k=0; k<15; k++)
		{
			//Copy first symbol
			*Antenna2Ptr++ = *Antenna1Ptr++;
			Antenna1NextPtr++;

			//STTD code the Next two Symbols
			Antenna2Ptr->real = -(Antenna1NextPtr->real);
			Antenna2Ptr->imaginary = Antenna1NextPtr->imaginary;
			Antenna2Ptr++;
			Antenna2Ptr->real = Antenna1Ptr->real;
			Antenna2Ptr->imaginary = - (Antenna1Ptr->imaginary);
			Antenna1Ptr += 2;
			Antenna1NextPtr += 2;
			Antenna2Ptr++;

			//Assign Pilot Codes
			Antenna2Ptr->real = (double) *TempPilotPtr++;
			Antenna2Ptr->imaginary = (double) *TempPilotPtr++;
			Antenna2Ptr++;
			Antenna2Ptr->real = (double) *TempPilotPtr++;
			Antenna2Ptr->imaginary = (double) *TempPilotPtr++;
			Antenna1Ptr += 2;
			Antenna1NextPtr += 2;

		}
	}
	else if (format.NPilot == 2)
	{
		//STTD coding is applied to all of the bits INCLUDING the Pilot bits.  
		//Note that the pilot symbol will now be preceeding the last Ndata2 symbol
		//Also note that the coded pilot symbol (bits) will be identical to the bits
		//defined in the N2PILOT2 array
		NumIterations = (format.BitsPerSlot) >> 2;

		for (k=0; k<15; k++)
		{
			for (j=0; j<NumIterations; j++)
			{
				Antenna2Ptr->real = - (Antenna1NextPtr->real);
				Antenna2Ptr->imaginary = Antenna1NextPtr->imaginary;
				Antenna2Ptr++;
				Antenna2Ptr->real = Antenna1Ptr->real;
				Antenna2Ptr->imaginary = - (Antenna1Ptr->imaginary);
				Antenna2Ptr++;
				Antenna1Ptr += 2;
				Antenna1NextPtr += 2;
			}
		}
	}
	else 
	{
		//STTD coding is applied to all of the bits with the exception of PilotBits, whcih are obtained from 
		//one of the above constant arrays
		NumIterations = (format.Ndata1 + format.Ndata2 + format.Ntfci + format.Ntpc) >> 2;
		NumPilotIterations = format.NPilot >> 1;

		for (k=0; k<15; k++)
		{
			for (j=0; j<NumIterations; j++)
			{
				//STTD code all fields except the pilot fields
				Antenna2Ptr->real = - (Antenna1NextPtr->real);
				Antenna2Ptr->imaginary = Antenna1NextPtr->imaginary;
				Antenna2Ptr++;
				Antenna2Ptr->real = Antenna1Ptr->real;
				Antenna2Ptr->imaginary = - (Antenna1Ptr->imaginary);
				Antenna2Ptr++;
				Antenna1Ptr += 2;
				Antenna1NextPtr += 2;
			}

			//Copy over the pilot fields
			for (j=0; j<NumPilotIterations; j++)
			{
				Antenna2Ptr->real = (double) *TempPilotPtr++;
				Antenna2Ptr->imaginary = (double) *TempPilotPtr++;
				Antenna2Ptr++;
			}
			Antenna1Ptr += NumPilotIterations;
			Antenna1NextPtr += NumPilotIterations;
		}
	}
	return (0);
}



ComplexNumber *TransmitterClass::GenDPCCHforCPCH(int *ChanCode,
										 ComplexNumber *ScrambleCode,
										 unsigned TPCCommand,
										 bool STTDflag)
/****************************************************************************************
/ComplexNumber *TransmitterClass::GenDPCCHforCPCH(int *ChanCode,
/										 ComplexNumber *ScrambleCode,
/										 unsigned TPCCommand,
/										 bool STTDflag)
/
/ Copyright 2002 The Mobile and Portable Radio Research Group
/
/ Generates the GenDPCCH for CPCH frame.  The funciton places the data in complex number 
/ format and then spreads the data.  The resutlatant data is then scambled via the 
/ scamble code and a pointer to the spreaded and scrambled frame is then returned.  
/
/
/ Returns	Pointer to the array that stores the spreaded and scrambled frame
/
/Parameters
/	Input
/		ChannelCode		int *					Contains the array that stores the Channel Code
/		ScrambleCode	ComplexNumber *			Contains the array that stores the scamble Code
/		TPCCommand		unsigned				Transmit Power Control Command--either a 0 or a 1
/		STTDflag		bool					Flag which determines if STTD is employed
/												or an interfering frame
*********************************************************************************************/
{
	//*****************************************************************
	//Declare and define pilot bits
	const int Npilot4[60]=	{-1,-1,-1,-1,
							-1,-1,1,1,
							-1,-1,1,-1,
							-1,-1,1,1,
							-1,-1,-1,1,
							-1,-1,-1,-1,
							-1,-1,-1,-1,
							-1,-1,-1,1,
							-1,-1,1,-1,
							-1,-1,-1,-1,
							-1,-1,1,-1,
							-1,-1,-1,1,
							-1,-1,-1,1,
							-1,-1,1,1,
							-1,-1,1,1};

	const int N4Pilot2[60] =	{1,-1,-1,1,
								-1,1,-1,1,
								-1,-1,-1,1,
								-1,1,-1,1,
								1,1,-1,1,
								1,-1,-1,1,
								1,-1,-1,1,
								1,1,-1,1,
								-1,-1,-1,1,
								1,-1,-1,1,
								-1,-1,-1,1,
								1,1,-1,1,
								1,1,-1,1,
								-1,1,-1,1,
								-1,1,-1,1};
	//Pilot bits defined and decoared
	//*****************************************************************

	int TPCsymbol;			//Stores the TPC symbol (ether a -1 or a 1)
	int *tempPilotPtr;		//Temporary pointer used to track the current pilot bit
	ComplexNumber *FrameBufferPtr,*TempFrameBufferPtr;	//Used to store the symbols used in the frame
	//The following variables are used for STTD coding (when enabled)
	ComplexNumber *Antenna1Ptr;			//Tracks the symbols allocated for Antenna 1
	ComplexNumber *Antenna1NextPtr;		//Tracks the symbols allocated for antenna 1
										//However, it also leads Antenna1Ptr by one symbols
	ComplexNumber *Antenna2Ptr;			//Tracks the symbols allocated for antenna2
	unsigned BitsPerFrame;				//Bits per frame = 150
	unsigned SymbolsPerFrame;			//Symbols per frame = 75
	double RandomNumber;				//Stores uniformly generated random number
	unsigned k,j;						//Loop counters
	unsigned CodeLength;				//Length of the array containing the spreaded and scrambled frame
										//If STTD is enabled then the code Length is 76,800.  Otherwise
										//the code length is 38,400.
	int *TempChanCodePtr;				//Temporary pointer to the channelization code
	ComplexNumber *TempChipSequencePtr,*ChipSequencePtr;	//Stores the spreaded and scrambled chipping 
															//sequence for the entire frame
	ComplexNumber *TempScrambleCodePtr;	//Temporary pointer to the scramble code
	int RandInitFlag=1;					//Initialization flag for random number generator
										//Set ot one because no initialization is requried

	//Set the bits per frame
	BitsPerFrame = 150;
	//Set the symbols per frame
	SymbolsPerFrame = 75;
	//Compute the TPCsymbol
	TPCsymbol = 1-2*TPCCommand;


	if (STTDflag)
		//if STTD is enabled then the frame will contain 150 symbols; 75 symbols per antenna
		FrameBufferPtr = (ComplexNumber *) calloc(150,sizeof(ComplexNumber));
	else
		//Otherwise the frame will contains 75 symbols
		FrameBufferPtr = (ComplexNumber *) calloc(75,sizeof(ComplexNumber));

	if (FrameBufferPtr == NULL)
	{
		printf("\nAllocation of memory to FrameBufferPtr failed--exiting\n");
		return(NULL);
	}

	//Initialize the temporary pilot pointer
	tempPilotPtr = (int *) Npilot4;
	//Initialize the temporary frame buffer pointer
	TempFrameBufferPtr = FrameBufferPtr;
	//Load the frame buffer on a slot by slot basis
	for (k=0; k<15; k++)
	{
		//TPC field
		TempFrameBufferPtr->real = (double) TPCsymbol;
		TempFrameBufferPtr->imaginary = (double) TPCsymbol;
		TempFrameBufferPtr++;

		//N_CCC Field (4 bits -- 2 symbols)
		RandomNumber = UniformRand

⌨️ 快捷键说明

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