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

📄 rxfunction.c

📁 MIMO 2x2接收端选择全系统仿真代码
💻 C
字号:
/*****************************************************************************
  Module     : External Functions
******************************************************************************

  Function   : External Functions used by the receiver.

  Procedures : 

  Author     : $Author: Jinfeng $

  Revision   : $Revision: 4 $

  Modified   : $Modtime: 05-05-17 13:22 $

  File       : $Workfile: rxfunctions.c $

******************************************************************************
 KTH, Royal Institute of Technology, S3, Stockholm
*****************************************************************************/

/*--- Include files --------------------------------------------------------*/

/* import */
#include <csl_stdinc.h>
#include "../common/commondef.h"

/* export */
#include "rxfunctions.h"

/*=== End of include files =================================================*/


/*--- Global variables definition ------------------------------------------*/

typRX_ENERGYDETSTATE EnergyDetState;
float Sig_Nois_Ratio; //the receive sigal to noise ratio.

/*=== End of global variables definition ===================================*/


/*--- Global constants definition ------------------------------------------*/
/*=== End of global constants definition ===================================*/


/*--- Local defines --------------------------------------------------------*/
/*=== End of local defines =================================================*/


/*--- Local types declaration ----------------------------------------------*/
/*=== End of local types declaration =======================================*/


/*--- Local variables definition -------------------------------------------*/
/*=== End of local variables definition ====================================*/


/*--- Local constants definition -------------------------------------------*/
/*=== End of local constants definition ====================================*/


/*--- Local functions definition -------------------------------------------*/
/*=== End of local functions definition ====================================*/


/*--- Global functions definition ------------------------------------------*/

/****************************************************************************
  Function    : computeEnergy
 ****************************************************************************

  Description : compute the energy of signal to detect frame start point

  Inputs      : received signal and threshold

  Outputs     : -start point and noise power per sample

  By          : 2005-05-05 Jinfeng Du
				2005-05-11 modified

 ****************************************************************************/
void computeEnergy(Int16 *pInBuff, const unsigned int uiInBuffSize, typRX_ENERGYDETSTATE *pEnergyDetState)
{
	int n, i;
	float channelA, channelB;
	float alfa = 0.95; //forgetting factor
	float factor = _rcpsp((float)pEnergyDetState->unEnergyBlock);
	

	n = 0;
	pEnergyDetState->iStartIndex = -1; //if fail to detect the signal

	while(n < uiInBuffSize)
	{
		i = 0;//count the length of the block
		channelA = 0.0;
		channelB = 0.0;
		while(i < pEnergyDetState->unEnergyBlock)
		{	
			channelA += pInBuff[n]*pInBuff[n];
			n++;
			channelB += pInBuff[n]*pInBuff[n];
			n++;
		}//end while i

		if (pEnergyDetState->fEnergyThrs < 0) //initialize the threshold
		{
			pEnergyDetState->fEnergyThrs = 10*channelA;
		}

		if (channelA > pEnergyDetState->fEnergyThrs || channelB > pEnergyDetState->fEnergyThrs)
		{
			pEnergyDetState->iStartIndex = n;
			n = uiInBuffSize; //	break;
			//compute the SNR in ChannelA for use later
			Sig_Nois_Ratio = (factor*channelA)*_rcpsp(pEnergyDetState->fNoisePower1);
		}
		else
		{
			pEnergyDetState->fNoisePower1 = factor*channelA; 
			pEnergyDetState->fNoisePower2 = factor*channelB;
			//update the threshold
			pEnergyDetState->fEnergyThrs = alfa*pEnergyDetState->fEnergyThrs 
				+ (1-alfa)*5*(channelA+channelB);  //Thrs = 10*Noise_Power
		}//end if			


	}//end if n

}// end computeEnergy

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

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

$Log: /MIMO/Receiver/rxfunctions.c $ 
 * 
 * 4     05-05-17 13:23 Jinfeng
 * initialize the threshold at the first call and update it timely
 * according to the noise power
 * 
 * 3     05-05-12 12:17 Jinfeng
 * No modification.
 * 
 * 2     05-05-12 12:13 Jinfeng
 * Introduce a global variable: float Sig_Nois_Ratio; //the receive sigal
 * to noise ratio.
 * 
 * 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 + -