//this is the simulation program for RCPC hybrid ARQ
//384 bits of a frame and 1/4 parent code rate
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>
#define PI 3.1415926
#define RAND_MAX 32767
void crcencode(void); //crc encoder
void ptencoding(void); //Turbo encoder
void punct(void); //puncture processing
void depunct(void); //depuncturing processing
void uncoded(void); //uncoded
void decoding(void); //tubor encoder
void noise(int); //channel
void cdecode(void); //crc decoder
void selective(void); //arq process
void sranint(void); //s-random interleaving
//double sranint(void); //s-random interleaving
double rnd(void); //random data
double norndl(void); //gaussian random datadouble sigma,sum=0,temp;
int w=1,l,n=368,m=384,nm=1356,row,repeat,rpt,mm=8,pun,pun1;
const int bps=34000,tail=384;
int cnum,t,nn=8,NN=34; //parameters for rayleigh fading//variables for tubor encoding
int tt1,tt2,tt3,tt4,vk,yy1[2500],yy2[2500],yy3[2500],yy4[2500],yy[6500],yin[6500];
int yz[2500],sg[6500],punc[6500],y[2500];//variables for tubor decoding
int decision[2500];
float dpunc1[2500],dpunc2[2500],dpunc3[2500],dpunc4[2500],dpunc5[2500];
float intv1[2500],intv2[2500],Le21[2500],deleav[2500],dt[6500],dt1[6500],Lre21[2500],Lre12[2500];
float sigma1[2500][20],sigma2[2500][20],Lre1[2500],final[2500];
float dsigma1[2500][20],dsigma2[2500][20],dalpha[2500][20],dbeta[2500][20];
float pred[200][2500],alpha[2500][20],beta[2500][20],Lre2[2500],Lre[2500];int zz[100][2000],si,ei,dd,vc,done,aa; //crc and arq parameters
int p[]={1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1}; //crc polynomial//variables & parameters for s-random interleaving
int sy[2500],sz[2500],sz1[2500],syy[2500],msb[2500],lsb[2500],oput[2500];
int dc,ii,tt,idex,idex1,index[2500],count,reverse[2500],kk=17;
float indat[2500],sintv[2500],slre[2500],smlre[2500],sran[2500],slre21[2500];//table index for the s-random interleaving when the frame size is blow 512
int invalue[]={5,15,5,15,1,9,9,15,13,15,3,15,5,13,15,9,3,1,3,15,1,13,1,9,15,11,3,15,5};
int er,error,er1,error1,celer,celer1; //variables for error countingvoid main()
{
int i=0,j,ri,retn;
float tput[900],derror[900],sn,loop,retnm[900],celerr[900],effny[900];
FILE *out1; out1=fopen("gtnfat.txt","w");
loop=100; //the number of frame simulated
// tail=384; //Frame size including tail bits
l=10; //first dB
aa=1; //counting block transmitting
srand(time(NULL)); //SNR range
while(l<160)
{
//Initialization
ri=0; //first frame
er=0; //error rate without error correction
celer1=0; //frame error
er1=0; //bit error
cnum=0; //symbol duration
t=0; //counting frame duration
retn=0; //retransmission number //Frames at each SNR point while(ri<loop)
{
si=0; //start index of window size
ei=0; //end index of windoe size
done=0;
vc=aa; //initial value for counting the number fo frame
dd=2; //first puncturing pattern crcencode(); //crc encoding
ptencoding(); //turbo encoding //ARQ process
// while(!done) if(!done)
{
punct(); //puncturing
noise(l); //channel
depunct(); //depuncturing switch(dd)
{
//select depunctured parity bits
case 1:{
uncoded();
break;
}
case 2:{
decoding(); //1/2 coding
break;
}
case 3:{
decoding(); //1/3 coding
break;
}
case 4:{
decoding(); //1/4 coding
break;
} }
//////////////////
// er=error+er; // printf("er=:%6d\n",er); cdecode(); //crc decoding
selective(); //arq
} er1=er1+error1; //bit error rate counting
celer1=celer1+celer; //frame error rate counting
retn=retn+vc; //throughput counting
ri++;
}
sn=10*log10(1/((0.002+0.001*l)*(0.002+0.001*l))); //SNR
// Residual error rates derror[i]=er1/(loop*m); //bit error rates
celerr[i]=celer1/loop; //frame error rates
//throughput
retnm[i]=retn/(loop); //average retransmission number
tput[i]=0.958/retnm[i]; //throughput considered a overhead by crc and tail bits
//(384/16000)=0.024,line efficiency:distance 1500km-->0.005
//distance 3000km-->0.01
effny[i]=0.024/((0.024+0.01)*retnm[i]);
printf("%f %6.5f %8.6f %6.5f %5.4f %5.4f\n",sn,tput[i],derror[i],celerr[i],retnm[i],effny[i]);
fprintf(out1,"%f %6.5f %8.6f %6.5f %5.4f %5.4f\n",sn,tput[i],derror[i],celerr[i],retnm[i],effny[i]);
if(tput[i]<0.1)
break;
//SNR range inteval adjusted
if(sn>25)
l=l+6;
if(sn<25&&sn>20)
l=l+12;
if(sn<20&&sn>15)
l=l+24;
if(sn<15&&sn>10)
l=l+36;
if(sn<10&&sn>7)
l=l+48;
if(sn<7)
l=l+84;
/////////////
i++;
//////////
}
fclose(out1);
}这是一部分程序,不知道是指针问题还是数组定义的过大
//384 bits of a frame and 1/4 parent code rate
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>
#define PI 3.1415926
#define RAND_MAX 32767
void crcencode(void); //crc encoder
void ptencoding(void); //Turbo encoder
void punct(void); //puncture processing
void depunct(void); //depuncturing processing
void uncoded(void); //uncoded
void decoding(void); //tubor encoder
void noise(int); //channel
void cdecode(void); //crc decoder
void selective(void); //arq process
void sranint(void); //s-random interleaving
//double sranint(void); //s-random interleaving
double rnd(void); //random data
double norndl(void); //gaussian random datadouble sigma,sum=0,temp;
int w=1,l,n=368,m=384,nm=1356,row,repeat,rpt,mm=8,pun,pun1;
const int bps=34000,tail=384;
int cnum,t,nn=8,NN=34; //parameters for rayleigh fading//variables for tubor encoding
int tt1,tt2,tt3,tt4,vk,yy1[2500],yy2[2500],yy3[2500],yy4[2500],yy[6500],yin[6500];
int yz[2500],sg[6500],punc[6500],y[2500];//variables for tubor decoding
int decision[2500];
float dpunc1[2500],dpunc2[2500],dpunc3[2500],dpunc4[2500],dpunc5[2500];
float intv1[2500],intv2[2500],Le21[2500],deleav[2500],dt[6500],dt1[6500],Lre21[2500],Lre12[2500];
float sigma1[2500][20],sigma2[2500][20],Lre1[2500],final[2500];
float dsigma1[2500][20],dsigma2[2500][20],dalpha[2500][20],dbeta[2500][20];
float pred[200][2500],alpha[2500][20],beta[2500][20],Lre2[2500],Lre[2500];int zz[100][2000],si,ei,dd,vc,done,aa; //crc and arq parameters
int p[]={1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1}; //crc polynomial//variables & parameters for s-random interleaving
int sy[2500],sz[2500],sz1[2500],syy[2500],msb[2500],lsb[2500],oput[2500];
int dc,ii,tt,idex,idex1,index[2500],count,reverse[2500],kk=17;
float indat[2500],sintv[2500],slre[2500],smlre[2500],sran[2500],slre21[2500];//table index for the s-random interleaving when the frame size is blow 512
int invalue[]={5,15,5,15,1,9,9,15,13,15,3,15,5,13,15,9,3,1,3,15,1,13,1,9,15,11,3,15,5};
int er,error,er1,error1,celer,celer1; //variables for error countingvoid main()
{
int i=0,j,ri,retn;
float tput[900],derror[900],sn,loop,retnm[900],celerr[900],effny[900];
FILE *out1; out1=fopen("gtnfat.txt","w");
loop=100; //the number of frame simulated
// tail=384; //Frame size including tail bits
l=10; //first dB
aa=1; //counting block transmitting
srand(time(NULL)); //SNR range
while(l<160)
{
//Initialization
ri=0; //first frame
er=0; //error rate without error correction
celer1=0; //frame error
er1=0; //bit error
cnum=0; //symbol duration
t=0; //counting frame duration
retn=0; //retransmission number //Frames at each SNR point while(ri<loop)
{
si=0; //start index of window size
ei=0; //end index of windoe size
done=0;
vc=aa; //initial value for counting the number fo frame
dd=2; //first puncturing pattern crcencode(); //crc encoding
ptencoding(); //turbo encoding //ARQ process
// while(!done) if(!done)
{
punct(); //puncturing
noise(l); //channel
depunct(); //depuncturing switch(dd)
{
//select depunctured parity bits
case 1:{
uncoded();
break;
}
case 2:{
decoding(); //1/2 coding
break;
}
case 3:{
decoding(); //1/3 coding
break;
}
case 4:{
decoding(); //1/4 coding
break;
} }
//////////////////
// er=error+er; // printf("er=:%6d\n",er); cdecode(); //crc decoding
selective(); //arq
} er1=er1+error1; //bit error rate counting
celer1=celer1+celer; //frame error rate counting
retn=retn+vc; //throughput counting
ri++;
}
sn=10*log10(1/((0.002+0.001*l)*(0.002+0.001*l))); //SNR
// Residual error rates derror[i]=er1/(loop*m); //bit error rates
celerr[i]=celer1/loop; //frame error rates
//throughput
retnm[i]=retn/(loop); //average retransmission number
tput[i]=0.958/retnm[i]; //throughput considered a overhead by crc and tail bits
//(384/16000)=0.024,line efficiency:distance 1500km-->0.005
//distance 3000km-->0.01
effny[i]=0.024/((0.024+0.01)*retnm[i]);
printf("%f %6.5f %8.6f %6.5f %5.4f %5.4f\n",sn,tput[i],derror[i],celerr[i],retnm[i],effny[i]);
fprintf(out1,"%f %6.5f %8.6f %6.5f %5.4f %5.4f\n",sn,tput[i],derror[i],celerr[i],retnm[i],effny[i]);
if(tput[i]<0.1)
break;
//SNR range inteval adjusted
if(sn>25)
l=l+6;
if(sn<25&&sn>20)
l=l+12;
if(sn<20&&sn>15)
l=l+24;
if(sn<15&&sn>10)
l=l+36;
if(sn<10&&sn>7)
l=l+48;
if(sn<7)
l=l+84;
/////////////
i++;
//////////
}
fclose(out1);
}这是一部分程序,不知道是指针问题还是数组定义的过大
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货