【文件属性】:
文件名称:信道容量迭代.docx
文件大小:15KB
文件格式:DOCX
更新时间:2022-07-06 04:35:01
c/c++
信道容量迭代# include
#include
#include
//#include
//#include
# define delta 1e-6
#define MAXFLOAT 3.4e+38
int main(void)
{
register int i,j;
register int k;
int r,s;
float *p_i=NULL;
float ** p_ij=NULL;
float ** phi_ji=NULL;
float c,c_pre,validate;
float *sum=NULL;
float p_j;
printf("请输入信源的符号数:");
fscanf (stdin,"%d",&r);
printf("\n");
printf("请输入信宿的符号数:");
fscanf(stdin,"%d",&s);
printf("\n");
p_i=(float *)calloc (r,sizeof (float));
p_ij=(float **)calloc(r,sizeof (float));
for (i=0;idelta)
{
fprintf(stdout,"输入数据不正确.\n");
exit(-1);
}
}
fprintf(stdout,"开始迭代…\n");
for (i=0;i=delta)
for(i=0;i=delta)
sum[i]+=p_ij[i][j]*(log(phi_ji[i][j])/log(2.0))/ 1.0;
}
sum[i]=pow(2.0,(double)sum[i]);
p_j+=sum[i];
}
for(i=0;idelta);
free(sum);
sum=NULL;
printf("迭代次数是%d.\n\n",k);
printf("信道容量C是%.6f 比特/符号.\n\n",c);
printf("最佳输入分布是:\n");
for(i=0;i=0;i--)
{
free(phi_ji[i]);
phi_ji[i]=NULL;
}
free(phi_ji);
phi_ji=NULL;
for(i=r-1;i>-0;i--)
{
free(p_ij[i]);
p_ij[i]=NULL;
}
free(p_ij);
p_ij=NULL;
free(p_i);
p_i=NULL;
return 1;
}