📄 dlrxdemod.cpp
字号:
#include "typedef.h"
#include "global_var.h"
#include "globalMacro.h"
#include "dlRxDemod.h"
#include "math.h"
#include "fft.h"
//#define PI 3.1415926
//ȥcp, t, f
void freqDerotation(Int16 *pRxIn,
Uint16 rxInLength,
Int16 timeOffset,
Int16 freqOffset,
Int16 *pRxOut)
{
int i;
Int16 *pInTmp;
Int16 *pOutTmp;
double freq,tempi,tempq;
Int16 cpLength;
Int16 autoLag; //autoCorrelation Lag ,NULL
Int16 dataLength;
autoLag = 2 * 64;
cpLength = 2 * g_cpDataRatio;
dataLength = rxInLength - autoLag;
pOutTmp = pRxOut + dataLength - cpLength - 1;
if (timeOffset >= 0)
{// timeOffset greater than zero, delay the signal by timeOffset.
pInTmp = pRxIn + dataLength - 2 * timeOffset - 1;
for (i = 0; i < dataLength - cpLength - 2 * timeOffset; i++)
{
*pOutTmp-- = *pInTmp--;
}
for (i = 0; i < 2 * timeOffset; i++)
{
*pOutTmp-- = 0;
}
}
else
{//timeOffset less than zero. eliminate delay of signal by timeOffset.
pInTmp = pRxIn + dataLength - 1;
for (i = 0; i < 2 * (- timeOffset); i++)
{
*pOutTmp-- = 0;
}
for (i = 0; i < dataLength - cpLength + 2 * timeOffset; i++)
{
*pOutTmp-- = *pInTmp--;
}
}
freq = freqOffset * 2 * PI / 32768 ;
for (i = 0; i < (rxInLength - cpLength) /2; i++)
{
tempi = pRxOut[2 * i] * cos(freq * i) - pRxOut[2 * i + 1] * sin(freq * i);
tempq = pRxOut[2 * i] * sin(freq * i) + pRxOut[2 * i + 1] * cos(freq * i);
pRxOut[2 * i] = tempi;
pRxOut[2 * i + 1] = tempq;
}
}
void dlRxDemod()
{
int i;
Uint8 fftWeightBW;
Uint16 fftSize;
Uint16 rxDeInLength;
Int16 *pFftOutBuff;
fftWeightBW = FFT_WEIGHTS_BITWIDTH;
fftSize = FFT_SIZE;
rxDeInLength = DL_RX_BUFF_SIZE;
pFftOutBuff = g_dlRxFftOutBuff;
freqDerotation (g_dlRxBuff, rxDeInLength, 0, 0, g_dlFreqDerotBuff);
for (i = 1; i < fftSize; i+=2)
{
g_dlFreqDerotBuff[2*i] *= -1;;
g_dlFreqDerotBuff[2*i+1] *= -1;
}
if (g_dlRxStcFlag == 1) //not stc and stcflag=0
{
pFftOutBuff += 2 * fftSize;
}
fft (g_dlFreqDerotBuff, fftSize, fftWeights, fftWeightBW, pFftOutBuff);
for (i = 0; i < fftSize; i++)
{
pFftOutBuff[2*i] >>= 1;
pFftOutBuff[2*i+1] >>= 1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -