?? frameofdm.c
字號:
#include <stdio.h>
#include <math.h>
#include "Setting.H"
#include "RS.H"
#include "Function.H"
#include "asintable.h"
/*
This script generates a COFDM waveform from an input data */
void OFDMModu(DType DataStr[], int BaseSignal[], DType RefPhase[])
/* DataStr: RS coded data to transmit in the CodewordBit given,
* UsedCarrier * SymPerFrame in length;
* BaseSignal: Final output modulated signal, SymbolSize * SymPerFrame in length;
* RefPhase: DPSK reference phase, UsedCarrier * 1 in length;
*/
{
WordType i, j, k;
DType DPSKdata[SymPerFrame * UsedCarrier];
long int TxSpecR[FFTSize], TxSpecI[FFTSize];
DType *pDPSK ,*pDataStr;
long int *pTxSpecR, *pTxSpecI;
int *pBase;
pBase = BaseSignal;
/* Convert to DQPSK */
for (j = 0; j < UsedCarrier; j++)
{
DPSKdata[j] = (DType) (DataStr[j] + RefPhase[j]) &
(DType) ((1 << CodewordBit) - 1);
}
pDPSK = DPSKdata + UsedCarrier;
pDataStr = DataStr + UsedCarrier;
for (i = 1; i < SymPerFrame; i++)
{
for (j = 0; j < UsedCarrier; j++)
{
*pDPSK = (DType) ((*pDataStr) + (*(pDPSK - UsedCarrier))) & (DType) ((1 << CodewordBit) - 1);
pDataStr++;
pDPSK++;
//DPSKdata[j + i * UsedCarrier] =
// (DType) (DataStr[j + i * UsedCarrier] + DPSKdata[j + (i - 1) * UsedCarrier]) &
// (DType) ((1 << CodewordBit) - 1);
}
}
/* Store the last carrier data in RefPhase[] for next subframe */
for (j = 0; j < UsedCarrier; j++)
{
RefPhase[j] = DPSKdata[j + (SymPerFrame - 1) * UsedCarrier];
}
/* Get the required spectrums */
k = 0;
for (j = 0; j < SymPerFrame; j++)
{
pTxSpecR = TxSpecR;
pTxSpecI = TxSpecI;
pDPSK = &DPSKdata[j * UsedCarrier + 1 - CarrierJumpPos];
for (i = 0; i < FFTSize; i++)
{
if ((i > CarrierJumpPos - 2) && (i < CarrierJumpPos + UsedCarrier - 1))
{
switch (*pDPSK)
{
case 0: *pTxSpecR = 16384; *pTxSpecI = 0; break;
case 1: *pTxSpecR = 0; *pTxSpecI = 16384; break;
case 2: *pTxSpecR = -16384; *pTxSpecI = 0; break;
case 3: *pTxSpecR = 0; *pTxSpecI = -16384;
}
}
else
{
*pTxSpecR = 0;
*pTxSpecI = 0;
}
pTxSpecR++;
pTxSpecI++;
pDPSK++;
}
/* Change to time waveform using IFFT */
FFT(TxSpecR, TxSpecI, -1);
/* Add cycle prefixion (guardtime) */
pTxSpecR = TxSpecR + FFTSize - GuardTimeSize;
for (i = GuardTimeSize; i > 0; i--)
{
*pBase =(int)(*pTxSpecR);
k++;
pBase++;
pTxSpecR++;
}
pTxSpecR = TxSpecR;
for (i = 0; i < FFTSize; i++)
{
*pBase =(int)(*pTxSpecR);
k++;
pBase++;
pTxSpecR++;
}
}
}
/* This script demodulates a COFDM waveform from an input data:
* DataStr: Received real signal, SymbolSize * SymPerFrame in length;
* SpecSignal: Demodulated RS data in CodewordBit size per symbol,
* UsedCarrier * SymPerFrame in length;
* RefPhase: DPSK reference phase, UsedCarrier * 1 in length;
*/
void OFDMDemo(int BaseSignal[], DType SpecSignal[], long int RefPhase[])
{
WordType i, j;
long int RxSpecR[FFTSize], RxSpecI[FFTSize];
long int CarrPh[SymPerFrame * UsedCarrier];
//int index;
int * pBase;
long int *pRxSpecR, *pRxSpecI,*pCarrPh,xR,xI;
DType *pSpec;
/* Reshape the linear time waveform into FFT segments & remove guard time */
for (i = 0; i < SymPerFrame; i++)
{
pRxSpecR = RxSpecR;
pRxSpecI = RxSpecI;
pBase = &BaseSignal[i * SymbolSize + GuardTimeSize];
for (j = 0; j < FFTSize; j++)
{
*pRxSpecR = (long int)(*pBase);
*pRxSpecI = 0;
pRxSpecR++;
pRxSpecI++;
pBase++;
}
/* Apply FFT on the rest of received data */
FFT(RxSpecR, RxSpecI, 1);
/* Convert to QPSK phase */
pCarrPh = &CarrPh[i * UsedCarrier];
pRxSpecR = RxSpecR + CarrierJumpPos - 1;
pRxSpecI = RxSpecI + CarrierJumpPos - 1;
for (j = 0; j < UsedCarrier; j++)
{
/* xR = *pRxSpecR;
xI = *pRxSpecI;
index = (float)90 * xI*xI/(xI*xI+xR*xR);
*pCarrPh = asin_tab[index]; //Q15
if(xR>=0 && xI<0)
{
*pCarrPh = -(*pCarrPh) + PI2Q15;
}
else if(xR<0 && xI<=0)
{
*pCarrPh = *pCarrPh + PIQ15;
}
else if(xR<0 && xI>0)
{
*pCarrPh = -(*pCarrPh) + PIQ15;
}*/
*pCarrPh = arctan2(*pRxSpecI, *pRxSpecR);
pRxSpecR++;
pRxSpecI++;
pCarrPh++;
}
}
/* Apply DQPSK on the received data */
for (j = 0; j < UsedCarrier; j++)
{
SpecSignal[j] = (DType) ((CarrPh[j] - RefPhase[j] + PI2Q15 + PIQ15 / (1 << CodewordBit)) /
(PIQ15 / (1 << CodewordBit) * 2)) & (DType) ((1 << CodewordBit) - 1);
}
pSpec = SpecSignal + UsedCarrier;
pCarrPh = CarrPh + UsedCarrier;
for (i = 1; i < SymPerFrame; i++)
{
for (j = 0; j < UsedCarrier; j++)
{
xR = *pCarrPh;
xI = *(pCarrPh - UsedCarrier);
*pSpec = (DType) ((xR - xI + PI2Q15 + PIQ15 / (1 << CodewordBit)) / (PIQ15 / (1 << CodewordBit) * 2)) &
(DType) ((1 << CodewordBit) - 1);
pSpec++;
pCarrPh++;
}
}
/* Save the RefPhase for next subframe */
pCarrPh = CarrPh + (SymPerFrame - 1) * UsedCarrier;
for (j = 0; j < UsedCarrier; j++)
{
RefPhase[j] = *pCarrPh;
pCarrPh++;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -