📄 main.cpp
字号:
#include "parameter_sets.h"
///////////////////////////////////////////////////////////////////////////////
// Release 0.1
// Build the initial program
///////////////////////////////////////////////////////////////////////////////
// Release 0.2
// Added a flag to identify the debugging mode and running mode
// Added an item to initialize the maximum time of iteration of decoding
// Added output for each Eb/No to assist to estimate the elapsed time
///////////////////////////////////////////////////////////////////////////////
// Release 0.3
// Added Log-BP algorithm
// Added Min-Sum algorithm
///////////////////////////////////////////////////////////////////////////////
// Release 0.4
// Made the interface more friendly
// Added a flag to choose Eb/No or SNR used in simulations
// Added the statistics of FER
// Added QPSK and 16QAM
///////////////////////////////////////////////////////////////////////////////
// Release 0.5
// Added 64QAM
///////////////////////////////////////////////////////////////////////////////
// Release 0.6
// Added a block to perform the soft de-modulation
// Added LTE R1-061019 Structured LDPC coding by ZTE
///////////////////////////////////////////////////////////////////////////////
// Release 0.7
// Added LTE R1-060910 type A rate-compatible LDPC codes by Mistubishi
// Changed the number of frames per Eb/No
///////////////////////////////////////////////////////////////////////////////
const int MAX_Eb_No = 20;
const char version[10] = "0.7";
const int PuncPos[15] = {17, 19, 21, 23, 25, 27, 29, 31, 18, 24, 22, 28, 30, 20, 26};
const double sqrt2norm[4] = {1.0, 1.414213562373095, 3.16227766016838, 6.48074069840786};
// {sqrt(1), sqrt(2), sqrt(10), sqrt(42)}, derived from Matlab 2006R
const double sqrt2 = 1.414213562373095; //From Matlab 2006R
const Complex constMap_bpsk[2] = {{1.0, 0}, {-1.0, 0}};
int main()
{
// Declaration
int i, j;
int * inputData, * encodeOut, * decodeOut, * harqOut;
struct Complex * moduOut, * chanOut;
double * demodOut;
double E,local_ber, local_ber1, local_ber2, n1, n2 ;
double global_ber[MAX_Eb_No], global_fer[MAX_Eb_No];
double global_ber1[MAX_Eb_No], global_fer1[MAX_Eb_No];
double global_ber2[MAX_Eb_No], global_fer2[MAX_Eb_No];
int local_iter,global_iter[MAX_Eb_No];
double global_throughPut[MAX_Eb_No];
double global_numOper[MAX_Eb_No];
struct BasicParaS ctrl;
for (i=0; i<79; i++)
printf("*");
printf("\n** The LDPC 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(EXIT_FAILURE);
// Loading the basic check matrix H
if (LoadBasicMatrixF(&ctrl) != 0)
exit(EXIT_FAILURE);
// Expand the basic matrix to the actual check matrix Hp
if (ExpandMatrixF(&ctrl) != 0)
exit(EXIT_FAILURE);
E = CountEF(&ctrl);
// Process for each Eb/No
for (i=0; i<ctrl.totalNumFrames; i++)
{
global_ber[i] = 0;
global_fer[i] = 0;
global_ber1[i] = 0;
global_fer1[i] = 0;
global_ber2[i] = 0;
global_fer2[i] = 0;
global_numOper[i]=0;
printf("The current Eb/No is %.2f ..\n", ctrl.Eb_No[i]);
local_iter = 0;
for (j=0; j<ctrl.numFrames[i]; j++)
{
// Generate a block of input data
if ((inputData = GenerateInputF(&ctrl)) == NULL)
exit(EXIT_FAILURE);
// Encode the data block
if ((encodeOut = EncodingF(&ctrl, inputData)) == NULL)
exit(EXIT_FAILURE);
// Modulate the encoded data block
if ((moduOut = ModulatingF(&ctrl, encodeOut,ctrl.codeN)) == NULL)
exit(EXIT_FAILURE);
delete [] encodeOut;
// undergo the AWGN channel
if ((chanOut = ChanAwgnF(&ctrl, moduOut, ctrl.Eb_No[i])) == NULL)
exit(EXIT_FAILURE);
// Soft De-modulation
if ((demodOut = DemodulatingF(&ctrl, chanOut, ctrl.Eb_No[i])) == NULL)
exit(EXIT_FAILURE);
delete [] chanOut;
// Decode the data block
if ((decodeOut = DecodingF(&ctrl, demodOut)) == NULL)
exit(EXIT_FAILURE);
printf("\n");
printf("When the frame number is %d\n", j);
local_ber = 0;
local_ber1 = 0;
local_ber2 = 0;
if ((local_ber = CountBerF(&ctrl, inputData, decodeOut)) < 0)
exit(EXIT_FAILURE);
printf("the BER is %E\n", local_ber);
//重传
if(local_ber>0)
{
if ((harqOut = HarqF(&ctrl,inputData , demodOut, ctrl.Eb_No[i]))== NULL)
exit(EXIT_FAILURE);
local_ber1 = ctrl.ber1;
local_ber2 = CountBerF(&ctrl, inputData, harqOut);
delete [] harqOut;
}
delete [] inputData;
delete [] demodOut;
delete [] decodeOut;
global_ber[i] += local_ber; //未重传的ber和fer
if (local_ber > 0)
global_fer[i]++;
global_ber1[i] += local_ber1; //未重传的ber和fer
if (local_ber1 > 0)
global_fer1[i]++;
global_ber2[i] += local_ber2; //重传两次后的BER和FER
if (local_ber2 > 0)
global_fer2[i]++;
local_iter += ctrl.numIter;
global_iter [i] = local_iter;
// printf("local_iter= %2d\n", local_iter);
// printf("global_iter [i]= %2d\n", global_iter [i]);
ctrl.r = 4.0/3; //
ctrl.codeN = (int)(ctrl.r*ctrl.codeK); //重新计算N
ctrl.codeM = ctrl.codeN - ctrl.codeK; //重新计算M
}
global_ber[i] /= ctrl.numFrames[i];
global_fer[i] /= ctrl.numFrames[i];
global_ber1[i] /= ctrl.numFrames[i];
global_fer1[i] /= ctrl.numFrames[i];
global_ber2[i] /= ctrl.numFrames[i];
global_fer2[i] /= ctrl.numFrames[i];
global_iter [i] /= ctrl.numFrames[i]; //average number of i
// printf("global_iter [i]= %2d\n", global_iter [i]);
n1=(0.5 - (ctrl.r-1))*16*ctrl.zfactor; //count p2
n2=(2-1.5)*16*ctrl.zfactor; //count p3
global_throughPut[i]=ctrl.codeK*(1-global_fer2[i])/(ctrl.codeN +global_fer[i]*n1 +global_fer1[i]*global_fer[i]*n2);
global_numOper[i]=global_iter[i]*(2*ctrl.codeK+ 6*ctrl.zfactor*E)/(global_throughPut[i]*ctrl.codeK);
}
// Export the BER of each point
if (ExportBerF(&ctrl, global_ber, global_ber1, global_ber2) != 0)
exit(EXIT_FAILURE);
// Export the FER of each point
if (ExportFerF(&ctrl, global_fer, global_fer1, global_fer2) != 0)
exit(EXIT_FAILURE);
// Export the througput and the average number of operations of each point
if (ExportOutputF(&ctrl, global_throughPut,global_numOper) !=0)
exit(EXIT_FAILURE);
printf("\nThe simulation is completed successfully!\n");
for (i=0; i<79; i++)
printf("*");
printf("\n");
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -