?? clinkprediction.cpp
字號:
//
// TITLE: Linear Interpolation Function
//
// PURPOSE:Given four 3-dimension points (x1,y1,z1), (x2,y2,z2), (x3,y3,z3),
// (x4,y4,z4), and the x-coordinate and the y-coordinate of the
// fifth point (x,y,z), this function can find the z-coordinate of
// the fifth point using linear interpolation method. Be sure that
// x1 = x3, x2 = x4, y1 = y2, and y3 = y4. Be sure also that
// x1 <= x <= x2 and y1 <= y <= y3.
//
// CALLED BY FUNCTIONS:
// CLinkPrediction::GetBLER()
//
// THE OLD ALGORITHMS:(only two points inputted)
// The 2-D linear interpolation is easy to resolve. The formula
// is:
// y = (y1 + y2) / 2 (x1 = x2)
// y = ((x2-x)*y1+(x-x1)*y2) / (x2-x1) (x1 <> x2)
// where
// (x1,y1) is the first 2-D point,
// (x2,y2) is the second 2-D point,
// (x,y) is the third 2-D point to be resolved,
// and we know x1, x2, y1, y2, x.
// Then y is given above
//
// But here is the 3-D case. Then should we resolve z according
// to x1, x2, x, or to y1, y2, y ? Neither of the two methods
// seems reasonable.
//
// We can simplified the resolution by this method:
// First, we find t1 according to x1, x2, x, and find t2 according
// to y1, y2, y, both using 2-D interpolation as above. Then we
// let z be equal to the mean of t1 and t2.
//
// So this is not a real 3-D linear interpolation algorithm. As it
// is very simple, we use it though it may be not very precise.
//
// The formula is given by:
// t1 = ((x2-x)*z1+(x-x1)*z2)/(x2-x1) (x1 <> x2)
// t2 = ((y2-y)*z1+(y-y1)*z2)/(y2-y1) (y1 <> y2)
// z = z1 (x1==x2, y1==y2)
// z = t1 (x1<>x2, y1==y2)
// z = t2 (x1==x2, y1<>y2)
// z = (t1 + t2)/2 (x1<>x2, y1<>y2)
//
// THE NEW ALGORITHMS:
// As is discussed above, interpolation with only 2 points is not
// precise enough. So I modify it to use four points. And these
// 4 points should satisfy the situations mentioned in the section
// of PURPOSE. Then the algorithms are very simple:
// t1 = z1 (x1 == x2)
// t1 = ((x2-x)*z1+(x-x1)*z2)/(x2-x1) (x1 <> x2)
// t2 = z3 (x3 == x4)
// t2 = ((x4-x)*z3+(x-x3)*z4)/(x4-x3) (x3 <> x4)
// z = t1 (y1 == y3)
// z = ((y3-y)*t1+(y-y1)*t2)/(y3-y1) (y1 <> y3)
//
// AUTHOR: Ouyang Hui
//
// DATE: 01/04/05
//
// MODIFICTIONS SINCE 01/04/05
// 01/04/06 Ouyang Hui Correct a bug
// 01/04/11 Ouyang Hui
// Modify the algorithms using 4 points
//
////////////////////////////////////////////////////////////////////////////
float CLinkPrediction::Interpolation(float x1,float x2,float x3,
float x4,float x,
float y1, float y2,float y3,
float y4,float y,
float z1, float z2,float z3,
float z4)
{
if (z1<1e-4)
z1=-4;
else
z1=(float)log10(z1);
if (z2<1e-4)
z2=-4;
else
z2=(float)log10(z2);
if (z3<1e-4)
z3=-4;
else
z3=(float)log10(z3);
if (z4<1e-4)
z4=-4;
else
z4=(float)log10(z4);
float t1,t2,z;
if (fabs(x2-x1)<m_fTollerance)
t1=z1;
else
t1=((x2-x)*z1+(x-x1)*z2)/(x2-x1);
if (fabs(x4-x3)<m_fTollerance)
t2=z3;
else
t2=((x4-x)*z3+(x-x3)*z4)/(x4-x3);
if (fabs(y3-y1)<m_fTollerance)
z=t1;
else
z=((y3-y)*t1+(y-y1)*t2)/(y3-y1);
z=(float)pow(10,z);
return z;
}
void CLinkPrediction::CheckTheInputs()
{
RATE2CI_TYPE* pRATE2CI;
RATE2BLER1_TYPE* pRATE2BLER1;
int i,iLength;
for (i=0;i<m_iPacketSizeNum;i++)
{
pRATE2CI=m_pstRatePredictionTable[i].pstAddrOfRate2CI;
iLength=m_pstRatePredictionTable[i].iRATE2CILength;
CheckRATE2CIList(pRATE2CI,iLength);
pRATE2BLER1=m_pstBLERPredictionTable[i].pstAddrOfRate2BLER;
iLength=m_pstBLERPredictionTable[i].iRATE2BLER1Length;
CheckRATE2BLER1List(pRATE2BLER1,iLength);
}
}
void CLinkPrediction::CheckRATE2CIList(RATE2CI_TYPE* pRATE2CI,int iLength)
{
int i;
float fLastCI=-10000;
float fCI;
for (i=0;i<iLength;i++)
{
fCI=pRATE2CI[i].fTargetC2I;
if (fCI<fLastCI)
{
cout<<"Error found in the Rate-to-CI lists!"<<endl
<<"Please check the data file of Link Prediction: "
<<m_sRate_BLERPredictionFileName<<"."<<endl
<<"Fail in initialization Channel Type "<<endl;
exit(1);
}
fLastCI=fCI;
}
}
void CLinkPrediction::CheckRATE2BLER1List(RATE2BLER1_TYPE* pRATE2BLER1,
int iLength)
{
int i;
float fLastRate=-1000;
float fRate;
int iNextLength;
SNR2BLER1_TYPE* pSNR2BLER1;
for (i=0;i<iLength;i++)
{
fRate=pRATE2BLER1[i].fEffectiveCodeRate;
iNextLength=pRATE2BLER1[i].iSNR2BLER1Length;
pSNR2BLER1=pRATE2BLER1[i].pstAddrOfSNR2BLER;
if (fRate<fLastRate)
{
cout<<"Error found in the Rate-to-BLER lists!"<<endl
<<"Please check the data file of Link Prediction: "
<<m_sRate_BLERPredictionFileName<<"."<<endl
<<"Fail in initialization Channel Type "<<endl;
exit(1);
}
CheckSNR2BLER1List(pSNR2BLER1,iNextLength);
fLastRate=fRate;
}
}
void CLinkPrediction::CheckSNR2BLER1List(SNR2BLER1_TYPE* pSNR2BLER1,
int iLength)
{
int iRowNum,iColNum=0;
float x,y;
float fLastx,fLasty;
int i,j;
//check the size of the list
fLasty=-10000;
for (i=0;i<iLength;i++)
{
y=pSNR2BLER1[i].fStdSNR;
if (y<fLasty)
break;
iColNum++;
fLasty=y;
}
iRowNum=iLength/iColNum;
if (iLength!=iRowNum*iColNum)
{
cout<<"Error found in the SNR-to-BLER lists!"<<endl
<<"Incorrect list size!"<<endl
<<"Please check the data file of Link Prediction: "
<<m_sRate_BLERPredictionFileName<<"."<<endl
<<"Fail in initialization Channel Type "<<endl;
DisplayFormatOfTheList();
exit(1);
}
//check the content of the list
//check the first row
fLastx=pSNR2BLER1[0].fMeanSNR;
fLasty=-1000;
for (i=0;i<iColNum;i++)
{
x=pSNR2BLER1[i].fMeanSNR;
y=pSNR2BLER1[i].fStdSNR;
if ((fabs(x-fLastx)>m_fTollerance)||
(y<fLasty))
{
cout<<"Error found in the SNR-to-BLER lists!"<<endl
<<"Incorrect order!"<<endl
<<"Please check the data file of Link Prediction: "
<<m_sRate_BLERPredictionFileName<<"."<<endl
<<"Fail in initialization Channel Type "<<endl;
DisplayFormatOfTheList();
exit(1);
}
fLasty=y;
}
//check the rest row
for (i=0;i<iColNum;i++)
{
fLastx=pSNR2BLER1[i].fMeanSNR;
fLasty=pSNR2BLER1[i].fStdSNR;
for (j=0;j<iRowNum;j++)
{
x=pSNR2BLER1[j*iColNum+i].fMeanSNR;
y=pSNR2BLER1[j*iColNum+i].fStdSNR;
if ((fabs(y-fLasty)>m_fTollerance)||
(x<fLastx))
{
cout<<"Error found in the SNR-to-BLER lists!"<<endl
<<"(x,y) should be inputted in grid!"<<endl
<<"Please check the data file of Link Prediction: "
<<m_sRate_BLERPredictionFileName<<"."<<endl
<<"Fail in initialization Channel Type "<<endl;
DisplayFormatOfTheList();
exit(1);
}
fLastx=x;
}
}
for (i=0;i<iRowNum;i++)
{
fLastx=pSNR2BLER1[i*iColNum].fMeanSNR;
for (j=0;j<iColNum;j++)
{
x=pSNR2BLER1[i*iColNum+j].fMeanSNR;
if (fabs(x-fLastx)>m_fTollerance)
{
cout<<"Error found in the SNR-to-BLER lists!"<<endl
<<"(x,y) should be inputted in grid!"<<endl
<<"Please check the data file of Link Prediction: "
<<m_sRate_BLERPredictionFileName<<"."<<endl
<<"Fail in initialization Channel Type "
<<"!"<<endl
<<"x0="<<fLastx<<" "
<<"x="<<x<<endl;
DisplayFormatOfTheList();
exit(1);
}
}
}
}
void CLinkPrediction::DisplayFormatOfTheList()
{
cout<<"The format of the list should be (example):"<<endl
<<"3072 2 ====================="<<endl
<<"0.2 9 -------------------"<<endl
<<"1 1 1"<<endl
<<"1 2 2"<<endl
<<"1 3 3"<<endl
<<"2 1 4"<<endl
<<"2 2 5"<<endl
<<"2 3 6"<<endl
<<"3 1 7"<<endl
<<"3 2 8"<<endl
<<"3 3 9"<<endl
<<"0.4 9 ----------------------"<<endl
<<"....."<<endl;
cout<<"Note that (1,1) to (9,9) are order in grids"<<endl;
}
///////////////////////////////////////////////////////////////////////////
void CLinkPrediction::SetRate_BLERPredictionFileName(char* sFilename)
{
strcpy(m_sRate_BLERPredictionFileName,
sFilename);
}
EPS2BLER1_TYPE* CLinkPrediction::GetBLERPredictionTable()
{
return m_pstBLERPredictionTable;
}
RATE2CI_TYPE* CLinkPrediction::GetSPDataRate(int iPacketSize, int iChannelType, float fC2IdB)
{
EPS2CI_TYPE* tempEPS2CI;
RATE2CI_TYPE* tempRATE2CI;
int iEPSize,iPacketLength;
float fCIdB,fLastCIdB=(float)0.0;
double fC2INeededdB,fPowerMargindB,fSPDCCHSlotC2I,fPDCHSlotC2I,fPDCHSlotC2IdB;
int i,k,l;
//find in the first level of the table
for (i=0;i<m_iPacketSizeNum;i++)
{
tempEPS2CI=&m_pstRatePredictionTable[i];
iEPSize=tempEPS2CI->iEncoderPacketSize;
if (fabs(iPacketSize-iEPSize)<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;
exit(1);
}
//find in the second level of the table
for (i=tempEPS2CI->iRATE2CILength-1;i>=0;i--)
{
tempRATE2CI=&(tempEPS2CI->pstAddrOfRate2CI)[i];
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) break;
fLastCIdB=fCIdB;
tempRATE2CI=NULL;
}
if(!tempRATE2CI)
{
tempEPS2CI=&m_pstRatePredictionTable[3];
tempRATE2CI=&(tempEPS2CI->pstAddrOfRate2CI)[0];
fSPDCCHSlotC2I=pow(10,(SPDCCHEbNt[3][iChannelType-1]-ProcessGain[3]+SPDCCHPowerMargin[3][iChannelType-1])/10);
}
m_fDeterminedSPDCHC2I=float(fSPDCCHSlotC2I);
return tempRATE2CI;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -