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

📄 rxdetector2.c

📁 MIMO 2x2接收端选择全系统仿真代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************
  Module     : Detector
******************************************************************************

  Function   : 

  Procedures : 

  Author     : $Author: Adrian $

  Revision   : $Revision: 9 $

  Modified   : $Modtime: 05-05-27 20:40 $

  File       : $Workfile: rxdetector.c $

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

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

/* import */
#include <math.h>
/* export */
#include "rxdetector.h"

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


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

typRX_DETECTORSTATE DetectorStat;

/*=== 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 -------------------------------------------*/

/****************************************************************************
  Function    : MaptoBytes
 ****************************************************************************

  Description : Maps the detected symbols to bytes

  Inputs      : The real and imaginary part of two symbols

  Outputs     : The two symbols in bytes

  By          : 2005-05-13 Created by Anders Lindgren
  				2005-05-15 modified by Anders Lindgren

 ****************************************************************************/
//static char MaptoBytes(float Ich_1, float Qch_1, float Ich_2, float Qch_2)
static char MaptoBytes(float Ich, float Qch)
{
	//int k;
	//int i;
	char c = 0x00;
	 	 //I-channel 1
	 		if (Ich > 0)
	 		{
	 			//bhat_1[i] = 1;
	 			c = c|0x08;
	 			if (Ich <= 2)
	 			{
	 				//bhat_1[i+1] = 1;
	 				c = c|0x04;
	 			}
	 		}
			else
			{
				//bhat_1[i] = 0;
				//a = a|0x00					//Don't need to do this setting?
				if (Ich > -2)
				{
					//bhat_1[i+1] = 1;
					c = c|0x04;
				}
			}
	 	 //Q-channel 1
			if (Qch > 0)
			{
				//bhat_1[i+2] = 1;
				c = c|0x02;
				if (Qch <= 2)
				{
					//bhat_1[i+3] = 1;
					c = c|0x01;
				}
			}
			else
			{
				//bhat_1[i+2] = 0;
				if (Qch > -2)
				{
					//bhat_1[i+3] = 1;
					c = c|0x01;
				}
			}
	return c;
}

/****************************************************************************
  Function    : Detect
 ****************************************************************************

  Description : Collect the bytes from the symbols into the DataBuffer

  Inputs      : Detected symbols

  Outputs     : Detected symbols in bytes

  By          : 2005-05-13 Created by Anders Lindgren
  				2005-05-15 modified by Anders Lindgren

 ****************************************************************************/

static void Detect(typRX_DETECTORSTATE *pDetectorStat)
{
	int data_len;
	int p, idx;
	char a;
	char b;
	//char bhat_1[120];			//Antenna 1. Assume 30 symbols in a buffer, which gives 30*4=120 bits
	//float bhat_2[120];			//Antenna 2
	//float len;
	float *Ich_1;
	float *Qch_1;
	float *Ich_2;
	float *Qch_2;
	//int nibble_1;					//nibble assumes the values 0 and 1, where 0 equals 'low' and 1 equals 'high'
	//int nibble_2;
	
	data_len = pDetectorStat->uiNoOfSymb;
	//len = 4*data_len;

	Ich_1 = pDetectorStat->pfCplxSymbBuff_1->pIBuffer;
	Qch_1 = pDetectorStat->pfCplxSymbBuff_1->pQBuffer;
	Ich_2 = pDetectorStat->pfCplxSymbBuff_2->pIBuffer;
	Qch_2 = pDetectorStat->pfCplxSymbBuff_2->pQBuffer;
	
	/*for (p = 0; p < data_len; p = p + 2)
	{
		pDetectorStat->pcDataBuff[p] = MaptoBytes(Ich_1[p], Qch_1[p], Ich_1[p+1], Qch_1[p+1]);
		pDetectorStat->pcDataBuff[p+1] = MaptoBytes(Ich_2[p], Qch_2[p], Ich_2[p+1], Qch_2[p+1]);
	}*/

	pDetectorStat->uiBytesWritten = 0;
	for (p = 0; p < data_len; p++)		
	{
		idx = (pDetectorStat->uiNextSymb + p) % pDetectorStat->uiBufLen;
		a = MaptoBytes(Ich_1[idx], Qch_1[idx]);
		if (pDetectorStat->nibble == 0)
		{
			pDetectorStat->pcDataBuff[pDetectorStat->uiNextWriteByte] = a;
			//nibble_1 = 1;
		}
		else
		{
			pDetectorStat->pcDataBuff[pDetectorStat->uiNextWriteByte] |= (a << 4);
			//nibble_1 = 0;
			//uiNextWriteByte++;
			//pDetectorStat->uiBytesWritten++;
		}
		
		b = MaptoBytes(Ich_2[idx], Qch_2[idx]);
		if (pDetectorStat->nibble == 0)
		{
			pDetectorStat->pcDataBuff[pDetectorStat->uiNextWriteByte+1] = b;
			pDetectorStat->nibble = 1;
		}
		else
		{
			pDetectorStat->pcDataBuff[pDetectorStat->uiNextWriteByte+1] |= (b << 4);
			//nibble_2 = 0;
			pDetectorStat->nibble = 0;
			pDetectorStat->uiNextWriteByte += 2;
			//uiNextWriteByte++;
			pDetectorStat->uiBytesWritten += 2;
		}
		
		
	}
}


/****************************************************************************
  Function    : norm_ML
 ****************************************************************************

  Description : Calculate the 2-norm of two symbols

  Inputs      : The real and imaginary part of two symbols

  Outputs     : 2-norm of the two symbols

  By          : 2005-05-07 Created by Anders Lindgren
  				2005-05-10 modified by Anders Lindgren

 ****************************************************************************/

static float norm_ML(float Z1_r, float Z1_i, float Z2_r, float Z2_i)
{
	float len_Z1;
	float len_Z2;
	float norm_Z;
	
	len_Z1 = sqrtf(Z1_r*Z1_r + Z1_i*Z1_i);
	len_Z2 = sqrtf(Z2_r*Z2_r + Z2_i*Z2_i);
	
	norm_Z = sqrtf(len_Z1*len_Z1 + len_Z2*len_Z2);
	
	return norm_Z;
}

/****************************************************************************
  Function    : MLDetector
 ****************************************************************************

  Description : Estimate the transmitted symbols with Maximum Likelihood

  Inputs      : Received symbols in antenna 1 and antenna 2

  Outputs     : Detected symbols in bytes

  By          : 2005-05-07 Created by Anders Lindgren
  				2005-05-13 modified by Anders Lindgren

 ****************************************************************************/

static void MLDetector(typRX_DETECTORSTATE *pDetectorStat)
{
	float data_len;
	float *pr1_data_I;
	float *pr1_data_Q;
	float *pr2_data_I;
	float *pr2_data_Q;
	float pS[2][2];
	float pZ[2][2];
	float normmin;
	float newnorm;
	float pS_out[4];
	int pp, idx;
	int s1_I = 0;
	int s1_Q = 0;

⌨️ 快捷键说明

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