📄 init_system.cpp
字号:
}
fscanf(fpQ,"%d %d",&i,&j); //max_row_wt and max_col_wt
int *row_wt_profile; //row weight distribution
row_wt_profile = (int*)calloc(sys_spt.check_bits,sizeof(int));
int numOfOneInQ; //number of element "1" in Q matrix
for (i=0,numOfOneInQ=0;i<sys_spt.check_bits;i++) //Q_matrix :[check_bits*message_bits]
{
fscanf(fpQ,"%d",&row_wt_profile[i]);
numOfOneInQ += row_wt_profile[i]; //count the number of "1"elments in Q matrix
}
//memory allocation for saving the G sparse matrix in the order of column
sys_spt.G_sp_col=(int *)calloc((numOfOneInQ+sys_spt.message_bits)*3,sizeof(int));
if (sys_spt.G_sp_col==NULL)
{
printf("Insufficient memory available for sys_spt.G_sp_col");
}
for (i=0;i<sys_spt.message_bits;i++)
{
fscanf(fpQ,"%d",&k); //col_wt_profile
}
for (i=0,x=0;i<sys_spt.check_bits;i++)
{
for (j=0;j<row_wt_profile[i];j++)
{
fscanf(fpQ,"%d",&k);
sys_spt.G_sp_col[3*x] = k; //col
sys_spt.G_sp_col[3*x+1] = i+1; //row
sys_spt.G_sp_col[3*x+2] = 1;
x++;
}
}
j = sys_spt.col_num-sys_spt.message_bits;
for(i=0,k=0;i<sys_spt.message_bits;i++)
{
sys_spt.G_sp_col[3*x] = k+1;
sys_spt.G_sp_col[3*x+1] = j+1;
sys_spt.G_sp_col[3*x+2] = 1;
k++;
j++;
x++;
}
fclose(fpQ);
free(row_wt_profile);
//memory allocation for message_location
sys_spt.message_locations=(int *)calloc(sys_spt.col_num,sizeof(int));
if (sys_spt.message_locations==NULL)
{
printf("Insufficient memory available for sys_spt.message_locations");
}
//read message_location from file
for (i=0;i<sys_spt.col_num;i++){
sys_spt.message_locations[i] = 1;
}
FILE *fporder;
fporder = fopen(ORDER_FILE,"r");
if (fporder==NULL)
{
printf("ORDER_FILE does not exist!!Check the file!\n");
exit(0);
}
for (i=0;i<(sys_spt.col_num-sys_spt.message_bits);i++){
fscanf(fporder,"%d",&j);
sys_spt.message_locations[j] = 0;
}
fclose(fporder);
}
void Init_system(){
int i;
Read_H_asc();
Read_G();
sys_spt.code_rate = (double)sys_spt.message_bits/sys_spt.col_num;
//-------------------------------------for encode
sys_spt.source_bits = (int *)calloc(sys_spt.message_bits+2000,sizeof(int));
if (sys_spt.source_bits==NULL)
{
printf("Insufficient memory for source bit!!!");
}
sys_spt.source_code = (int *)calloc(sys_spt.col_num+2000,sizeof(int));
if (sys_spt.source_code==NULL)
{
printf("Insufficient memory for source code!!!");
}
sys_spt.source_bits_in = (int *)calloc(sys_spt.message_bits+2000,sizeof(int));
if (sys_spt.source_bits_in==NULL)
{
printf("Insufficient memory for source bits out!!!");
}
sys_spt.source_bits_out = (int *)calloc(sys_spt.message_bits+2000,sizeof(int));
if (sys_spt.source_bits_out==NULL)
{
printf("Insufficient memory for source bits out!!!");
}
sys_spt.received = (int *)calloc(sys_spt.col_num+2000,sizeof(int));
sys_spt.send_code = (int *)calloc(sys_spt.col_num+2000,sizeof(int));
if (sys_spt.send_code==NULL)
{
printf("Insufficient memory for send code!!!");
}
sys_spt.rece_code = (int *)calloc(sys_spt.col_num+2000,sizeof(int));
if (sys_spt.rece_code==NULL)
{
printf("Insufficient memory for rece code!!!");
}
//-------------------------------------for decoding
//allcate memory for bit_nodes.llr
sys_spt.bit_nodes.llr = (double **)calloc(sys_spt.col_num+2000,sizeof(double*));
if (sys_spt.bit_nodes.llr==NULL)
{
printf("Insufficient memory available for sys_spt.bit_nodes.llr");
}
for (i=0;i<sys_spt.col_num;i++)
{
sys_spt.bit_nodes.llr[i] = (double *)calloc(sys_spt.bit_nodes.size[i]+10,sizeof(double));
if (sys_spt.bit_nodes.llr[i]==NULL)
{
printf("Insufficient memory available for sys_spt.bit_nodes.llr[i]");
}
}
//allcate memory for bit_nodes.llr_sign
sys_spt.bit_nodes.llr_sign = (int **)calloc(sys_spt.col_num+2000,sizeof(int*));
if (sys_spt.bit_nodes.llr_sign==NULL)
{
printf("Insufficient memory available for sys_spt.bit_nodes.llr_sign");
}
for (i=0;i<sys_spt.col_num;i++)
{
sys_spt.bit_nodes.llr_sign[i] = (int *)calloc(sys_spt.bit_nodes.size[i]+10,sizeof(int));
if (sys_spt.bit_nodes.llr_sign[i]==NULL)
{
printf("Insufficient memory available for sys_spt.bit_nodes.llr_sign[i]");
}
}
sys_spt.check_nodes.llr_sign = (int *)calloc(sys_spt.row_num+2000,sizeof(int));
if (sys_spt.check_nodes.llr_sign==NULL)
{
printf("Insufficient memory available for sys_spt.check_nodes.llr_sign");
}
//allcate memory for bit_nodes.llr_sum
sys_spt.bit_nodes.llr_sum = (double *)calloc(sys_spt.col_num+2000,sizeof(double));
if (sys_spt.bit_nodes.llr_sum==NULL)
{
printf("Insufficient memory available for sys_spt.bit_nodes.llr_sum");
}
//allcate memory for bit_nodes.llr_out
sys_spt.bit_nodes.llr_out = (double *)calloc(sys_spt.col_num+2000,sizeof(int));
if (sys_spt.bit_nodes.llr_out==NULL)
{
printf("Insufficient memory available for sys_spt.bit_nodes.llr_out");
}
sys_spt.bit_nodes.llr_in = (int *)calloc(sys_spt.col_num+2000,sizeof(int));
if (sys_spt.bit_nodes.llr_in==NULL)
{
printf("Insufficient memory available for sys_spt.bit_nodes.llr_out");
}
sys_spt.check_nodes.llr = (double *)calloc(sys_spt.row_num+2000,sizeof(double));
if (sys_spt.check_nodes.llr==NULL)
{
printf("Insufficient memory for check_nodes.llr!!!");
}
sys_spt.llr_init = (double *)calloc(sys_spt.col_num+2000,sizeof(double)); //llr from channel
if (sys_spt.llr_init==NULL)
{
printf("Insufficient memory for llr_init!!!");
}
//--------------------allocate memory for min-sum iteration function
sys_spt.check_nodes.llr_sub_min = (double *)calloc(sys_spt.row_num+2000,sizeof(double));
if (sys_spt.check_nodes.llr_sub_min==NULL)
{
printf("Insufficient memory for check_nodes.llr_sub_min!!!");
}
sys_spt.check_nodes.llr_sub_min2 = (double *)calloc(sys_spt.row_num+2000,sizeof(double));
if (sys_spt.check_nodes.llr_sub_min2==NULL)
{
printf("Insufficient memory for check_nodes.llr_sub_min2!!!");
}
sys_spt.check_nodes.llr_min = (double *)calloc(sys_spt.row_num+2000,sizeof(double));
if (sys_spt.check_nodes.llr_min==NULL)
{
printf("Insufficient memory for check_nodes.llr_min!!!");
}
//-------------------------------------for channel paramter declaration
sys_spt.EbNo = 0.;
sys_spt.EbNo_start = Eb_N0_START;
sys_spt.EbNo_end = Eb_N0_END;
sys_spt.EbNo_step = Eb_N0_STEP;
//-------------------------------------for simulation end condition
sys_spt.iter_times = NUM_ITER;
sys_spt.max_block = MAX_SIM_BLOCK;
sys_spt.min_block = MIN_SIM_BLOCK;
sys_spt.max_error_bits = MAX_ERROR_BITS;
sys_spt.target_ber = TARGET_BER;
//-------------------------------------for statistic
sys_spt.run_time = 0;
sys_spt.bit_error = 0;
sys_spt.block_error = 0;
sys_spt.hard_error = 0;
sys_spt.undetected_bit_error = 0;
sys_spt.undetected_block_error = 0;
sys_spt.max_iterations = 0;
sys_spt.min_iterations = sys_spt.iter_times;
sys_spt.aver_iterations = 0.;
sys_spt.ber = 0.;
sys_spt.bler = 0.;
sys_spt.undet_ber = 0.;
sys_spt.undet_bler = 0.;
sys_spt.hard_ber = 0.;
sys_spt.ber_iter = (double *)calloc(sys_spt.iter_times,sizeof(double));
if (sys_spt.ber_iter==NULL)
{
printf("No sufficient memory for sys_spt.ber_iter!!!");
}
sys_spt.error_iter = (int *)calloc(sys_spt.iter_times,sizeof(int));
if (sys_spt.error_iter==NULL)
{
printf("No sufficient memory for sys_spt.error_iter!!!");
}
//-------------------------------------for print file
/* fprintf(sys_spt.fp_result,"************************************\n");
fprintf(sys_spt.fp_result,"* LDPC CODE PARAMETERS: *\n");
fprintf(sys_spt.fp_result,"* col_num = %4d *\n",sys_spt.col_num);
fprintf(sys_spt.fp_result,"* row_num = %4d *\n",sys_spt.row_num);
fprintf(sys_spt.fp_result,"* max_col_wt = %4d *\n",sys_spt.max_col_wt);
fprintf(sys_spt.fp_result,"* max_row_wt = %4d *\n",sys_spt.max_row_wt);
fprintf(sys_spt.fp_result,"* iteration = %4d *\n",sys_spt.iter_times);
fprintf(sys_spt.fp_result,"* code rate = %1.6f *\n",sys_spt.code_rate);
fprintf(sys_spt.fp_result,"************************************\n");
time(&sys_spt.timenow);
fprintf(sys_spt.fp_result, "Simulation start : %s\n", ctime(&sys_spt.timenow));
fclose(sys_spt.fp_result);
*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -