?? ldpc_main.cpp
字號(hào):
#include "LDPC_head.h"
unsigned int test_num=10000;
double ber=0;
double error_bit=0; //the number of error bits
long now;
matrix_bit *get_matrix();
//matrix_bit *Gen(unsigned int M, unsigned int N, unsigned int t);
unsigned int test(struct matrix_bit *matrix);
node *space(struct matrix_bit *matrix);
code *encode(struct matrix_bit *matrix, unsigned int *message);
code *Gaussian_channel(code *codewordsk,double n0);
unsigned int decode(struct code *codewords,struct matrix_bit *matrix,struct node *head1, unsigned int *message,double n0);
void main()
{
unsigned int i;
unsigned int j;
unsigned int noise;
unsigned int num; //the number of tested codewords
unsigned int success=0; //decoding judge symbol
unsigned int k=0;
double N0; //the SNR
double n0; //the power spectral density
struct matrix_bit *matrix;
struct node *head;
unsigned int *message;
code *codewords;
int error; //the number of error codewords
FILE *fp;
//get the matrix from file "matrix.txt"
cout<<"get the matrix......."<<endl;
matrix=get_matrix();
//generate the double circle link
cout<<"appling for the corresponding space......"<<endl;
head=space(matrix);
i=test(matrix);
if(i)
{
cout<<"matrix error!"<<endl;
}
srand(time(&now));
cout<<"starting simulation....."<<endl;
fp=fopen("result.txt","w+");
message=(unsigned int *) malloc ((sizeof(unsigned int))*matrix->M1);
for(noise=8;noise<=12;noise++)
{
N0=0.25*noise;//here N0 denotes Eb/N0(dB)
n0=pow(10,-(double)N0/10)*matrix->N/matrix->M1;//the noise power spectral density (symbol power equal 1)
ber=0;
error_bit=0;
success=0;
error=0;
//for(num=0;num<test_num;num++)
for(num=0;num>=0;num++)
{
for(i=0;i<matrix->M1;i++)
{
message[i]=rand()%2;//generate the message bits
}
codewords=encode(matrix,message);
codewords=Gaussian_channel(codewords,n0);
j=0;
j=decode(codewords,matrix,head,message,n0);
if(j==0)
{
success++;
}
else
{
error++;
}
error_bit+=j;
ber=error_bit/(double)((num+1)*matrix->M1);
if((num+1)%50==0)
{
cout<<"N0="<<N0<<" num="<<num+1<<" success="<<success<<" error_bit="<<error_bit<<" error_code="<<error<<" ber="<<ber<<endl;
}
free(codewords->codeword);
free(codewords);
if(((error>1000)&&(num>test_num))||(num>10*test_num))
{
break;
}
}
fprintf(fp,"N0=%f num=%d ber=%f\n",N0,num,ber);
}
free(message);
free(matrix->G);
free(matrix->H);
free(matrix);
free(head);
fclose(fp);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -