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

📄 rxswitchmgr.c

📁 MIMO 2x2接收端选择全系统仿真代码
💻 C
📖 第 1 页 / 共 3 页
字号:
			C -=(pH_pre_i[Bi][0]*(float)Delta_S_Seti[0][0] + pH_pre_i[Bi][1]*(float)Delta_S_Seti[1][0]);
			D  = pH_pre_r[Bi][0]*(float)Delta_S_Seti[0][0] + pH_pre_r[Bi][1]*(float)Delta_S_Seti[1][0];
			D += pH_pre_i[Bi][0]*(float)Delta_S_Setr[0][0] + pH_pre_i[Bi][1]*(float)Delta_S_Setr[1][0];
		
			min_d = A*A + B*B + C*C + D*D;
		
			for(len=1;len<DELTA_S_SET_LEN;len++)
			{
				// compute the norm of Hr*Delta_S=[A+jB;C+jD]
				A  = pH_pre_r[Ai][0]*(float)Delta_S_Setr[0][len] + pH_pre_r[Ai][1]*(float)Delta_S_Setr[1][len];
				A -=(pH_pre_i[Ai][0]*(float)Delta_S_Seti[0][len] + pH_pre_i[Ai][1]*(float)Delta_S_Seti[1][len]);
				B  = pH_pre_r[Ai][0]*(float)Delta_S_Seti[0][len] + pH_pre_r[Ai][1]*(float)Delta_S_Seti[1][len];
				B += pH_pre_i[Ai][0]*(float)Delta_S_Setr[0][len] + pH_pre_i[Ai][1]*(float)Delta_S_Setr[1][len];
				C  = pH_pre_r[Bi][0]*(float)Delta_S_Setr[0][len] + pH_pre_r[Bi][1]*(float)Delta_S_Setr[1][len];
				C -=(pH_pre_i[Bi][0]*(float)Delta_S_Seti[0][len] + pH_pre_i[Bi][1]*(float)Delta_S_Seti[1][len]);
				D  = pH_pre_r[Bi][0]*(float)Delta_S_Seti[0][len] + pH_pre_r[Bi][1]*(float)Delta_S_Seti[1][len];
				D += pH_pre_i[Bi][0]*(float)Delta_S_Setr[0][len] + pH_pre_i[Bi][1]*(float)Delta_S_Setr[1][len];
			
				new_d = A*A + B*B + C*C + D*D;
			
				min_d =(new_d < min_d ? new_d:min_d); //update with the minimum norm
			}//end for set_len
			
			if (min_d > max_d) //find the maximum minimum, and set the selection decision.
			{
				max_d = min_d;
				Ant1 = Ai; // keep the index of the maximum value
				Ant2 = Bi;
			}//end if	
		
		}//end for Ai,Bi

		/****************** end of Minimum BER criteria ***********************************/
	} 

	else if(selection_type == eAnteMMI)
	{/**************** start of Maximum Mutual Information criteria*********************/
		
		for(i=0; i<4; i++)
		{	
			Ai = Selection[i][0];
			Bi = Selection[i][1];

			// compute the multiplication of Hr*Hr'=[A B+Ci; B-Ci D],A B C D are real number.
			A  = pH_pre_r[Ai][0]*pH_pre_r[Ai][0] + pH_pre_i[Ai][0]*pH_pre_i[Ai][0];
			A += 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];
			B  = pH_pre_r[Ai][0]*pH_pre_r[Bi][0] + pH_pre_i[Ai][0]*pH_pre_i[Bi][0];
			B += pH_pre_r[Ai][1]*pH_pre_r[Bi][1] + pH_pre_i[Ai][1]*pH_pre_i[Bi][1];
			C  = pH_pre_i[Ai][0]*pH_pre_r[Bi][0] + pH_pre_i[Ai][1]*pH_pre_r[Bi][1];
			C -= pH_pre_r[Ai][0]*pH_pre_i[Bi][0] + pH_pre_r[Ai][1]*pH_pre_i[Bi][1];
			// compute the det of (I + SNR * Hr*Hr') = | 1+A*snr    (B+Ci)*snr   | 
			//                                         |(B-Ci)*snr     1+D*snr   |
			A = 1.0 + A*signal_noise;
			D = 1.0 + D*signal_noise;
			B = B*signal_noise;
			C = C*signal_noise;

			new_d = A*D - (B*B + C*C);

			if (new_d > max_d) //find the maximum Mutual Info, and set the selection decision.
			{
				max_d = new_d;
				Ant1 = Ai; // keep the index of the maximum value
				Ant2 = Bi;
			}//end if				


		}//end for Ai,Bi
		
		/****************** end of Maximum Mutual Information criteria**********************/
	}

	else
	{/***************************** no antenna selection************************************/
				 
		Ant1 = (pSwitchState->uiPosSwitch1 == eSWITCH1) ? 0:1; //find previous status
		Ant2 = (pSwitchState->uiPosSwitch2 == eSWITCH3) ? 2:3;

	}
	   
	/***end of any selection***/


	//switch to the unselected antenna subset first at the beginning of the frame
	pSwitchState->uiPos1SetSwitch1 = (Ant1>0?eSWITCH1:eSWITCH2);  
	pSwitchState->uiPos1SetSwitch2 = (Ant2>2?eSWITCH3:eSWITCH4);

	// switch to the selected antenna subset after the first training sequence

	pSwitchState->uiPos2SetSwitch1 = (Ant1<1?eSWITCH1:eSWITCH2);  
	pSwitchState->uiPos2SetSwitch2 = (Ant2<3?eSWITCH3:eSWITCH4);

}// end for Antenna selection


/****************************************************************************
  Function   : switch_init
 ****************************************************************************

  Description : Initializes the state variables before the first time
  				switch_control is called, but after the start index is
  				known and set.

  Inputs      : pointer to the structure for the control function
  				pointer to the structure containing the switch states

  Outputs     : -

  By          : 2005-05-12 Adrian Schumacher

 ****************************************************************************/
void switch_cntrl_init(typRX_SWITCHSTATE *pSwitchState, const int iSyncRep)
{
	pSwitchState->iPos1Sw1 = pSwitchState->iNextStartIndex+((GUARDSYMBOLS*OVERSAMPLING)/2);
	pSwitchState->iPos1Sw2 = pSwitchState->iNextStartIndex+((GUARDSYMBOLS*OVERSAMPLING)/2);
	pSwitchState->iPos2Sw1 = pSwitchState->iPos1Sw1 + ((TRAINLEN+GUARDSYMBOLS)*OVERSAMPLING);
	pSwitchState->iPos2Sw2 = pSwitchState->iPos1Sw2 + ((TRAINLEN+GUARDSYMBOLS)*OVERSAMPLING);
	if (iSyncRep == 1)
	{
		// next frame will also be a sync frame, therefore adapt the switching instant for the second guard interval
		pSwitchState->iPos2Sw1 += SYNCSYMBLENGTH*OVERSAMPLING;
		pSwitchState->iPos2Sw2 += SYNCSYMBLENGTH*OVERSAMPLING;
	}
}


/****************************************************************************
  Function   : switch_control
 ****************************************************************************

  Description : Takes care of the correct setting of the switches,
  				needs to be called once for every buffer to update the
  				indices

  Inputs      : pointer to the output buffer
  				length of one channel in the output buffer
  				pointer to the structure containing the 
  				pointer to the structure containing the switch states

  Outputs     : -

  By          : 2005-05-12 Adrian Schumacher

 ****************************************************************************/
void switch_control(Int16 *pOutBuff, const unsigned int uiBuffLen, const int iFrameLen,
	typRX_SWITCHSTATE *pSwitchState, const int iSyncRep, const int iSyncCtrl)
{
	int iBuffLen = (int)uiBuffLen;
	typRX_SWITCHSTATE TempSwitchState;

	pSwitchState->iNextStartIndex -= iBuffLen;
	pSwitchState->iPos1Sw1 -= iBuffLen;
	pSwitchState->iPos1Sw2 -= iBuffLen;
	pSwitchState->iPos2Sw1 -= iBuffLen;
	pSwitchState->iPos2Sw2 -= iBuffLen;
	if ((pSwitchState->iNextStartIndex - iBuffLen) < iBuffLen-1)
	{
		// start of a next frame occures in the next buffer, action has to be taken
	}

	// make a temporary copy of the switch states
	memcpy(&TempSwitchState,pSwitchState,sizeof(TempSwitchState));
	// adapt
	// switch for training sequence 1
	// check switch 1
	if ((pSwitchState->uiPos1SetSwitch1 == eSWITCH2) && (pSwitchState->uiPosSwitch1 == eSWITCH1))
		TempSwitchState.iPos1Sw1 -= DELAY_SWITCH_ON; // it will switch on
	if ((pSwitchState->uiPos1SetSwitch1 == eSWITCH1) && (pSwitchState->uiPosSwitch1 == eSWITCH2))
		TempSwitchState.iPos1Sw1 -= DELAY_SWITCH_OFF; // it will switch off
	// check switch 2
	if ((pSwitchState->uiPos1SetSwitch2 == eSWITCH4) && (pSwitchState->uiPosSwitch2 == eSWITCH3))
		TempSwitchState.iPos1Sw2 -= DELAY_SWITCH_ON; // it will switch on
	if ((pSwitchState->uiPos1SetSwitch2 == eSWITCH3) && (pSwitchState->uiPosSwitch2 == eSWITCH4))
		TempSwitchState.iPos1Sw2 -= DELAY_SWITCH_OFF; // it will switch off
	// switch for training sequence 2
	// check switch 1
	if ((pSwitchState->uiPos2SetSwitch1 == eSWITCH2) && (pSwitchState->uiPos1SetSwitch1 == eSWITCH1))
		TempSwitchState.iPos2Sw1 -= DELAY_SWITCH_ON; // it will switch on
	if ((pSwitchState->uiPos2SetSwitch1 == eSWITCH1) && (pSwitchState->uiPos1SetSwitch1 == eSWITCH2))
		TempSwitchState.iPos2Sw1 -= DELAY_SWITCH_OFF; // it will switch off
	// check switch 2
	if ((pSwitchState->uiPos2SetSwitch2 == eSWITCH4) && (pSwitchState->uiPos1SetSwitch2 == eSWITCH3))
		TempSwitchState.iPos2Sw2 -= DELAY_SWITCH_ON; // it will switch on
	if ((pSwitchState->uiPos2SetSwitch2 == eSWITCH3) && (pSwitchState->uiPos1SetSwitch2 == eSWITCH4))
		TempSwitchState.iPos2Sw2 -= DELAY_SWITCH_OFF; // it will switch off
	// check frame format for the next frame
	if ((iSyncRep != 0) && (iSyncCtrl+1 > iSyncRep))
	{
		// next frame will be a sync frame, therefore adapt the switching instant for the second guard interval
		TempSwitchState.iPos2Sw1 += SYNCSYMBLENGTH*OVERSAMPLING;
		TempSwitchState.iPos2Sw2 += SYNCSYMBLENGTH*OVERSAMPLING;
	}

	set_switches(pOutBuff, uiBuffLen, &TempSwitchState);
	if (TempSwitchState.iPos1Sw1 < iBuffLen-1)
		pSwitchState->iPos1Sw1 += iFrameLen;
	if (TempSwitchState.iPos1Sw2 < iBuffLen-1)
		pSwitchState->iPos1Sw2 += iFrameLen;
	if (TempSwitchState.iPos2Sw1 < iBuffLen-1)
		pSwitchState->iPos2Sw1 += iFrameLen;
	if (TempSwitchState.iPos2Sw2 < iBuffLen-1)
		pSwitchState->iPos2Sw2 += iFrameLen;
}


/*=== End of global functions definition ===================================*/

/*--- AUTOMATICALLY GENERATED VERSION HISTORY --------------------------------

$Log: /MIMO/Receiver/rxswitchmgr.c $ 
 * 
 * 15    05-05-29 22:35 Jinfeng
 * Correct the error in MMI,  replace norm with det.
 * 
 * 14    05-05-28 20:15 Adrian
 * added a routine to account for the changed position of the second
 * switching instant when we receive sync frames
 * 
 * 13    05-05-23 9:51 Jinfeng
 * remove the choice of LAZY
 * 
 * 12    05-05-20 18:04 Jinfeng
 * Add typRX_eAntenna to make antenna selection type vary. 
 * 
 * 11    05-05-20 13:41 Jinfeng
 * using MMNP now instead of MBER
 * 
 * 10    05-05-17 16:48 Jinfeng
 * Add Modified Minimum Noise Power mehtod to antenna selection
 * 
 * 9     05-05-13 16:54 Adrian
 * modified create_rect(), set_switches(), switch_cntrl_init() and
 * switch_control(). idea of the algorithm is fixed now but could still
 * contain errors, since it's not tested yet.
 * 
 * 8     05-05-12 17:05 Adrian
 * Added switch_control() and switch_init(), but is not finished, needs
 * changes in set_switches() and create_rect().
 * 
 * 7     05-05-12 13:31 Jinfeng
 * change pH_pre_Ar to pH_pre_r, and pH_pre_Ai to pH_pre_i as they will be
 * changed in the rxchannelest.c as Loghman did.
 * 
 * 6     05-05-12 12:20 Jinfeng
 * Change to :  extern float Sig_Nois_Ratio;  //dB is not convinent to
 * use. 
 * 
 * 5     05-05-12 12:03 Jinfeng
 * Add the variable SNR as->  extern float Sig_Nois_dB;
 * give correct value to the switch state.
 * 
 * 4     05-05-12 11:44 Adrian
 * Added function set_switches()
 * 
 * 3     05-05-11 23:39 Jinfeng
 * Add other selection methods, inculdeing Maximum Mutual Information and
 * LAZY methods. Just de-comment the method you prefer and comment others
 * will work. When not using Miminum BER method, we need SNR as input
 * parameter. This need to be discussed.
 * 
 * 2     05-05-11 18:40 Jinfeng
 * 
 * 1     05-05-11 17:00 Adrian
 * created and added to VSS

===== END OF AUTOMATICALLY GENERATED VERSION HISTORY =======================*/

/**** End of file ***********************************************************/

⌨️ 快捷键说明

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