在运行程序是出现Unhandled exception at 0x00194B81 in LDPC_main.exe。。。的错诶

问题描述

一个对于LDPC码子译码的程序,在运行时出现了Unhandledexceptionat0x00194B81inLDPC_main.exe:0xC0000005:Accessviolationreadinglocation0x00000014.的错误,请哪位大神指导一下,要怎么修改!!!main函数:#include"LDPC_head.h"unsignedinttest_num=10000;doubleber=0;doubleerror_bit=0;//thenumberoferrorbitslongnow;matrix_bit*get_matrix();//matrix_bit*Gen(unsignedintM,unsignedintN,unsignedintt);unsignedinttest(structmatrix_bit*matrix);node*space(structmatrix_bit*matrix);code*encode(structmatrix_bit*matrix,unsignedint*message);code*Gaussian_channel(code*codewordsk,doublen0);unsignedintdecode(structcode*codewords,structmatrix_bit*matrix,structnode*head1,unsignedint*message,doublen0);voidmain(){unsignedinti;unsignedintj;unsignedintnoise;unsignedintnum;//thenumberoftestedcodewordsunsignedintsuccess=0;//decodingjudgesymbolunsignedintk=0;doubleN0;//theSNR信噪比doublen0;//thepowerspectraldensity功率谱密度structmatrix_bit*matrix;structnode*head;unsignedint*message;code*codewords;interror;//thenumberoferrorcodewordsFILE*fp;//getthematrixfromfile"matrix.txt"cout<<"getthematrix......."<<endl;matrix=get_matrix();//generatethedoublecirclelinkcout<<"applingforthecorrespondingspace......"<<endl;head=space(matrix);i=test(matrix);if(i){cout<<"matrixerror!"<<endl;}structtm*date_tm;time_tTime1;srand(time(&Time1));cout<<"startingsimulation....."<<endl;fp=fopen("result.txt","w+");message=(unsignedint*)malloc((sizeof(unsignedint))*matrix->M1);for(noise=32;noise<=32;noise++){N0=0.25*noise;//hereN0denotesEb/N0(dB)n0=pow(10,-(double)N0/10)*7/4;//*matrix->N/matrix->M1;//thenoisepowerspectraldensity(symbolpowerequal1)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]=0;//generatethemessagebits}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>1000*test_num)){break;}}fprintf(fp,"N0=%fnum=%dber=%fn",N0,num,ber);}free(message);free(matrix->G);free(matrix->H);free(matrix);free(head);fclose(fp);}读取H矩阵和G矩阵的函数:#include"LDPC_head.h"#include<stdlib.h>#include<iostream>usingnamespacestd;matrix_bit*get_matrix(){matrix_bit*matrix;unsignedinti;unsignedintj;FILE*fp;matrix=(structmatrix_bit*)malloc(sizeof(structmatrix_bit));//建立一个指向该结构体的指针fp=fopen("matrix2.txt","r");if(fp==NULL){cout<<"can'topenthefile!"<<endl;exit(0);}else{fscanf(fp,"%dn",&(matrix->N));//1008fscanf(fp,"%dn",&(matrix->M1));//504fscanf(fp,"%dn",&(matrix->M));//504fscanf(fp,"%dn",&(matrix->G_mcw));//281fscanf(fp,"%dn",&(matrix->H_mrw));//6//getG,N*G_mcwmatrix->G=(unsignedint*)malloc((sizeof(unsignedint))*matrix->N*matrix->G_mcw);for(i=0;i<matrix->N*matrix->G_mcw;i++)//i<1008*281{matrix->G[i]=0;}for(i=0;i<matrix->G_mcw;i++){for(j=0;j<matrix->N;j++){fscanf(fp,"%dn",&(matrix->G[i*matrix->N+j]));}}//getHmatrix->H=(unsignedint*)malloc((sizeof(unsignedint))*matrix->H_mrw*matrix->M);for(i=0;i<matrix->H_mrw*matrix->M;i++){matrix->H[i]=0;}for(i=0;i<matrix->M;i++){for(j=0;j<matrix->H_mrw;j++){fscanf(fp,"%dn",&(matrix->H[i*matrix->H_mrw+j]));}}//for(intpp=0;pp<50;pp++)//std::cout<<pp<<""<<matrix->H[pp]<<"n";fclose(fp);}return(matrix);}构造节点的函数,问题是出在这里的:#include"LDPC_head.h"#include<stdlib.h>node*space(structmatrix_bit*matrix){node*head;node*p1;node*p2;unsignedinti;unsignedintj;//unsignedintk;head=(structnode*)malloc(sizeof(structnode));head->row=-1;head->col=-1;head->left=NULL;head->right=NULL;head->up=NULL;head->down=NULL;head->Q=0;head->R=0;//分配行骨架节点head->right=(structnode*)malloc((sizeof(structnode))*matrix->N);for(i=0;i<matrix->N;i++){p1=head->right+i;p1->row=-1;p1->col=i;p1->up=NULL;p1->down=NULL;p1->Q=0;p1->R=0;if(i==0){p1->left=head;}else{p1->left=p1-1;}if(i==matrix->N-1){p1->right=head;}else{p1->right=p1+1;}}head->left=head->right+matrix->N-1;//分配列骨架节点head->down=(structnode*)malloc((sizeof(structnode))*matrix->M);for(i=0;i<matrix->M;i++){p1=head->down+i;p1->row=i;p1->col=-1;p1->left=NULL;p1->right=NULL;p1->Q=0;p1->R=0;if(i==0){p1->up=head;}else{p1->up=p1-1;}if(i==matrix->M-1){p1->down=head;}else{p1->down=p1+1;}}head->up=head->down+matrix->M-1;//构造体节点for(i=0;i<matrix->M;i++){for(j=0;j<matrix->H_mrw;j++){if(matrix->H[i*matrix->H_mrw+j]!=0){p1=(structnode*)malloc(sizeof(structnode));p1->row=i;p1->col=matrix->H[i*matrix->H_mrw+j]-1;p1->R=0;p1->Q=0;p2=head->right+matrix->H[i*matrix->H_mrw+j]-1;while(p2->down!=NULL){p2=p2->down;}p2->down=p1;p1->up=p2;p1->down=NULL;p2=head->down+i;while(p2->right!=NULL){p2=p2->right;}p2->right=p1;p1->left=p2;p1->right=NULL;}}}p1=head->right;for(i=0;i<matrix->N;i++){p2=p1->down;while(p2->down!=NULL)报错的时候显示的是这一行有问题{p2=p2->down;}p2->down=p1;p1->up=p2;p1++;}p1=head->down;for(i=0;i<matrix->M;i++){p2=p1->right;while(p2->right!=NULL){p2=p2->right;}p2->right=p1;p1->left=p2;p1++;}return(head);}译码函数:#include"LDPC_head.h"#include<stdlib.h>structcode*initializtion(structcode*codewords,doublen0);voidone_step(structmatrix_bit*matrix,structnode*head,structcode*f);doublebasic(doublex,doubley);structcode*judge(structnode*head,structcode*codewords,structcode*f);unsignedintdecode(structcode*codeword,structmatrix_bit*matrix,structnode*head1,unsignedint*message,doublen0){code*codewords;code*final_code;code*f;node*head;node*p1;//node*p2;unsignedinti;unsignedintj;unsignedintk;head=head1;codewords=codeword;//calculatetheLLRsofeverybitf=initializtion(codewords,n0);for(i=0;i<matrix->N;i++){p1=head->right+i;p1->Q=f->codeword[i];p1->R=0;p1=p1->down;while(p1->row!=-1){p1->Q=f->codeword[i];p1->R=0;p1=p1->down;}}for(i=0;i<iterative_num;i++){//cout<<i<<endl;one_step(matrix,head,f);//cout<<i<<endl;final_code=judge(head,codewords,f);j=0;for(k=0;k<matrix->M1;k++){if(message[k]!=(unsignedint)final_code->codeword[k]){j++;}}free(final_code->codeword);free(final_code);if(j==0){break;}}free(f->codeword);free(f);return(j);}//calculatetheLLRsofeverybitcode*initializtion(structcode*codewords,doublen0){unsignedinti;code*f;f=(structcode*)malloc(sizeof(structcode));f->length=codewords->length;f->codeword=(double*)malloc((sizeof(double))*f->length);for(i=0;i<f->length;i++){//whenLLRsdecodingf->codeword[i]=4*codewords->codeword[i]/n0;//whenLRsdecoding//f->codeword[i]=exp(-4*(codewords->codeword[i])/n0);}return(f);}doublebasic(doublex,doubley){//whenLLRsdecodingdoublez;z=log((1+exp(x+y))/(exp(x)+exp(y)));//overlow?if(z>MAX){z=MAX;}elseif(z<-MAX){z=-MAX;}returnz;//whenLRsdecoding/*doublez;z=(x+y)/(1+x*y);if(z>MAX)

解决方案

解决方案二:
编码函数:#include"LDPC_head.h"#include<stdlib.h>code*encode(structmatrix_bit*matrix,unsignedint*message){code*code1;unsignedinti;unsignedintj;unsignedintk;code1=(structcode*)malloc(sizeof(structcode));code1->length=matrix->N;code1->codeword=(double*)malloc((sizeof(double))*code1->length);for(i=0;i<code1->length;i++){k=0;for(j=0;j<matrix->G_mcw;j++){if(matrix->G[j*matrix->N+i]!=0){k+=message[matrix->G[j*matrix->N+i]-1];}}if(k%2==0){code1->codeword[i]=1;}else{code1->codeword[i]=-1;}}return(code1);}模拟高斯信道函数:#include"LDPC_head.h"#include<stdlib.h>code*Gaussian_channel(code*codewords,doublen0){unsignedinti;doubleu1,u0;doublegaussnoise;for(i=0;i<codewords->length;i++){u0=(double)rand()/(double)RAND_MAX;u1=(double)rand()/(double)RAND_MAX;if(u0<limit){u0=limit;}gaussnoise=sqrt(n0*log(1./u0))*cos(2*pi*u1);//gaussnoise=0;codewords->codeword[i]+=gaussnoise;}return(codewords);}生成矩阵函数:#include"LDPC_head.h"#include<stdlib.h>matrix_bit*Gen(unsignedintM,unsignedintN,unsignedintt){matrix_bit*Matrix;unsignedint*col;unsignedint*row;unsignedint*check;unsignedinti;unsignedintj;unsignedintk;unsignedintl;unsignedintrank;unsignedintretry;longnow;//applyforthecorespondingspaceMatrix=(structmatrix_bit*)malloc(sizeof(structmatrix_bit));Matrix->H_mrw=M;Matrix->G_mcw=N;Matrix->H=(unsignedint*)malloc(sizeof(unsignedint)*(N-M)*N);Matrix->G=(unsignedint*)malloc(sizeof(unsignedint)*M*N);for(j=0;j<N;j++){for(i=0;i<M;i++){Matrix->G[i*N+j]=0;}}col=(unsignedint*)malloc((sizeof(unsignedint))*N);for(i=0;i<N;i++){col[i]=0;}row=(unsignedint*)malloc((sizeof(unsignedint))*N);//generatetheHatrandomloop1:for(j=0;j<N;j++){for(i=0;i<N-M;i++){Matrix->H[i*N+j]=0;}}for(i=0;i<N-M;i++){row[i]=0;}retry=0;structtm*date_tm;time_tTime1;srand(time(&Time1));for(j=0;j<N;j++){for(k=0;k<t;k++){i=rand()%(N-M);if((Matrix->H[i*N+j]==0)&&(row[i]<(double)(t*N/(N-M)))){Matrix->H[i*N+j]=1;row[i]++;}else{k--;retry++;if(retry>N*(N-M)){gotoloop1;}}}}//checkifHisfullrankcheck=(unsignedint*)malloc((sizeof(unsignedint))*(N-M)*N);for(i=0;i<N-M;i++){for(j=0;j<N;j++){check[i*N+j]=Matrix->H[i*N+j];//cout<<check[i*N+j]<<"";}//cout<<endl;}//changeHintouppertriangleformwhenchecktherankofHrank=0;for(j=0;j<N;j++){for(i=rank;i<N-M;i++){if(check[i*N+j]==1){//cout<<"("<<rank<<","<<j<<")"<<endl;for(k=0;k<N;k++){col[k]=check[i*N+k];check[i*N+k]=check[rank*N+k];check[rank*N+k]=col[k];}for(k=i+1;k<N-M;k++){if(check[k*N+j]==1){for(l=j;l<N;l++){check[k*N+l]^=check[rank*N+l];}}}rank++;/*for(k=0;k<N-M;k++){for(l=0;l<N;l++){cout<<check[k*N+l]<<"";}cout<<endl;}*/break;}}}/*cout<<"arranged!-------"<<endl;for(i=0;i<N-M;i++){for(j=0;j<N;j++){cout<<check[i*N+j]<<"";}cout<<endl;}*///cout<<rank<<endl;if(rank!=N-M){//cout<<"notfullrank"<<endl;//getchar();gotoloop1;}//re-arrangeHmatrix//exchangethecolumnsofHtochangeHintostandarduppertriangleformfor(i=0;i<N-M;i++){j=i;while(check[i*N+j]==0){j++;}if(j>=N){cout<<j<<"Error!"<<endl;getchar();}if(i!=j){for(k=0;k<N-M;k++){row[k]=Matrix->H[k*N+i];Matrix->H[k*N+i]=Matrix->H[k*N+j];Matrix->H[k*N+j]=row[k];row[k]=check[k*N+i];check[k*N+i]=check[k*N+j];check[k*N+j]=row[k];}}}//changeHintounitmatrix+Pmatrixformfor(j=0;j<N-M;j++){for(i=0;i<j;i++){if(check[i*N+j]==1){for(k=0;k<N;k++){check[i*N+k]^=check[j*N+k];}}}}//checkifthereisall-zerocolumninitfor(j=N-M;j<N;j++){k=1;for(i=0;i<N-M;i++){if(check[i*N+j]==1){k=0;break;}}}if(k){gotoloop1;}//generateGfor(i=0;i<N-M;i++){for(j=N-M;j<N;j++){Matrix->G[(j-(N-M))*N+i+M]=check[i*N+j];}}for(i=0;i<M;i++){Matrix->G[i*N+i]=1;}//rearrangeHintostandardformfor(i=0;i<N-M;i++){for(j=0;j<N;j++){check[i*N+j]=Matrix->H[i*N+j];}}for(i=0;i<N-M;i++){for(j=0;j<N;j++){Matrix->H[i*N+j]=check[i*N+(j+M)%N];}}return(Matrix);}然后这个是我输入进去的矩阵:54183612111111111111111111111111111111111111111111111111111111123456789101112131415161718123456789101112131415161718123456789101112131415161718192021222324252627282930313233343536271920212223242526353628293031323334313233343536282930192021222324252627

时间: 2024-10-05 16:52:45

在运行程序是出现Unhandled exception at 0x00194B81 in LDPC_main.exe。。。的错诶的相关文章

Unhandled exception at 0x........ in XXXX.exe: 0xC0000005:Access violation reading location 0x......

Unhandled exception at 0x........ in XXXX.exe: 0xC0000005:Access violation reading location 0x...... 对于C++初学者或粗心者,很容易犯如下图所示错误: 那么该错误是由什么造成的呢? 答案无疑只有一个,即:读取了本该没有的值或者地址. 那么如何解决呢? 第一件事,检查下你传入的参数是否合法: 第二件事,若malloc了一块内存,必须记得free: 第三件事,你是否赋值了已经溢出的值或地址. 举例说

Solve Error: Unhandled exception at 0x00905a4d in xxx.exe: 0xC0000005: Access violation.

在使用Visual Studio进行项目开发的时候,有时候会遇到下面这个错误: Unhandled exception at 0x00905a4d in xxx.exe: 0xC0000005: Access violation 产生这个错误的原因可能是在Visual Studio中链接了后缀为"*.a"的库文件,这种库文件应该是在Linux系统或者是使用MinGW编译时链接的,用VS的话应该链接"*.lib"的库文件,而下载的第三方库中一般会包含"*.d

vs2010-调试没错,运行就有错了。。Unhandled exception at 0x10002c64

问题描述 调试没错,运行就有错了..Unhandled exception at 0x10002c64 调试没错,运行就有错了..Unhandled exception at 0x10002c64 in DIPAX.exe: 0xC0000005: Access violation writing location 0x00000000. 头文件:#pragma once // CMixDlg dialog class CMixDlg : public CDialogEx{ DECLARE_DY

exception-deiphi7程序关闭时 显示Exception EAccessViolation。。

问题描述 deiphi7程序关闭时 显示Exception EAccessViolation.. deiphi7程序关闭时 显示Exception EAccessViolation in module spxs.exe at 00100674 解决方案 这很难说,比如说你有什么东西没有释放 解决方案二: 或者你对消息循环挂钩(Hook),但是退出的时候没有还原,但是你的对象已经销毁,等等. 还有文件系统.com对象等等. 解决方案三: 你应该用调试方式运行程序,或者把delphi注册为调试器,然

myeclipse tomcat6.0在运行程序时报错,错误如下,请大神帮帮忙

问题描述 myeclipse tomcat6.0在运行程序时报错,错误如下,请大神帮帮忙 HTTP Status 500 - type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception org.apache.jasper.JasperException: javax.se

hadoop字啊运行程序出现错误,求大神指点,谢谢了

问题描述 hadoop字啊运行程序出现错误,求大神指点,谢谢了 [hadoop@Master hadoop]$ bin/hadoop jar wikipedia-miner-hadoop.jar org.wikipedia.miner.extraction.DumpExtractor input/enwiki-20130503-pages-articles.xml input/languages.xml en input/en-sent.bin output13/11/01 15:20:37 I

安卓 eclipse tomcat-在Eclipse 安卓虚拟机中运行程序时,原来可以运行,现在却突然终止?

问题描述 在Eclipse 安卓虚拟机中运行程序时,原来可以运行,现在却突然终止? 在Eclipse 安卓虚拟机中运行程序时,原来可以运行,现在却突然终止,看到控制台出现空指针的报错,是什么原因 如:FATAL EXCEPTION:MAIN 解决方案 这点信息恐怕不够.提供几个解决方案 1.你有layout文件夹下有main.xml么?位置有没有放对? 2.activity里有没有用setContentView(R.layout.main)去访问你的main.xml? 3.AndroidMani

tomcat-myeclipse Tomcat7.0运行程序报错,起初是没有问题的

问题描述 myeclipse Tomcat7.0运行程序报错,起初是没有问题的 上周出现的问题,百度不到解决办法,重装了myeclipse,并且换了一个tomcat,不知怎么的突然能运行了,现在一看,又报相同的错 解决方案 java.lang.NoClassDefFoundError: Could not initialize class org.springframework.beans.factory.BeanCreationException at org.springframework.

mfc sql ado-MFC 运行程序遇到abnormal program termination,可能连接数据库有问题

问题描述 MFC 运行程序遇到abnormal program termination,可能连接数据库有问题 C++6.0用ADO连接SQL,编译没问题,运行有错误,现在实现登录然后弹出主窗口 ADo代码 // ADO.cpp: implementation of the CADO class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #i