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

📄 rxdownconv.c

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

  Function   : 

  Procedures : none

  Author     : $Author: Adrian $

  Revision   : $Revision: 10 $

  Modified   : $Modtime: 05-05-29 10:39 $

  File       : $Workfile: rxdownconv.c $

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

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

/* import */
#include "../common/commondef.h"

/* export */
#include "rxdownconv.h"
#include <math.h>

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


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

typRX_DOWNCONVSTATE DownConvState;


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

extern float cos_table[COS_TAB_SIZE];

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

  Description : downconvert the received passband signal to basedband

  Inputs      : data stream and estimated frequency

  Outputs     : baseband signal

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

 ****************************************************************************/
void downconvert(Int16 * restrict pInBuffer, typCOM_fCPLXBUFF * restrict fCplxTempBuffer1,
	typCOM_fCPLXBUFF * restrict fCplxTempBuffer2, typRX_DOWNCONVSTATE *pDownConvState,
	const unsigned int uiInBuffSize)
{
/*	unsigned int n = 0;
	Int16 pos = 0;
	Int16 lookup_index = 0;
	Int16 index_sin = 0;
	Int16 index_cos = 0;
    float interval;
//	float delta_x;
	float cos_n, sin_n;
	
	float temp1 = 0.0;
	float temp2 = 0.0;

	unsigned int s = pDownConvState->unPhaseIndex;
	float Omega = (pDownConvState->fInterFreq*_rcpsp((float)SAMPFREQ));
	float phase_decimal = pDownConvState->fPhaseDeci;
	float factor = 2*PI*_rcpsp((float)COS_TAB_SIZE);
*/
	unsigned int n = pDownConvState->unPhaseIndex;
	unsigned int i, lookup_index;
	Int16 index_sin, index_cos;
	float cos_n, sin_n;
	float omega = pDownConvState->fInterFreq/SAMPFREQ;// * _rcpsp((float)SAMPFREQ);

	for(i=0;i<(uiInBuffSize/2);i++)
	{
		lookup_index = (int)(COS_TAB_SIZE * omega * n);

		index_cos = (Int16)(lookup_index & (COS_TAB_SIZE-1));
		index_sin = (Int16)((lookup_index + 3*COS_TAB_SIZE/4) & (COS_TAB_SIZE-1));

		cos_n = cos_table[index_cos];
		sin_n = cos_table[index_sin];

		fCplxTempBuffer1->pIBuffer[i] =  cos_n*(float)pInBuffer[2*i];
		fCplxTempBuffer1->pQBuffer[i] = -sin_n*(float)pInBuffer[2*i];
		fCplxTempBuffer2->pIBuffer[i] =  cos_n*(float)pInBuffer[2*i+1];
		fCplxTempBuffer2->pQBuffer[i] = -sin_n*(float)pInBuffer[2*i+1];

		n++;
	}	
	pDownConvState->unPhaseIndex = n % ((10*SAMPFREQ)/INTERFREQ);

/*	while(n < uiInBuffSize)
	{
		// times by cos and -sin
	//	interval = (Omega*(n/2)-floorf(Omega*(n/2)));
	
		interval = modff(temp1,&temp2);
		

		lookup_index = (Int16)(COS_TAB_SIZE * interval+ phase_decimal);
	//	delta_x = (interval - lookup_index)*factor;

	//	lookup_index += s; //ensure the phase continuous  
		index_cos = (lookup_index + s) & (COS_TAB_SIZE-1);
		index_sin = (lookup_index + s + 3*COS_TAB_SIZE/4) & (COS_TAB_SIZE-1);
	//	index_sin = index_sin>COS_TAB_SIZE?(index_sin-COS_TAB_SIZE):index_sin;
		
	//	cos_n = (1-0.5*delta_x*delta_x)*cos_table[lookup_index] - delta_x*cos_table[index_sin];
	//	sin_n = (1-0.5*delta_x*delta_x)*cos_table[index_sin] + delta_x*cos_table[lookup_index];

		cos_n = cos_table[index_cos];
		sin_n = cos_table[index_sin];
		
		fCplxTempBuffer1->pIBuffer[pos] =  cos_n*(float)pInBuffer[n];
		fCplxTempBuffer1->pQBuffer[pos] = -sin_n*(float)pInBuffer[n];
		
		fCplxTempBuffer2->pIBuffer[pos] =  cos_n*(float)pInBuffer[n+1];
		fCplxTempBuffer2->pQBuffer[pos] = -sin_n*(float)pInBuffer[n+1];

		temp1 += Omega;
		pos++;
		n += 2;
		

	}//end while n	
	
	temp1 = COS_TAB_SIZE * (interval + Omega);
	pDownConvState->fPhaseDeci = modff(temp1, &temp2);
	pDownConvState->unPhaseIndex = (unsigned int)temp2;//ensure the phase continuous  
*/
}

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

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

$Log: /MIMO/Receiver/rxdownconv.c $ 
 * 
 * 10    05-05-29 11:24 Adrian
 * rewrote the downconversion to remove an error causing discontinuities
 * and to optimize the function
 * 
 * 9     05-05-26 9:16 Adrian
 * changed unSampleIndex to unPhaseIndex
 * 
 * 8     05-05-25 12:07 Jinfeng
 * remove the memory dependence between interval and n
 * 
 * 7     05-05-24 16:56 Jinfeng
 * small improvement to optimized.
 * 
 * 6     05-05-23 19:58 Jinfeng
 * Introduce new variable to decrease the phase error and verified with
 * MATLAB
 * 
 * 5     05-05-23 10:40 Jinfeng
 * remove modification of cos table, need to be optimized.
 * 
 * 4     05-05-18 23:43 Jinfeng
 * correct index_sin in the cos_table
 * 
 * 3     05-05-18 14:23 Jinfeng
 * correct errors to sustain continuous phase
 * 
 * 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 + -