📄 chtrack.cpp
字号:
#include "typedef.h"
#include "chTrack.h"
#include "globalMacro.h"
void calculate(Int16 w, Int16 *sin, Int16 *cos)
{
if (w == 0)
{
*sin = 0;
*cos = 32767;
}
else
{
*sin = g_sineTable[w];
*cos = g_sineTable[128 - w];
}
}
void chTrack (Int16 *pRxFftOut,
Uint16 rxFftOutLength,
ChannelEstResult *pPreambleChEstRes,
PilotParam *pPilotParam,
PhaseParam *pPhaseShift)
{
Int16 i;
Uint8 wk;
Uint8 outBit;
Int16 symbolTrackLength = 201;
Int16 symbolTrackIn[402];
Int16 trackPilot[8*2];//remove chEst;
Int16 tempI,tempQ;
Int16 freqOffset;
Int16 tanValue;
Int16 angular;
Int16 sinValue,cosValue;
Int16 pilotOffsetSin[4],pilotOffsetCos[4];
Int16 pilotOffset;
Int8 resign, imsign, sign;
Uint8 freqOffsetShift = 12;
Uint8 fixPhaseShift = 15;
Uint8 trackshift = 12;
for (i = 0; i < rxFftOutLength - 55; i++)
{
symbolTrackIn[2*i] = pRxFftOut[2*i+56];
symbolTrackIn[2*i+1] = pRxFftOut[2*i+57];
}
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 ++;
for (i = 0; i < 4; i++)
{
if (i == 1 || i == 3)
{
trackPilot[2*i] = (Int16) (((Int32) symbolTrackIn[2*(12+25*i)] * pPreambleChEstRes[0].ChEstOut[2*(12+25*i)]
+ (Int32) symbolTrackIn[2*(12+25*i)+1] * pPreambleChEstRes[0].ChEstOut[2*(12+25*i)+1]) >> trackshift) * (1-2*(~wk&1));
trackPilot[2*i+1] = (Int16) (((Int32) symbolTrackIn[2*(12+25*i)+1] * pPreambleChEstRes[0].ChEstOut[2*(12+25*i)]
- (Int32) symbolTrackIn[2*(12+25*i)] * pPreambleChEstRes[0].ChEstOut[2*(12+25*i)+1]) >> trackshift) * (1-2*(~wk&1));
}
else
{
trackPilot[2*i] = (Int16) (((Int32) symbolTrackIn[2*(12+25*i)] * pPreambleChEstRes[0].ChEstOut[2*(12+25*i)]
+ (Int32) symbolTrackIn[2*(12+25*i)+1] * pPreambleChEstRes[0].ChEstOut[2*(12+25*i)+1]) >> trackshift) * (1-2*(wk));
trackPilot[2*i+1] = (Int16) (((Int32) symbolTrackIn[2*(12+25*i)+1] * pPreambleChEstRes[0].ChEstOut[2*(12+25*i)]
- (Int32) symbolTrackIn[2*(12+25*i)] * pPreambleChEstRes[0].ChEstOut[2*(12+25*i)+1]) >> trackshift) * (1-2*(wk));
}
}
for (i = 4; i < 8; i++)
{
if (i == 4 || i == 5)
{
trackPilot[2*i] = (Int16) (((Int32) symbolTrackIn[2*(13+25*i)] * pPreambleChEstRes[0].ChEstOut[2*(13+25*i)]
+ (Int32) symbolTrackIn[2*(13+25*i)+1] * pPreambleChEstRes[0].ChEstOut[2*(13+25*i)+1]) >> trackshift) * (1-2*(~wk&1));
trackPilot[2*i+1] = (Int16) (((Int32) symbolTrackIn[2*(13+25*i)+1] * pPreambleChEstRes[0].ChEstOut[2*(13+25*i)]
- (Int32) symbolTrackIn[2*(13+25*i)] * pPreambleChEstRes[0].ChEstOut[2*(13+25*i)+1]) >> trackshift) * (1-2*(~wk&1));
}
else
{
trackPilot[2*i] = (Int16) (((Int32) symbolTrackIn[2*(13+25*i)] * pPreambleChEstRes[0].ChEstOut[2*(13+25*i)]
+ (Int32) symbolTrackIn[2*(13+25*i)+1] * pPreambleChEstRes[0].ChEstOut[2*(13+25*i)+1]) >> trackshift) * (1-2*(wk));
trackPilot[2*i+1] = (Int16) (((Int32) symbolTrackIn[2*(13+25*i)+1] * pPreambleChEstRes[0].ChEstOut[2*(13+25*i)]
- (Int32) symbolTrackIn[2*(13+25*i)] * pPreambleChEstRes[0].ChEstOut[2*(13+25*i)+1]) >> trackshift) * (1-2*(wk));
}
}
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])
>> freqOffsetShift);
tempQ += (Int16) (((Int32) trackPilot[2*i] * trackPilot[2*(i+1)+1]
- (Int32) trackPilot[2*i+1] * trackPilot[2*(i+1)])
>> 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]) >> freqOffsetShift);
tempQ += (Int16) (((Int32) trackPilot[2*i] * trackPilot[2*(i+1)+1]
- (Int32) trackPilot[2*i+1] * trackPilot[2*(i+1)]) >> freqOffsetShift);
}
resign = (tempI >= 0) ? 1 : -1;
imsign = (tempQ >= 0) ? 1 : -1;
sign = resign * imsign;
tempI *= resign;
tempQ *= imsign;
if (tempQ <= tempI)//[0, pi/4);
{
tanValue = tempQ * 128 / tempI;
angular = g_atanCoarseTable[tanValue] +
((tempQ * 32767 / tempI - g_atanQuanLevelTable[tanValue]) * g_atanFineTable[tanValue] / 32767);
pPhaseShift->freqIq = angular / 25;
}
else
{
tanValue = tempI * 128 / tempQ;
angular = g_atanCoarseTable[tanValue] +
( ( tempI * 32767 / tempQ - g_atanQuanLevelTable[tanValue]) * g_atanFineTable[tanValue] / 32767);
pPhaseShift->freqIq = (51470 - angular) / 25; //pi/2~~~~51470 pi/4 ~~~~25735
}
freqOffset = pPhaseShift->freqIq * 256 / (32767 * PI);
//the phase change angular frequency.
calculate(freqOffset, &sinValue, &cosValue);
pPhaseShift->fixedPhase[0] = pPhaseShift->fixedPhase[1] = 0;
for (i = 0; i < 4; i++)
{
pilotOffset = (13 + 25 * (3 - i) ) * freqOffset;//subcarrier number 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])
>> 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])
>> fixPhaseShift);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -