📄 main.cpp
字号:
#include "parameter_sets.h"
///////////////////////////////////////////////////////////////////////////////
// Release 1.0
// Build the initial program
///////////////////////////////////////////////////////////////////////////////
//Release 2.0
//添加打孔方式
//////////////////////////////////////////////////////////////////////////
const int MAX_Eb_No = 20;
const int MAX_RETRANS = 10;
const char version[10] = "1.0";
int main()
{
//Declaration
int i,j,k,m;
struct BasicParaS ctrl;
int * inputData,* encodeOut, * decodeOut;
double * demoduOut, * demoduOut1, * demoduOut2;
struct Complex * moduOut;
double local_ber, global_ber[MAX_Eb_No], global_fer[MAX_Eb_No],global_throughPut[MAX_Eb_No];
double fer[MAX_Eb_No][MAX_RETRANS];
double l[MAX_RETRANS];
double f;
for (i=0; i<79; i++)
printf("*");
printf("\n** The Data Puncturing simulation program of < Release %s>\n", version);
for (i=0; i<79; i++)
printf("*");
printf("\n");
// Display the parameters used in the current simulation
if (DispInitParaF(&ctrl) != 0)
exit(0);
// Loading the basic check matrix H
if (LoadBasicMatrixF(&ctrl) != 0)
exit(0);
// Expand the basic matrix to the actual check matrix Hp
if (ExpandMatrixF(&ctrl) != 0)
exit(0);
// Process for each Eb/No
for (i=0; i<ctrl.totalNumFrames; i++)
{
ctrl.numIter=0;
global_ber[i]=0;
global_fer[i]=0;
for (k=0; k<MAX_RETRANS; k++)
{
fer[i][k] = 0;
}
printf("The current Eb/No is %.2f ..\n", ctrl.Eb_No[i]);
for(j=0; j<ctrl.nFrames[i]; j++ )
{
printf(" %d \r",j);
// Generate a block of input data
if ((inputData = GenerateInputF(&ctrl)) == NULL)
exit(0);
for (k=0; k<=ctrl.maxRetrans; k++)
{
//Encode the data block
if ((encodeOut = EncodingF(&ctrl,inputData,k)) == NULL)
exit(0);
//Modulate the encoded data
if ((moduOut = ModulatingF(&ctrl, encodeOut,k)) == NULL)
exit(0);
delete [] encodeOut;
// undergo the AWGN channel
if ((ChanAwgnF(&ctrl, moduOut, ctrl.Eb_No[i])) != 0)
exit(0);
//Demodulate
if((demoduOut = DemodulatingF(&ctrl, moduOut, ctrl.Eb_No[i])) == NULL)
exit(0);
delete [] moduOut;
//Decoding
if (k==0)
{
if(DecodingF(&ctrl,demoduOut)==0)
break;
else
{
if((demoduOut1=Updating1F(&ctrl, demoduOut)) == NULL) //demoduOut1作为下一次译码的完整信息
exit(0);
delete [] demoduOut;
fer[i][k] ++;
// continue;
}
}
else
{
//更新第一级译码所需似然比信息
if((demoduOut2=Updating2F(&ctrl, demoduOut1, demoduOut, k)) == NULL)
exit(0);
delete [] demoduOut;
DecodingF(&ctrl, demoduOut2); //第一级译码
//更新第二级译码所需似然比信息
if ((demoduOut=UpdatingF(&ctrl, demoduOut1, demoduOut2, k)) == NULL )
exit(0);
delete [] demoduOut2;
delete [] demoduOut1;
m = DecodingF(&ctrl,demoduOut); //第二级译码
if(m==0) //译码成功则跳出
break;
else //译码不成功
{
fer[i][k] ++;
if (k==ctrl.maxRetrans) //达到最大重传次数也跳出
break;
if((demoduOut1=Updating1F(&ctrl, demoduOut)) == NULL) //更新似然信息
exit(0);
delete [] demoduOut;
}
}
}
//Dicision
if ((decodeOut = DecidingF(&ctrl, demoduOut)) == NULL)
exit(0);
delete [] demoduOut;
// Count the error bits
if ((local_ber = CountBerF(&ctrl, inputData, decodeOut)) < 0)
exit(0);
delete [] inputData;
delete [] decodeOut;
global_ber[i] += local_ber;
if (local_ber > 0)
global_fer[i]++;
}
ctrl.numIter /= ctrl.nFrames[i];
global_ber[i] /= ctrl.nFrames[i];
global_fer[i] /= ctrl.nFrames[i];
for (k=0; k<MAX_RETRANS; k++)
fer[i][k] /= ctrl.nFrames[i];
f=0;
// for (k=0; k<MAX_RETRANS; k++)
// l[k] = 0;
// l[0] = fer[i][0];
// for (k=0; k<MAX_RETRANS; k++)
// l[k] = l[k-1]*fer[i][k];
for (k=0; k<MAX_RETRANS; k++)
// f += l[k];
f += fer[i][k];
global_throughPut[i] = ctrl.codeK*(1-global_fer[i])/(ctrl.codeN+f*ctrl.codeM);
if (ExportOutputF(&ctrl,global_ber[i],global_fer[i],global_throughPut[i],ctrl.Eb_No[i]) != 0)
exit(0);
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -