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

📄 clinkprediction.cpp

📁 这是cdma2000的一个分组调度算法实例
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	for (i=0;i<m_iPacketSizeNum;i++)
	{
		tempEPS2CI=&m_pstRatePredictionTable[i];
		iEPSize=tempEPS2CI->iEncoderPacketSize;
	
	//find in the second level of the table
		for (j=tempEPS2CI->iRATE2CILength-1;j>=0;j--)
		{
			tempRATE2CI=&(tempEPS2CI->pstAddrOfRate2CI)[j];
			fCIdB=tempRATE2CI->fTargetC2I;
			iPacketLength=tempRATE2CI->iSlotNumPerSubPacket;
			for(k=0;k<4;k++)
			{
				if(iPacketLength==pow(2,k))
				{
					for(l=0;l<5;l++)
					{
						if(iChannelType==l+1)
						{
							fC2INeededdB=SPDCCHEbNt[k][l]-ProcessGain[k];
							fPowerMargindB=SPDCCHPowerMargin[k][l];
							m_fDeterminedErrorRate=float(SPDCCHErrorRate[k][l]);
							break;
						}
				
					}
				break;
				}
		
			}

			fSPDCCHSlotC2I=pow(10,(fC2INeededdB+fPowerMargindB)/10);
			fPDCHSlotC2I=pow(10,fC2IdB/10)-fSPDCCHSlotC2I;
			if(fPDCHSlotC2I<=0.0) continue;
			fPDCHSlotC2IdB=10*log10(fPDCHSlotC2I);
			if (fPDCHSlotC2IdB>=fCIdB)
			{
				bIsDataRateDetermined=true;
				break;
			}
			fLastCIdB=fCIdB;
		}
		if(bIsDataRateDetermined&&lDataQueueSize>=iEPSize) break;
		else tempRATE2CI=NULL;
	}
	if(tempRATE2CI) 
	{
		m_iDeterminedPacketSize=iEPSize;
	}
	else
	{
		tempEPS2CI=&m_pstRatePredictionTable[3];
		tempRATE2CI=&(tempEPS2CI->pstAddrOfRate2CI)[0];
		m_iDeterminedPacketSize=384;
		fSPDCCHSlotC2I=pow(10,(SPDCCHEbNt[3][iChannelType-1]-ProcessGain[3]+SPDCCHPowerMargin[3][iChannelType-1])/10);
	}
	m_fDeterminedSPDCHC2I=float(fSPDCCHSlotC2I);


	return tempRATE2CI;
}



//////////////////////////////////////////////////////////////////////////
//
//	TITLE:	Getting BLER Function
//
//	PURPOSE:通过查BLER估计表,获得相应的BLER数据,参数为分组长度,等效SNR的
//			均值和标准差,等效编码速率
//
//	SAMPLE CALL:
//			CLinkPrediction* pLink;
//			float fBLER=pLink->GetBLER(1536, 10., 0.4, 0.033333);
//
//	INPUTS:	iPacketSize	 -- the length of the packet
//							should be given precisely and only these 4
//							values are legal:
//							3072, 1536, 768, 384
//			fMeanSNR	 -- the mean value of SNR
//			fStdSNR		 -- the standard deviation of SNR
//			fEncodingRate-- the encoder packet rate
//
//	OUTPUTS:
//			fBLER		--	the block error
//
//	CALLED BY FUNCTIONS:
//			CDataMs::PERPrediction()
//
//	CALLING FUNCTIONS:
//			CLinkPrediction::Interpolation()
//			CLinkPrediction::GetFourPoints()
//
//	AUTHOR:	Ouyang Hui
//
//	DATE:	01/04/04
//
//
//	MODIFICATIONS SINCE 01/04/04:
//			01/04/04	Add the interpolation algorithm
//
//			01/04/05	Modified the interpolation algorithm
//			Key points:
//			In the previous version, the function needs precise encoder
//			packet rate. If this condiction cannot be satisfied, the
//			would report an error and reject to return a value.
//			Of course, this is not reasonable, because actually the 
//			encoder packet rates are not subject to the eight points
//			in the list. So I modified the codes in this way:
//
//			1, When the input encoder packet rate cannot be found in the
//			list, the function finds the two nearest values that assure
//			the input value is between them. (Of course, if the input is
//			larger or smaller than all the values in the list, the two
//			values are both the largest or the smallest one in the list.)
//
//			2.Then we get the two SNR-to-BLER list according to the two
//			encoder packet rate values found in step 1. Then we get the
//			two BLER values in these two list independently using 2-D
//			interpolation method.
//
//			3.Get the final BLER value according to the two BLER values
//			found in step 2, using 1-D interpolation method.
//							
//		01/04/06	Ouyang Hui 
//			Modify the part getting the two nearest values described
//			in the first step of last section. This time the function
//			assures x1<=x<=x2 and y1<=y<=y2.
//
//		01/04/11 to 01/04/12	Ouyang Hui
//			Modify the part of interpolation. The function uses it with
//			four points. See the function CLinkPrediction::Interpolation().
//			Now the problem is HOW TO GET THESE FOUR POINTS. Since the 
//			algorithms are somewhat intricate. I move the job to a newly
//			added function CLinkPrediction::GetFourPoints(). Today, I test
//			this function and succeed. If you want to know more, please
//			see the comments of CLinkPrediction::GetFourPoints() and the
//			document on the test of this function. 
//
//////////////////////////////////////////////////////////////////////////
float CLinkPrediction::GetBLER(int iPacketSize, float fMeanSNR, 
							  float fStdSNR, float fEncodingRate)
{
	EPS2BLER1_TYPE* pEPS2BLER1;
	RATE2BLER1_TYPE* pRATE2BLER1[2];
//	SNR2BLER1_TYPE* pSNR2BLER1[2];
	int i;

	//find in the first level of the table
	for (i=0;i<m_iPacketSizeNum;i++)
	{
		pEPS2BLER1=&m_pstBLERPredictionTable[i];
		if (fabs(pEPS2BLER1->iEncoderPacketSize-iPacketSize)<1e-6) 
			break;
	}
	if (i==m_iPacketSizeNum)
	{
		cerr<<"Illegal encoder packet size of "<<iPacketSize<<endl
			<<"Can't find this kind of packet size in the table!"<<endl;
		return 1.0;
	}

	//find in the second level of the table
	//we can get two copies of the third level of the table
	for (i=0;i<pEPS2BLER1->iRATE2BLER1Length;i++)
	{
		pRATE2BLER1[1]=&(pEPS2BLER1->pstAddrOfRate2BLER)[i];
		if (fEncodingRate<pRATE2BLER1[1]->fEffectiveCodeRate)
			break;
		pRATE2BLER1[0]=pRATE2BLER1[1];
	}
	if (i==0)
		pRATE2BLER1[0]=pRATE2BLER1[1];
	
	float m0=pRATE2BLER1[0]->fEffectiveCodeRate;
	float m1=pRATE2BLER1[1]->fEffectiveCodeRate;
	float m =fEncodingRate;

	int j;

	float x1[2],x2[2],x3[2],x4[2],x[2];
	float y1[2],y2[2],y3[2],y4[2],y[2];
	float z1[2],z2[2],z3[3],z4[2],z[2];
	float zz;
	int iDoingTimes;

	if (pRATE2BLER1[0]==pRATE2BLER1[1])
		iDoingTimes=1;
	else
		iDoingTimes=2;

	//deal with the third level of the table
	for (j=0;j<iDoingTimes;j++)
	{
		x[j]=fMeanSNR;
		y[j]=fStdSNR;

		GetFourPoints(pRATE2BLER1[j],x[j],y[j],x1[j],y1[j],z1[j],
			x2[j],y2[j],z2[j],x3[j],y3[j],z3[j],x4[j],y4[j],z4[j]);

		z[j]=Interpolation(x1[j],x2[j],x3[j],x4[j],x[j],
			y1[j],y2[j],y3[j],y4[j],y[j],
			z1[j],z2[j],z3[j],z4[j]);
	}

	if (z[0]<1e-4)
		z[0]=-4;
	else
		z[0]=(float)log10(z[0]);

	if (iDoingTimes==1)
	{
		zz=z[0];
		
	}
	else
	{
		if (z[1]<1e-4)
			z[1]=-4;
		else
			z[1]=(float)log10(z[1]);
		if (m0==m1)
			zz=z[0];
		else
			zz=((m1-m)*z[0]+(m-m0)*z[1])/(m1-m0);
	}

	zz=(float)pow(10,zz);

	return zz;

}

///////////////////////////////////////////////////////////////////////////////
//
//	PURPOSE:Given a point (x,y), get the four adjacent points (x1,y1), (x2,y2)
//			(x3,y3), (x4,y4), and the values at these four points: z1, z2, z3,
//			and z4. Be sure that x1<=x<=x2, y1<=y<=y3, x1=x3, x2=x4, y1=y2,
//			and y3=y4. (Of course, when (x,y) is outside the boudary of the 
//			points in the list, the first two condiction cannot be satisfied.
//			Then the four points should be the closest ones to (x,y) at the
//			boundary). To employ this function correctly, the order and the 
//			values of the inputted list should be very strict. So the function
//			of initialization should include checking the table of EPS-to-
//			BLER.
//
//	INPUTS: A point of (x,y)
//
//	OUTPUTS:Four points of (x1,y1), (x2,y2), (x3,y3), (x4,y4) and the values
//			at these four points of z1, z2, z3, z4.
//
//	CALLED BY FUNCTIONS:
//			CLinkPrediction::GetBLER()
//
//	ALGORITHMS:
//			This function seems very simple to implement, but actually the
//			algorithms are very intricate. This is due to the following
//			two reasoms:
//			1. The order of the inputted list. Although the points are 2-D
//          points, the list is organized in one-dimension. For example, if
//			there are 9 points from (1,1) to (9,9), the organization in the 
//			list should be:
//				(1,1,xx)
//				(1,2,xx)
//				(1,3,xx)
//				(2,1,xx)
//				......
//				(9,9,xx).
//			And it needs special treatment while scanning from (1,3) to (2,1).
//			2. While the x- or y-coordinate or the inputted point (x,y) is
//			outside the range of all the points in the list, the expected
//			four points would shrink to one or two points. And it is very
//			difficult to determine the points.
//
//			The algorithms can be described as two steps:
//			1. Find (x1,y1,z1) and (x4,y4,z4). Mark their indexes in the list.
//			2. The points (x1,y1) and (x3,y3) are adjacent or the same, so are
//			(x2,y2) and (x4,y4). And when (x1,y1) is at the boundary, (x4,y4)
//			is at the same boudary. So when (x1,y1) and (x4,y4) determined in
//			step 1 are correct, it is easy to determine (x2,y2,z2) and
//			(x3,y3,z3).
//			So the key point is in step one. There are nine cases shuld be
//			considered, and eight of them are the cases while (x,y) is
//			outside the boudary. To know more, please read the reference
//			documents written by Ouyang Hui.
//
//	AUTHOR:	Ouyang Hui
//
//	DATE:	01/04/12
//
//	MODIFICATIONS SINCE 01/04/12:
//
///////////////////////////////////////////////////////////////////////////////
void CLinkPrediction::GetFourPoints(
				RATE2BLER1_TYPE* pRATE2BLER1,float x,float y,
				float& x1,float& y1,float& z1,
				float& x2,float& y2,float& z2,
				float& x3,float& y3,float& z3,
				float& x4,float& y4,float& z4)
{
	SNR2BLER1_TYPE* pSNR2BLER1;
	int i,iIndex1,iIndex2;
	float xx,yy;
	float xMax,yMax,xMin,yMin;

	xMax=(pRATE2BLER1->pstAddrOfSNR2BLER)
		[pRATE2BLER1->iSNR2BLER1Length-1].fMeanSNR;
	yMax=(pRATE2BLER1->pstAddrOfSNR2BLER)
		[pRATE2BLER1->iSNR2BLER1Length-1].fStdSNR;
	xMin=(pRATE2BLER1->pstAddrOfSNR2BLER)[0].fMeanSNR;
	yMin=(pRATE2BLER1->pstAddrOfSNR2BLER)[0].fStdSNR;

	for (i=0;i<pRATE2BLER1->iSNR2BLER1Length;i++)
	{
		pSNR2BLER1=&((pRATE2BLER1->pstAddrOfSNR2BLER)[i]);
		xx=pSNR2BLER1->fMeanSNR;
		yy=pSNR2BLER1->fStdSNR;
		iIndex2=i;

		if ((x<=xx)&&(y<=yy))
			break;	//satisfy the condiction
					//(x,y) is in the region #9
				
		if ((x<=xx)&&(y>=yMax)&&(fabs(yy-yMax)<m_fTollerance))
			break;	//(x,y) is in the region #6 or #7

		if ((x>=xMax)&&(fabs(xx-xMax)<m_fTollerance)&&(y<=yy))
			break;	//(x,y) is in the region #3 or #4

	//if all (xx,yy) cannot satisfy any of the above condictions,
	//then (x,y) is in the region #5.
	}
	x2=x4=xx;
	y3=y4=yy;
	z4=pSNR2BLER1->fBLER;
	

	for (i=pRATE2BLER1->iSNR2BLER1Length-1;i>=0;i--)
	{
		pSNR2BLER1=&((pRATE2BLER1->pstAddrOfSNR2BLER)[i]);
		xx=pSNR2BLER1->fMeanSNR;
		yy=pSNR2BLER1->fStdSNR;
		iIndex1=i;

		if ((x>=xx)&&(y>=yy))
			break;	//satisfy the condiction
					//(x,y) is in the region #9
		
		if ((x>=xx)&&(y<=yMin)&&(fabs(yy-yMin)<m_fTollerance))
			break;	//(x,y) is in the region #2 or #3

		if ((x<=xMin)&&(fabs(xx-xMin)<m_fTollerance)&&(y>=yy))
			break;	//(x,y) is in the region #7 or #8
		
	//if all (xx,yy) cannot satisfy any of the above condictions,
	//then (x,y) is in the region #1
	}
	x1=x3=xx;
	y1=y2=yy;
	z1=pSNR2BLER1->fBLER;

	if (fabs(x1-x2)<m_fTollerance)
	{
		z2=z1;
		z3=z4;
	}
	else
	{
		if (fabs(y1-y3)<m_fTollerance)
		{
			z2=z4;
			z3=z1;
		}
		else
		{
			z3=(pRATE2BLER1->pstAddrOfSNR2BLER)[iIndex2-1].fBLER;
			z2=(pRATE2BLER1->pstAddrOfSNR2BLER)[iIndex1+1].fBLER;
		}
	}
}

////////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

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