📄 rxswitchmgr.c
字号:
else
uiStop = uiBuffLen-1;
create_rect(pOutBuff, uiBuffSize, uiStart, uiStop, CHANNEL1);
}
else
{ // check cases b,c,d
// at least one of the changes have to be performed in the present buffer
if (iPos1Sw1 < iBuffLen-1)
{ // check cases b,c
if (iPos2Sw1 < iBuffLen-1)
{ // case c
// two switch instances in the present buffer
// set the switch state up to the first change
uiStart = 0;
if (pSwitchState->uiPosSwitch1 == eSWITCH1)
uiStop = uiStart;
else
uiStop = (unsigned int)(iPos1Sw1-1);
create_rect(pOutBuff, uiBuffSize, uiStart, uiStop, CHANNEL1);
// set the switch state after the first change up to the second
uiStart = (unsigned int)iPos1Sw1;
if (pSwitchState->uiPos1SetSwitch1 == eSWITCH1)
uiStop = uiStart;
else
uiStop = (unsigned int)(iPos2Sw1-1);
create_rect(pOutBuff, uiBuffSize, uiStart, uiStop, CHANNEL1);
// set the switch state after the second change
uiStart = (unsigned int)iPos2Sw1;
if (pSwitchState->uiPos2SetSwitch1 == eSWITCH1)
uiStop = uiStart;
else
uiStop = uiBuffLen-1;
create_rect(pOutBuff, uiBuffSize, uiStart, uiStop, CHANNEL1);
// update the state variable
pSwitchState->uiPosSwitch1 = pSwitchState->uiPos2SetSwitch1;
}
else
{ // case b
// only first change is in the present buffer
// set the switch state up to the first change
uiStart = 0;
if (pSwitchState->uiPosSwitch1 == eSWITCH1)
uiStop = uiStart;
else
uiStop = (unsigned int)(iPos1Sw1-1);
create_rect(pOutBuff, uiBuffSize, uiStart, uiStop, CHANNEL1);
// set the switch state after the first change
uiStart = (unsigned int)iPos1Sw1;
if (pSwitchState->uiPos1SetSwitch1 == eSWITCH1)
uiStop = uiStart;
else
uiStop = uiBuffLen-1;
create_rect(pOutBuff, uiBuffSize, uiStart, uiStop, CHANNEL1);
// update the state variable
pSwitchState->uiPosSwitch1 = pSwitchState->uiPos1SetSwitch1;
}
}
else
{ // case d
// only second change is in the present buffer (the first is already set for the next frame)
// set the switch state up to the second change
uiStart = 0;
if (pSwitchState->uiPosSwitch1 == eSWITCH1)
uiStop = uiStart;
else
uiStop = (unsigned int)(iPos2Sw1-1);
create_rect(pOutBuff, uiBuffSize, uiStart, uiStop, CHANNEL1);
// set the switch state after the second change
uiStart = (unsigned int)iPos2Sw1;
if (pSwitchState->uiPos1SetSwitch1 == eSWITCH1)
uiStop = uiStart;
else
uiStop = uiBuffLen-1;
create_rect(pOutBuff, uiBuffSize, uiStart, uiStop, CHANNEL1);
// update the state variable
pSwitchState->uiPosSwitch1 = pSwitchState->uiPos2SetSwitch1;
}
}
// tests for switch 2
if ((iPos1Sw2 > iBuffLen-1) && (iPos2Sw2 > iBuffLen-1))
{ // case a
// no changes, keep the old positions over the whole buffer
uiStart = 0;
if (pSwitchState->uiPosSwitch2 == eSWITCH3)
uiStop = uiStart;
else
uiStop = uiBuffLen-1;
create_rect(pOutBuff, uiBuffSize, uiStart, uiStop, CHANNEL2);
}
else
{ // check cases b,c,d
// at least one of the changes have to be performed in the present buffer
if (iPos1Sw2 < iBuffLen-1)
{ // check cases b,c
if (iPos2Sw2 < iBuffLen-1)
{ // case c
// two switch instances in the present buffer
// set the switch state up to the first change
uiStart = 0;
if (pSwitchState->uiPosSwitch2 == eSWITCH3)
uiStop = uiStart;
else
uiStop = (unsigned int)(iPos1Sw2-1);
create_rect(pOutBuff, uiBuffSize, uiStart, uiStop, CHANNEL2);
// set the switch state after the first change up to the second
uiStart = (unsigned int)iPos1Sw2;
if (pSwitchState->uiPos1SetSwitch2 == eSWITCH3)
uiStop = uiStart;
else
uiStop = (unsigned int)(iPos2Sw2-1);
create_rect(pOutBuff, uiBuffSize, uiStart, uiStop, CHANNEL2);
// set the switch state after the second change
uiStart = (unsigned int)iPos2Sw2;
if (pSwitchState->uiPos2SetSwitch2 == eSWITCH3)
uiStop = uiStart;
else
uiStop = uiBuffLen-1;
create_rect(pOutBuff, uiBuffSize, uiStart, uiStop, CHANNEL2);
// update the state variable
pSwitchState->uiPosSwitch2 = pSwitchState->uiPos2SetSwitch2;
}
else
{ // case b
// only first change is in the present buffer
// set the switch state up to the first change
uiStart = 0;
if (pSwitchState->uiPosSwitch2 == eSWITCH3)
uiStop = uiStart;
else
uiStop = (unsigned int)(iPos1Sw2-1);
create_rect(pOutBuff, uiBuffSize, uiStart, uiStop, CHANNEL2);
// set the switch state after the first change
uiStart = (unsigned int)iPos1Sw2;
if (pSwitchState->uiPos1SetSwitch2 == eSWITCH3)
uiStop = uiStart;
else
uiStop = uiBuffLen-1;
create_rect(pOutBuff, uiBuffSize, uiStart, uiStop, CHANNEL2);
// update the state variable
pSwitchState->uiPosSwitch2 = pSwitchState->uiPos1SetSwitch2;
}
}
else
{ // case d
// only second change is in the present buffer (the first is already set for the next frame)
// set the switch state up to the second change
uiStart = 0;
if (pSwitchState->uiPosSwitch2 == eSWITCH3)
uiStop = uiStart;
else
uiStop = (unsigned int)(iPos2Sw2-1);
create_rect(pOutBuff, uiBuffSize, uiStart, uiStop, CHANNEL2);
// set the switch state after the second change
uiStart = (unsigned int)iPos2Sw2;
if (pSwitchState->uiPos1SetSwitch2 == eSWITCH3)
uiStop = uiStart;
else
uiStop = uiBuffLen-1;
create_rect(pOutBuff, uiBuffSize, uiStart, uiStop, CHANNEL2);
// update the state variable
pSwitchState->uiPosSwitch2 = pSwitchState->uiPos2SetSwitch2;
}
}
}
/*=== End of local functions definition ====================================*/
/*--- Global functions definition ------------------------------------------*/
/****************************************************************************
Function : antennaselection
****************************************************************************
Description : antenna subset selection based on MBER
Inputs : channel estimation
Outputs : antenna state
By : 2005-05-06 Jinfeng Du
2005-05-11 be modified
****************************************************************************/
void antennaselection(typRX_SWITCHSTATE *pSwitchState)
{
/* channel estimation needed, a seletion set need to be stored in one group */
float max_d, min_d, new_d;
float A,B,C,D;
Int16 Ai, Bi, len;
Int16 Ant1,Ant2;//for antenna selection
Int16 i = 0;
typRX_eAntenna selection_type;
const Int16 Selection[4][2] = {0, 2, 0, 3, 1, 2, 1, 3};
float signal_noise = Sig_Nois_Ratio;
max_d = 0;
min_d = 1.0e10;
new_d = 1.0e10;
selection_type = pSwitchState->uiAnteSelType;
/***** Antenna Selection using different methods MBER, MMI, MMNP or LAZY, ***********
* possible methods for antenna subset selection
typedef enum
{
eAnteNO = 0,
eAnteMMNP,
eAnteMBER,
eAnteMMI,
eAnteLAZY
} typRX_eAntenna;
***********************************************************************************/
if (selection_type == eAnteMMNP)
{/**************** start of Modified Minimum Noise Power criteria**********************/
for(i=0; i<4; i++)
{
Ai = Selection[i][0];
Bi = Selection[i][1];
// r = arg min_i max_j {Rjj(i)},
// where Rjj(i) is the (j,j) element in matrx R(i)= inv(Hi)*inv(Hi)'
// compute the multiplication of R = inv(Hr)*inv(Hr)', R11 = C/(A*A+B*B), R22=D/(A*A+B*B);
A = pH_pre_r[Ai][0]*pH_pre_r[Bi][1] + pH_pre_i[Ai][1]*pH_pre_i[Bi][0];
A -= pH_pre_i[Ai][0]*pH_pre_i[Bi][1] + pH_pre_r[Ai][1]*pH_pre_r[Bi][0];
B = pH_pre_r[Ai][0]*pH_pre_i[Bi][1] + pH_pre_i[Ai][0]*pH_pre_r[Bi][1];
B -= pH_pre_r[Ai][1]*pH_pre_i[Bi][0] + pH_pre_i[Ai][1]*pH_pre_r[Bi][0];
C = pH_pre_r[Ai][0]*pH_pre_r[Ai][0] + pH_pre_i[Ai][0]*pH_pre_i[Ai][0];
C += pH_pre_r[Ai][1]*pH_pre_r[Ai][1] + pH_pre_i[Ai][1]*pH_pre_i[Ai][1];
D = pH_pre_r[Bi][0]*pH_pre_r[Bi][0] + pH_pre_i[Bi][0]*pH_pre_i[Bi][0];
D += pH_pre_r[Bi][1]*pH_pre_r[Bi][1] + pH_pre_i[Bi][1]*pH_pre_i[Bi][1];
// compute the R11 = C/(A*A+B*B), R22=D/(A*A+B*B) respectively
A = A*A + B*B;
B = _rcpsp(A); //now R11 = C*B, R22 = D*B;
max_d = B * (C<D?D:C);// max_d = max(R11,R22)
if ( max_d <= min_d && (B*(C+D)) < new_d) //find one with minimum max(Rjj) and minimum total power
{
min_d = max_d;
Ant1 = Ai; // keep the index of the maximum value
Ant2 = Bi;
new_d = B*(C+D);
}//end if
}//end for Ai,Bi
/****************** end of Modified Minimum Noise Power criteria**********************/
}
else if(selection_type == eAnteMBER)
{/**************** start of Minimum BER criteria ***********************************/
for(i=0; i<4; i++)
{
Ai = Selection[i][0];
Bi = Selection[i][1];
// compute the norm of Hr*Delta_S=[A+jB;C+jD]
A = pH_pre_r[Ai][0]*(float)Delta_S_Setr[0][0] + pH_pre_r[Ai][1]*(float)Delta_S_Setr[1][0];
A -=(pH_pre_i[Ai][0]*(float)Delta_S_Seti[0][0] + pH_pre_i[Ai][1]*(float)Delta_S_Seti[1][0]);
B = pH_pre_r[Ai][0]*(float)Delta_S_Seti[0][0] + pH_pre_r[Ai][1]*(float)Delta_S_Seti[1][0];
B += pH_pre_i[Ai][0]*(float)Delta_S_Setr[0][0] + pH_pre_i[Ai][1]*(float)Delta_S_Setr[1][0];
C = pH_pre_r[Bi][0]*(float)Delta_S_Setr[0][0] + pH_pre_r[Bi][1]*(float)Delta_S_Setr[1][0];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -