📄 chcompstc.cpp
字号:
//chcomp for stc code
//input length 256
//output length 201
#include "typedef.h"
#include "chCompStc.h"
void chCompStc (Uint8 stcFlag,
Int16 *pChCompIn,
Uint16 chCompLength, //2*ffisize
PhaseParam *pPhaseShift,
Int16 *pChCompOut)
//只去处信道的固定频偏和角偏移,不去处信道响应
{
Int16 i;
Int16 freqOffsetCoarse;
double freqOffsetFine;
Int16 symbolCompIn[804];
Int16 symbolCompFirst[804];
Int16 sinValue;
Int16 cosValue;
Uint16 chCompOutLength;
Int16 shiftFixPhrase = 14;
Int16 shiftFreOffset = 15; // (16-1) mod of sine;
chCompOutLength = chCompLength - 110; //402
for (i = 0; i < chCompOutLength / 2; i++)
{
symbolCompIn[2*i] = pChCompIn[2*i+56];
symbolCompIn[2*i+1] = pChCompIn[2*i+57];
symbolCompIn[2*i+402] = pChCompIn[2*i+512+56];
symbolCompIn[2*i+403] = pChCompIn[2*i+512+57];
}
for (i = 0; i < chCompOutLength / 2; i++)
{
symbolCompFirst[2*i] = (Int16)(((Int32)symbolCompIn[2*i] * pPhaseShift[0].fixedPhase[0]
+ (Int32)symbolCompIn[2*i+1] * pPhaseShift[0].fixedPhase[1])
>> shiftFixPhrase);
symbolCompFirst[2*i+1] = (Int16)(((Int32)symbolCompIn[2*i+1] * pPhaseShift[0].fixedPhase[0]
- (Int32)symbolCompIn[2*i] * pPhaseShift[0].fixedPhase[1])
>> shiftFixPhrase);
symbolCompFirst[2*i+402] = (Int16)(((Int32)symbolCompIn[2*i+402] * pPhaseShift[0].fixedPhase[0]
+ (Int32)symbolCompIn[2*i+403] * pPhaseShift[0].fixedPhase[1])
>> shiftFixPhrase);
symbolCompFirst[2*i+403] = (Int16)(((Int32)symbolCompIn[2*i+403] * pPhaseShift[0].fixedPhase[0]
- (Int32)symbolCompIn[2*i+402] * pPhaseShift[0].fixedPhase[1])
>> shiftFixPhrase);
}
for (i = 0; i < chCompOutLength / 4; i++)
{
freqOffsetCoarse = pPhaseShift[0].freqIq * (100 - i) * 256 / (32767 * PI);
freqOffsetFine = pPhaseShift[0].freqIq * (100-i) * 256 / (32767 * PI);
if (freqOffsetCoarse == 0)
{
sinValue = freqOffsetFine * 32767 * PI / 256;
cosValue = 32767 - ((sinValue * sinValue) >> 16);//cosx=1-0.5*x^2
}
else
{
sinValue = (Int16)(g_sineTable[freqOffsetCoarse]
+ (freqOffsetFine - freqOffsetCoarse) * g_sineTable[128-freqOffsetCoarse]);
cosValue = (Int16)(g_sineTable[128-freqOffsetCoarse]
- (freqOffsetFine - freqOffsetCoarse) * g_sineTable[freqOffsetCoarse]);
}
pChCompOut[2*i] = (Int16)(((Int32)symbolCompFirst[2*i] * cosValue
- (Int32)symbolCompFirst[2*i+1] * sinValue)
>> shiftFreOffset);
pChCompOut[2*i+1] = (Int16)(((Int32)symbolCompFirst[2*i+1] * cosValue
+ (Int32)symbolCompFirst[2*i] * sinValue)
>> shiftFreOffset);
pChCompOut[2*(200-i)] = (Int16)(((Int32)symbolCompFirst[2*(200-i)] * cosValue
+ (Int32)symbolCompFirst[2*(200-i)+1] * sinValue)
>> shiftFreOffset);
pChCompOut[2*(200-i)+1] = (Int16)(((Int32)symbolCompFirst[2*(200-i)+1] * cosValue
- (Int32)symbolCompFirst[2*(200-i)] * sinValue)
>> shiftFreOffset);
pChCompOut[2*i+402] = (Int16)(((Int32)symbolCompFirst[2*i+402] * cosValue
- (Int32)symbolCompFirst[2*i+403] * sinValue)
>> shiftFreOffset);
pChCompOut[2*i+403] = (Int16)(((Int32)symbolCompFirst[2*i+403] * cosValue
+ (Int32)symbolCompFirst[2*i+402] * sinValue)
>> shiftFreOffset);
pChCompOut[2*(200-i)+402] = (Int16)(((Int32)symbolCompFirst[2*(200-i)+402] * cosValue
+ (Int32)symbolCompFirst[2*(200-i)+403] * sinValue)
>> shiftFreOffset);
pChCompOut[2*(200-i)+403] = (Int16)(((Int32)symbolCompFirst[2*(200-i)+403] * cosValue
- (Int32)symbolCompFirst[2*(200-i)+402] * sinValue)
>> shiftFreOffset);
}
//去处信道的角偏移.
pChCompOut[200] = symbolCompFirst[200];
pChCompOut[201] = symbolCompFirst[201];
pChCompOut[602] = symbolCompFirst[602];
pChCompOut[603] = symbolCompFirst[603];
//subcarrier 为0,不用去除freqoffset
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -