?? test.c
字號:
#include "mapRemoveCpFFTequalization_oneFrame.h"
#include "../../OFDM_modulation/frame by frame/mapPilotIFFTcp_oneFrame.h"
#define TEST2
//#define TRANSCEIVER
int main(void)
{
int i;
int n;
int fftSize=8;
#ifdef TEST2
int CpLength1=5;
int CpLength2=2;
#else
//int CpLength=9;
int CpLength=2;
#endif // #ifdef TEST2
//int dataSymbolNumberPerFrame=10;
int dataSymbolNumberPerFrame=12; // upper bound is 13 for long CP or 15 for short CP
int OFDMsymbolPerFrame=7;
int numberOfOccupiedSubcarrier=4;
floatComplexVec* u_OFDMsymbolCP;
floatComplexMatrix* estimatedCFR;
intVec* occupiedSubcarrierIndex;
floatComplexMatrix* pilotPatternAndValue;
floatComplexVec* u_equalizedDataSymbol;
floatComplexVec* d_dataSymbol;
// define pilotPatternAndValue
pilotPatternAndValue=floatComplexMatrixAlloc(OFDMsymbolPerFrame, numberOfOccupiedSubcarrier);
for (i=0; i<OFDMsymbolPerFrame; ++i)
{
for (n=0; n<numberOfOccupiedSubcarrier; ++n)
{
pilotPatternAndValue->a[i][n]=floatComplexSet(0.0, 0.0);
}
}
pilotPatternAndValue->a[1][0]=floatComplexSet((float)2.1, (float)6.7);
pilotPatternAndValue->a[1][2]=floatComplexSet((float)-6.8, (float)4.8);
pilotPatternAndValue->a[2][1]=floatComplexSet((float)0.6, 0.0);
pilotPatternAndValue->a[2][3]=floatComplexSet(0.0, (float)6.7);
pilotPatternAndValue->a[3][2]=floatComplexSet(5, 5);
pilotPatternAndValue->a[4][1]=floatComplexSet(0.0, (float)-0.3);
pilotPatternAndValue->a[4][3]=floatComplexSet((float)8.6, 0.0);
pilotPatternAndValue->a[5][0]=floatComplexSet((float)1.1, (float)2.2);
pilotPatternAndValue->a[5][1]=floatComplexSet((float)3.2, (float)-6);
pilotPatternAndValue->a[5][2]=floatComplexSet((float)4.9, 0.0);
pilotPatternAndValue->a[5][3]=floatComplexSet(0.0, (float)9.1);
#ifndef TEST2
//pilotPatternAndValue->a[0][0]=floatComplexSet((float)1.1, (float)2.2);
//pilotPatternAndValue->a[0][1]=floatComplexSet((float)3.2, -6);
//pilotPatternAndValue->a[0][2]=floatComplexSet((float)4.9, 0.0);
//pilotPatternAndValue->a[0][3]=floatComplexSet(0.0, (float)9.1);
#else
//pilotPatternAndValue->a[6][0]=floatComplexSet((float)-3.89, (float)4.5);
//pilotPatternAndValue->a[6][3]=floatComplexSet(0, (float)-6.7);
#endif // #ifndef TEST2
// define occupiedSubcarrierIndex
//occupiedSubcarrierIndex=intVecAlloc(numberOfOccupiedSubcarrier+1);
occupiedSubcarrierIndex=intVecAlloc(numberOfOccupiedSubcarrier);
occupiedSubcarrierIndex->a[0]=6;
occupiedSubcarrierIndex->a[1]=7;
occupiedSubcarrierIndex->a[2]=1;
occupiedSubcarrierIndex->a[3]=2;
//occupiedSubcarrierIndex->a[3]=8;
// define d_dataSymbol (it will be used if TRANSCEIVER is defined)
d_dataSymbol=floatComplexVecAlloc(dataSymbolNumberPerFrame);
for (i=0; i<dataSymbolNumberPerFrame; ++i)
{
d_dataSymbol->a[i]=floatComplexSet((float)rand()/(float)13.1, (float)rand()/(float)10.6);
}
// define u_OFDMsymbolCP
#if (defined(TRANSCEIVER) && !defined(TEST2)) // generate u_OFDMsymbolCP through d_dataSymbol
u_OFDMsymbolCP=mapPilotIFFTcp_oneFrame(d_dataSymbol, occupiedSubcarrierIndex,
pilotPatternAndValue, fftSize, CpLength);
#endif // #if (defined(TRANSCEIVER) && !defined(TEST2))
#if (defined(TRANSCEIVER) && defined(TEST2)) // generate u_OFDMsymbolCP through d_dataSymbol
u_OFDMsymbolCP=mapPilotIFFTcp_oneFrame2(d_dataSymbol, occupiedSubcarrierIndex,
pilotPatternAndValue, fftSize, CpLength1, CpLength2);
#endif // #if (defined(TRANSCEIVER) && defined(TEST2))
#if (!defined(TRANSCEIVER) && !defined(TEST2)) // specify u_OFDMsymbolCP directly
//u_OFDMsymbolCP=floatComplexVecAlloc((fftSize+CpLength)*OFDMsymbolPerFrame+1);
u_OFDMsymbolCP=floatComplexVecAlloc((fftSize+CpLength)*OFDMsymbolPerFrame);
for (n=0; n<(fftSize+CpLength)*OFDMsymbolPerFrame; ++n)
{
u_OFDMsymbolCP->a[n]=floatComplexSet((float)n, (float)-n*2);
}
#endif // #if (!defined(TRANSCEIVER) && !defined(TEST2))
#if (!defined(TRANSCEIVER) && defined(TEST2)) // specify u_OFDMsymbolCP directly
if (CpLength2!=0)
{
//u_OFDMsymbolCP=floatComplexVecAlloc(6*(fftSize+CpLength1)+1*(fftSize+CpLength2)+1);
u_OFDMsymbolCP=floatComplexVecAlloc(6*(fftSize+CpLength1)+1*(fftSize+CpLength2));
for (n=0; n<(int)u_OFDMsymbolCP->len; ++n)
{
u_OFDMsymbolCP->a[n]=floatComplexSet((float)n, (float)-n*2);
}
}
else
{
//u_OFDMsymbolCP=floatComplexVecAlloc(6*(fftSize+CpLength1)+1);
u_OFDMsymbolCP=floatComplexVecAlloc(6*(fftSize+CpLength1));
for (n=0; n<(int)u_OFDMsymbolCP->len; ++n)
{
u_OFDMsymbolCP->a[n]=floatComplexSet((float)n, (float)-n*2);
}
}
#endif // #if (!defined(TRANSCEIVER) && defined(TEST2))
// define estimatedCFR
estimatedCFR=floatComplexMatrixAlloc(OFDMsymbolPerFrame, fftSize);
//estimatedCFR=floatComplexMatrixAlloc(OFDMsymbolPerFrame, fftSize+1);
//estimatedCFR=floatComplexMatrixAlloc(OFDMsymbolPerFrame+1, fftSize);
for (n=0; n<OFDMsymbolPerFrame; ++n)
{
for (i=0; i<fftSize; ++i)
{
#ifndef TRANSCEIVER
estimatedCFR->a[n][i]=floatComplexSet((float)n+1, (float)i+1);
#else
estimatedCFR->a[n][i]=floatComplexSet(1.0, 0.0);
#endif
}
}
// call function mapRemoveCpFFTequalization_oneFrames
#ifndef TEST2
u_equalizedDataSymbol=mapRemoveCpFFTequalization_oneFrame(u_OFDMsymbolCP,
estimatedCFR, fftSize, dataSymbolNumberPerFrame, occupiedSubcarrierIndex,
pilotPatternAndValue);
#else
u_equalizedDataSymbol=mapRemoveCpFFTequalization_oneFrame2(u_OFDMsymbolCP, estimatedCFR,
fftSize, CpLength1, CpLength2, dataSymbolNumberPerFrame, occupiedSubcarrierIndex,
pilotPatternAndValue);
#endif // #ifndef TEST2
#ifndef TEST2
printf("d_dataSymbol\n");
floatPrintComplexVec(d_dataSymbol);
printf("\npilotPatternAndValue:\n");
floatPrintComplexMatrix(pilotPatternAndValue);
printf("\noccupiedSubcarrierIndex:\n");
intPrintVec(occupiedSubcarrierIndex);
printf("\nu_OFDMsymbolCP:\n");
floatPrintComplexVec(u_OFDMsymbolCP);
printf("\nestimatedCFR:\n");
floatPrintComplexMatrix(estimatedCFR);
printf("\nu_equalizedDataSymbol:\n");
floatPrintComplexVec(u_equalizedDataSymbol);
#endif // #ifndef TEST2
#if (defined(TEST2) && !defined(TRANSCEIVER))
floatComplexVecDump(u_equalizedDataSymbol,"u_equalizedDataSymbol_r.txt","u_equalizedDataSymbol_i.txt");
#endif // #ifdef TEST2
// comparison
#ifdef TRANSCEIVER
{
printf("\n%d\n\n", u_equalizedDataSymbol->len-d_dataSymbol->len);
for (n=0; n<(int)u_equalizedDataSymbol->len; ++n)
{
printf("%f\n", u_equalizedDataSymbol->a[n].re-d_dataSymbol->a[n].re);
printf("%f\n\n", u_equalizedDataSymbol->a[n].im-d_dataSymbol->a[n].im);
}
}
#endif // #ifdef TRANSCEIVER
floatComplexMatrixFree(pilotPatternAndValue);
floatComplexMatrixFree(estimatedCFR);
floatComplexVecFree(u_equalizedDataSymbol);
floatComplexVecFree(u_OFDMsymbolCP);
floatComplexVecFree(d_dataSymbol);
intVecFree(occupiedSubcarrierIndex);
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -