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

📄 chtrackstc.cpp

📁 在vc上做的802.16d ofdm phy的仿真
💻 CPP
字号:
#include "typedef.h"
#include "globalMacro.h"

#include "chTrackStc.h"
#include "chTrack.h"
	  
void chTrackStc(Uint8 stcFlag,
				Int16 *pRxFftOut,
				Uint16 rxFftOutLength,
				ChannelEstResult *pPreambleChEstRes,
				PilotParam *pPilotParam,
				Int8 	pStcPilots[][8],
				PhaseParam *pPhaseShift)
{
	Int16  i;
	Uint8  wk;
	Uint8  outBit;
	Int16  symbolTrackLength = 201;
	Int16  symbolTrackIn[402];
	Int16  trackPilot[8*2*2];//estimate channel frequence offset;
	Int16  tempI,tempQ;
	Int16  freqOffset;
	Int16  tanValue;
	Int16  angular;
	Int16  sinValue,cosValue;
	Int8   resign, imsign, sign;
	Int16  pilotOffsetSin[4],pilotOffsetCos[4];
	Int16  pilotOffset;
	Uint8  freqOffsetShift = 12;
	Uint8  fixPhaseShift = 15;
	Uint8  trackshift = 14;	
	
	if (pPilotParam->ofdmSymIndex == 0)
	{
		pPilotParam->registers = pPilotParam->encodePoly;
	}
	
	wk = (pPilotParam->registers & 1);
	outBit = wk ^ ((pPilotParam->registers >>2) & 1);
	pPilotParam->registers >>= 1;
	outBit <<= 10;
	pPilotParam->registers |= outBit;
	pPilotParam->ofdmSymIndex ++;
	
	pStcPilots[0][0] = 1 - 2 * wk;
	pStcPilots[0][2] = 1 - 2 * wk;
	pStcPilots[0][6] = 1 - 2 * wk;
	pStcPilots[0][7] = 1 - 2 * wk;
	pStcPilots[0][1] = 1 - 2 * (~wk&1);
	pStcPilots[0][3] = 1 - 2 * (~wk&1);
	pStcPilots[0][4] = 1 - 2 * (~wk&1);
	pStcPilots[0][5] = 1 - 2 * (~wk&1);
	
	wk = (pPilotParam->registers & 1);
	outBit = wk ^ ((pPilotParam->registers >> 2) & 1);
	pPilotParam->registers >>= 1;
	outBit <<= 10;
	pPilotParam->registers |= outBit;
	pPilotParam->ofdmSymIndex ++;
	
	pStcPilots[1][0] = 1 - 2 * wk;
	pStcPilots[1][2] = 1 - 2 * wk;
	pStcPilots[1][6] = 1 - 2 * wk;
	pStcPilots[1][7] = 1 - 2 * wk;
	pStcPilots[1][1] = 1 - 2 * (~wk&1);
	pStcPilots[1][3] = 1 - 2 * (~wk&1);
	pStcPilots[1][4] = 1 - 2 * (~wk&1);
	pStcPilots[1][5] = 1 - 2 * (~wk&1);
	
	for (i = 0; i < rxFftOutLength / 2 - 55; i++)
	{
		symbolTrackIn[2*i] = pRxFftOut[2*i+56];
		symbolTrackIn[2*i+1] = pRxFftOut[2*i+57];
	}
	
		//求出每个pilot的偏移角度
	
	for (i = 0; i < 4; i++)
	{
		trackPilot[2*i] = (Int16) (((Int32)(pPreambleChEstRes[0].ChEstOut[2*(12+25*i)] * pStcPilots[0][i]
						+ pPreambleChEstRes[1].ChEstOut[2*(12+25*i)] * pStcPilots[1][i])
						* symbolTrackIn[2*(12+25*i)] 
						+ (Int32)(pPreambleChEstRes[0].ChEstOut[2*(12+25*i)+1] * pStcPilots[0][i]
						+ pPreambleChEstRes[1].ChEstOut[2*(12+25*i)+1] * pStcPilots[1][i])	
						* symbolTrackIn[2*(12+25*i)+1]) >> trackshift);
					 	
		trackPilot[2*i+1] = (Int16) (((Int32)(pPreambleChEstRes[0].ChEstOut[2*(12+25*i)] * pStcPilots[0][i]
						+ pPreambleChEstRes[1].ChEstOut[2*(12+25*i)] * pStcPilots[1][i])
						* symbolTrackIn[2*(12+25*i)+1] 
						- (Int32)(pPreambleChEstRes[0].ChEstOut[2*(12+25*i)+1] * pStcPilots[0][i]
						+ pPreambleChEstRes[1].ChEstOut[2*(12+25*i)+1] * pStcPilots[1][i])	
						* symbolTrackIn[2*(12+25*i)])>> trackshift);
	}		
	for (i = 4; i < 8; i++)
	{
		trackPilot[2*i] = (Int16) (((Int32)(pPreambleChEstRes[0].ChEstOut[2*(13+25*i)] * pStcPilots[0][i]
						+ pPreambleChEstRes[1].ChEstOut[2*(13+25*i)] * pStcPilots[1][i])
						* symbolTrackIn[2*(13+25*i)]
						+ (Int32)(pPreambleChEstRes[0].ChEstOut[2*(13+25*i)+1] * pStcPilots[0][i]
						+ pPreambleChEstRes[1].ChEstOut[2*(13+25*i)+1] * pStcPilots[1][i])	
						* symbolTrackIn[2*(13+25*i)+1])>> trackshift);
					 	
		trackPilot[2*i+1] = (Int16) (((Int32)(pPreambleChEstRes[0].ChEstOut[2*(13+25*i)] * pStcPilots[0][i]
						+ pPreambleChEstRes[1].ChEstOut[2*(13+25*i)] * pStcPilots[1][i])
						* symbolTrackIn[2*(13+25*i)+1] 
						- (Int32)(pPreambleChEstRes[0].ChEstOut[2*(13+25*i)+1] * pStcPilots[0][i]
						+ pPreambleChEstRes[1].ChEstOut[2*(13+25*i)+1] * pStcPilots[1][i])	
						* symbolTrackIn[2*(13+25*i)]) >> trackshift);	
	}	
	
	for (i = 0; i < rxFftOutLength/2 - 55; i++)
	{
		symbolTrackIn[2*i] = pRxFftOut[2*i+512+56];
		symbolTrackIn[2*i+1] = pRxFftOut[2*i+512+57];
	}
			
	for (i = 0; i < 4; i++)
	{
		trackPilot[16+2*i] = (Int16) (((Int32)(pPreambleChEstRes[0].ChEstOut[2*(12+25*i)] * (-pStcPilots[1][i])
						+ pPreambleChEstRes[1].ChEstOut[2*(12+25*i)] * pStcPilots[0][i])
						* symbolTrackIn[2*(12+25*i)] 
						+ (Int32)(pPreambleChEstRes[0].ChEstOut[2*(12+25*i)+1] * (-pStcPilots[1][i])
						+ pPreambleChEstRes[1].ChEstOut[2*(12+25*i)+1] * pStcPilots[0][i])	
						* symbolTrackIn[2*(12+25*i)+1]) >> trackshift);
					 	
		trackPilot[17+2*i] = (Int16) (((Int32)(pPreambleChEstRes[0].ChEstOut[2*(12+25*i)] * (-pStcPilots[1][i])
						+ pPreambleChEstRes[1].ChEstOut[2*(12+25*i)] * pStcPilots[0][i])
						* symbolTrackIn[2*(12+25*i)+1] 
						- (Int32)(pPreambleChEstRes[0].ChEstOut[2*(12+25*i)+1] * (-pStcPilots[1][i])
						+ pPreambleChEstRes[1].ChEstOut[2*(12+25*i)+1] * pStcPilots[0][i])	
						* symbolTrackIn[2*(12+25*i)]) >> trackshift);
	}		
	for (i = 4; i < 8; i++)
	{
		trackPilot[16+2*i] = (Int16) (((Int32)(pPreambleChEstRes[0].ChEstOut[2*(13+25*i)] * (-pStcPilots[1][i])
						+ pPreambleChEstRes[1].ChEstOut[2*(13+25*i)] * pStcPilots[0][i])
						* symbolTrackIn[2*(13+25*i)] 
						+ (Int32)(pPreambleChEstRes[0].ChEstOut[2*(13+25*i)+1] * (-pStcPilots[1][i])
						+ pPreambleChEstRes[1].ChEstOut[2*(13+25*i)+1] * pStcPilots[0][i])	
						* symbolTrackIn[2*(13+25*i)+1]) >> trackshift);
					 	
		trackPilot[17+2*i] = (Int16) (((Int32)(pPreambleChEstRes[0].ChEstOut[2*(13+25*i)] * (-pStcPilots[1][i])
						+ pPreambleChEstRes[1].ChEstOut[2*(13+25*i)] * pStcPilots[0][i])
						* symbolTrackIn[2*(13+25*i)+1] 
						- (Int32)(pPreambleChEstRes[0].ChEstOut[2*(13+25*i)+1] * (-pStcPilots[1][i])
						+ pPreambleChEstRes[1].ChEstOut[2*(13+25*i)+1] * pStcPilots[0][i])	
						* symbolTrackIn[2*(13+25*i)]) >> trackshift);	
	}
	//相关,求出w(freqIq),求出w
	tempI = tempQ = 0;
		
	for (i = 0; i < 3; i++)
	{
		tempI += (Int16) (((Int32) trackPilot[2*i] * trackPilot[2*(i+1)] 
				+ (Int32) trackPilot[2*i+1] * trackPilot[2*(i+1)+1]
				+ (Int32) trackPilot[2*i+2*8] * trackPilot[2*(i+1)+2*8] 
				+ (Int32) trackPilot[2*i+2*8+1] * trackPilot[2*(i+1)+2*8+1]) 
				>> freqOffsetShift);
				
		tempQ += (Int16) (((Int32) trackPilot[2*i] * trackPilot[2*(i+1)+1] 
				- (Int32) trackPilot[2*i+1] * trackPilot[2*(i+1)]
				+ (Int32) trackPilot[2*i+2*8] * trackPilot[2*(i+1)+2*8+1] 
				- (Int32) trackPilot[2*i+2*8+1] * trackPilot[2*(i+1)+2*8]) 
				>> freqOffsetShift);
	}
	for (i = 4; i < 7; i++)
	{
		tempI += (Int16) (((Int32) trackPilot[2*i] * trackPilot[2*(i+1)] 
				+ (Int32) trackPilot[2*i+1] * trackPilot[2*(i+1)+1]
				+ (Int32) trackPilot[2*i+2*8] * trackPilot[2*(i+1)+2*8] 
				+ (Int32) trackPilot[2*i+2*8+1] * trackPilot[2*(i+1)+2*8+1])
				>> freqOffsetShift);
				
		tempQ += (Int16) (((Int32) trackPilot[2*i] * trackPilot[2*(i+1)+1] 
				- (Int32) trackPilot[2*i+1] * trackPilot[2*(i+1)]
				+ (Int32) trackPilot[2*i+2*8] * trackPilot[2*(i+1)+2*8+1] 
				- (Int32) trackPilot[2*i+2*8+1] * trackPilot[2*(i+1)+2*8]) 
				>> freqOffsetShift);		
	}
	
	resign = (tempI >= 0) ? 1 : -1;
	imsign = (tempQ >= 0) ? 1 : -1;
	sign = resign * imsign;
	tempI *= resign;
	tempQ *= imsign;
	if (tempQ <= tempI)//[0, pi/4];	
	{
		if (tempI == 0)
		{
			angular = 0;
		}
		else
		{
			tanValue = tempQ * 128 / tempI;
			angular = g_atanCoarseTable[tanValue]
					+ (( tempQ * 32767 / tempI - g_atanQuanLevelTable[tanValue]) * g_atanFineTable[tanValue] / 32767);
				//查表,得出angular
		}
		(*pPhaseShift).freqIq = angular / 25;//每两个pilot间隔25个subcarrier
	}
	else
	{
		tanValue = tempI * 128 / tempQ;
		angular = g_atanCoarseTable[tanValue]
				 + ((tempI * 32767 / tempQ - g_atanQuanLevelTable[tanValue]) * g_atanFineTable[tanValue] / 32767);
		(*pPhaseShift).freqIq = (51470 - angular) / 25;
	}
	freqOffset = pPhaseShift->freqIq * 64 / 32767;
	calculate(freqOffset, &sinValue, &cosValue);
	(*pPhaseShift).fixedPhase[0] = (*pPhaseShift).fixedPhase[1] = 0;
	
	for (i = 0; i < 4; i++)
	{
		pilotOffset = 13 + 25 * (3 - i) * freqOffset;//13,38,63,88 ?pilot
		calculate(pilotOffset, &pilotOffsetSin[i], &pilotOffsetCos[i]);
		
		(*pPhaseShift).fixedPhase[0] += (Int16) (((Int32) trackPilot[2*i] * pilotOffsetCos[i] 
										- (Int32) trackPilot[2*i+1] * pilotOffsetSin[i]
										+ (Int32) trackPilot[2*(7-i)] * pilotOffsetCos[i] 
										+ (Int32) trackPilot[2*(7-i)+1] * pilotOffsetSin[i]
										+ (Int32) trackPilot[2*i+16] * pilotOffsetCos[i] 
										- (Int32) trackPilot[2*i+17] * pilotOffsetSin[i]
										+ (Int32) trackPilot[2*(7-i)+16] * pilotOffsetCos[i] 
										+ (Int32) trackPilot[2*(7-i)+17] * pilotOffsetSin[i]) 
										>> fixPhaseShift);
		
		(*pPhaseShift).fixedPhase[1] += (Int16) (((Int32) trackPilot[2*i+1] * pilotOffsetCos[i] 
										+ (Int32) trackPilot[2*i] * pilotOffsetSin[i]
										+ (Int32) trackPilot[2*(7-i)+1] * pilotOffsetCos[i] 
										- (Int32) trackPilot[2*(7-i)] * pilotOffsetSin[i]
										+ (Int32) trackPilot[2*i+17] * pilotOffsetCos[i] 
										+ (Int32) trackPilot[2*i+16] * pilotOffsetSin[i]
										+ (Int32) trackPilot[2*(7-i)+17] * pilotOffsetCos[i] 
										- (Int32) trackPilot[2*(7-i)+16] * pilotOffsetSin[i]) 
										>> fixPhaseShift);

	}
	//固定角偏移fixedPhase
}

⌨️ 快捷键说明

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