⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 这是lva算法
💻 C
📖 第 1 页 / 共 2 页
字号:
	 if (numb_shu[y]<8)
  survivor_state[nextstate[j*2+l]*(depth_of_trellis+1)*8+(depth_of_trellis+1)*y+q]
      =survivor_state_temp[j*(depth_of_trellis+1)*8+(depth_of_trellis+1)*numb_shu[y]+q];
	 else
    survivor_state[nextstate[j*2+l]*(depth_of_trellis+1)*8+(depth_of_trellis+1)*y+q]
      =survivor_state_temp[(j+1)*(depth_of_trellis+1)*8+(depth_of_trellis+1)*(numb_shu[y]-8)+q];
 }
if (numb_shu[y]<8)
  survivor_state[nextstate[j*2+l]*(depth_of_trellis+1)*8+(depth_of_trellis+1)*y+i]=j;
 else
  survivor_state[nextstate[j*2+l]*(depth_of_trellis+1)*8+(depth_of_trellis+1)*y+i]=j+1;
  
 }
//---------------------------------------------------------------------
for (y=0;y<8;y++)
{
	 if(numb_shu[y]<8)
state_metric[nextstate[j*2+l]*(L+1)+y]=state_metric_temp[j*(L+1)+numb_shu[y]]+branch_metric;
	 else
state_metric[nextstate[j*2+l]*(L+1)+y]=state_metric_temp[(j+1)*(L+1)+(numb_shu[y]-8)]+branch_metric1;
}
//----------------------------------------------------------
}
	  for(q=0;q<number_of_states*8;q++)	  
       state_metric_temp[q]=state_metric[q];
	  	  for (q=0;q<number_of_states*(depth_of_trellis+1)*(L+1);q++)
        survivor_state_temp[q]=survivor_state[q];
}


// for(i=0;i<number_of_states*(L+1)*(depth_of_trellis+1);i++)

//printf("%d ",survivor_state[i]);
//-----------------------------------generate the decoder output from the optimal path
//-----------------------------frist one






//---------------------------------------------------shou wei
//
//structure
//
//
//structure
//
//
//
//
//
//
//
//-------------------------------------------------------shou wei

for(i=depth_of_trellis-L+2;i<=depth_of_trellis;i++)
{
		l=0;
	last_stop=number_of_states/pow(2,i-depth_of_trellis+L-2);
  // printf("%d\n",last_stop);
 // for (j=0;j<last_stop;j++)
  	  for (j=0;j<last_stop;j=j+2)
	  {
//--------------------------------------------------
		         branch_metric=0;
				 
	   branch_output_1=out_put[j*2+l]&0x0001;

	  // printf("%d\n",out_put[j*2+l]);

	   branch_output_2=(out_put[j*2+l]&0x0002)>>1;
	   branch_output_3=(out_put[j*2+l]&0x0004)>>2;


 //for(ll=0;ll<n;ll++)
    if (branch_output_1!=channel_output_matrix[i-1])
		branch_metric++;
		    if (branch_output_2!=channel_output_matrix[i-1+depth_of_trellis])
		branch_metric++;
		    if (branch_output_3!=channel_output_matrix[i-1+2*depth_of_trellis])
		branch_metric++;
//--------------------------------------------------
			branch_metric1=0;
				   branch_output_1=out_put[(j+1)*2+l]&0x0001;

	  // printf("%d\n",out_put[j*2+l]);

	   branch_output_2=(out_put[(j+1)*2+l]&0x0002)>>1;
	   branch_output_3=(out_put[(j+1)*2+l]&0x0004)>>2;


 //for(ll=0;ll<n;ll++)
    if (branch_output_1!=channel_output_matrix[i-1])
		branch_metric1++;
		    if (branch_output_2!=channel_output_matrix[i-1+depth_of_trellis])
		branch_metric1++;
		    if (branch_output_3!=channel_output_matrix[i-1+2*depth_of_trellis])
		branch_metric1++;
//-------------------------------------------------------------------------
			
temp[0]=state_metric_temp[j*(L+1)+0]+branch_metric;
temp[1]=state_metric_temp[j*(L+1)+1]+branch_metric;
temp[2]=state_metric_temp[j*(L+1)+2]+branch_metric;
temp[3]=state_metric_temp[j*(L+1)+3]+branch_metric;
temp[4]=state_metric_temp[j*(L+1)+4]+branch_metric;
temp[5]=state_metric_temp[j*(L+1)+5]+branch_metric;
temp[6]=state_metric_temp[j*(L+1)+6]+branch_metric;
temp[7]=state_metric_temp[j*(L+1)+7]+branch_metric;


temp[8]=state_metric_temp[(j+1)*(L+1)+0]+branch_metric1;
temp[9]=state_metric_temp[(j+1)*(L+1)+1]+branch_metric1;
temp[10]=state_metric_temp[(j+1)*(L+1)+2]+branch_metric1;
temp[11]=state_metric_temp[(j+1)*(L+1)+3]+branch_metric1;
temp[12]=state_metric_temp[(j+1)*(L+1)+4]+branch_metric1;
temp[13]=state_metric_temp[(j+1)*(L+1)+5]+branch_metric1;
temp[14]=state_metric_temp[(j+1)*(L+1)+6]+branch_metric1;
temp[15]=state_metric_temp[(j+1)*(L+1)+7]+branch_metric1;

//-----------------------------------------------------------pai xu
//
//
//
//
//
//
//
//------------------------------------------------------------pai xu
for(y=0;y<8;y++)
{
numb[y]=temp[0];  numb_shu[y]=0;
for(q=1;q<16;q++)
{
	if(temp[q]<numb[y])
	{
		numb[y]=temp[q];
     numb_shu[y]=q;
	}
}
  temp[numb_shu[y]]= 32767;
}




//----------------------------------------------------------matrix
//
//
//
//
//
//
//----------------------------------------------------------matrix
 for(y=0;y<8;y++)
 {
 for(q=0;q<depth_of_trellis+1;q++)
 {
	 if (numb_shu[y]<8)
  survivor_state[nextstate[j*2+l]*(depth_of_trellis+1)*8+(depth_of_trellis+1)*y+q]
      =survivor_state_temp[j*(depth_of_trellis+1)*8+(depth_of_trellis+1)*numb_shu[y]+q];
	 else
    survivor_state[nextstate[j*2+l]*(depth_of_trellis+1)*8+(depth_of_trellis+1)*y+q]
      =survivor_state_temp[(j+1)*(depth_of_trellis+1)*8+(depth_of_trellis+1)*(numb_shu[y]-8)+q];
 }
if (numb_shu[y]<8)
  survivor_state[nextstate[j*2+l]*(depth_of_trellis+1)*8+(depth_of_trellis+1)*y+i]=j;
 else
  survivor_state[nextstate[j*2+l]*(depth_of_trellis+1)*8+(depth_of_trellis+1)*y+i]=j+1;
  
 }
//---------------------------------------------------------------------
for (y=0;y<8;y++)
{
	 if(numb_shu[y]<8)
state_metric[nextstate[j*2+l]*(L+1)+y]=state_metric_temp[j*(L+1)+numb_shu[y]]+branch_metric;
	 else
state_metric[nextstate[j*2+l]*(L+1)+y]=state_metric_temp[(j+1)*(L+1)+(numb_shu[y]-8)]+branch_metric1;
}
//----------------------------------------------------------
}
	  for(q=0;q<number_of_states*8;q++)	  
       state_metric_temp[q]=state_metric[q];
	  	  for (q=0;q<number_of_states*(depth_of_trellis+1)*(L+1);q++)
        survivor_state_temp[q]=survivor_state[q];
}

































//////////////////////////--------------------------------------chan sheng
//for (q=0;q<depth_of_trellis+1;q++)



//printf("%d ",survivor_state[q]);


for (i=0;i<=depth_of_trellis-L;i++)
   decodeder_output_matrix[i]=0;

for (y=0;y<8;y++)
{

for (i=1;i<=depth_of_trellis+1;i++)
  state_sequence[i-1]=survivor_state[i+y*(depth_of_trellis+1)];
  state_sequence[depth_of_trellis]=0;
//for (q=0;q<depth_of_trellis+1;q++)
//printf("%d ",state_sequence[q]);



 for (i=0;i<=depth_of_trellis-L;i++)
 {
    decodeder_output_matrix[i+y*(depth_of_trellis-L+1)]
		=input[state_sequence[i]*number_of_states+state_sequence[i+1]];
//	printf("%d%d ",channel_input[i],decodeder_output_matrix[i]);
 }

}
/*
for(i=0;i<88;i++)
{
 printf("%d",channel_input[i]);
}
printf("\n");
for(i=0;i<88;i++)
{
 printf("%d",decodeder_output_matrix[i]);
}
printf("\n");
*/
/*
x1=0;
x2=0;
x3=0;
x4=0;
x5=0;
x6=0;
x7=0;
x8=0;
for(i=0;i<88;i++)
{
if(channel_input[i]!=decodeder_output_matrix[i+88*0])
x1++;

if(channel_input[i]!=decodeder_output_matrix[i+88*1])
x2++;
if(channel_input[i]!=decodeder_output_matrix[i+88*2])
x3++;
if(channel_input[i]!=decodeder_output_matrix[i+88*3])
x4++;
if(channel_input[i]!=decodeder_output_matrix[i+88*4])
x5++;
if(channel_input[i]!=decodeder_output_matrix[i+88*5])
x6++;
if(channel_input[i]!=decodeder_output_matrix[i+88*6])
x7++;
if(channel_input[i]!=decodeder_output_matrix[i+88*7])
x8++;

}

printf("%d %d %d %d %d %d %d %d ",x1,x2,x3,x4,x5,x6,x7,x8);
printf("\n");


//////////////////yan zheng

 y=0;

*/


for(y=0;y<8;y++)
{
	q=0;
	z=0;
while(q<in_length)
{
if((z&0x100)==0)
  z=(z<<1)|decodeder_output_matrix[(q++)+y*in_length];
else
    z=(z&0xff)^0x1D;
}

if((z&0x100)!=0)
 z=(z&0xff)^0x1D;


 if (z==0)
 {
	 for(i=0;i<in_length-8;i++)
	 
		 decoder_resut[i]=decodeder_output_matrix[y*in_length+i];
	 //printf("%d",y);
		 break;
 }
}



if (z!=0)

	numerror=numerror+5;

 /////////////////////////////////////////////////////CRC jiao yan
else
{
 for (i=0;i<in_length-8;i++)
 {
	 if(channel_input[i]!=decoder_resut[i])
		 numerror++;
 }

}

}

 
 errorate[p]=numerror/800000;
 printf("%.9f ",errorate[p]);
 numerror=0;
}


   if((fp=fopen("lva.bin","wb"))==NULL)
 printf("cannot open infile\n");
   for(p=0;p<9;p++)
 fwrite(&errorate[p],sizeof(double),1,fp);
 fclose(fp);



























/*
for(i=1;i<=(depth_of_trellis-L+1);i++)
{
  for(g=0;g<number_of_states;g++)
	  flag[g]=0;
  if (i<=L)
	  step=pow(2,L-i);
   
  else
	  step=1;
  //printf("%d\n",step);
  for (j=0;j<number_of_states;j=j+step)
	  for(l=0;l<=1;l++)
	  {
       branch_metric=0;
	   branch_output_1=out_put[j*2+l]&0x0001;

	  // printf("%d\n",out_put[j*2+l]);

	   branch_output_2=(out_put[j*2+l]&0x0002)>>1;
	   branch_output_3=(out_put[j*2+l]&0x0004)>>2;


 //for(ll=0;ll<n;ll++)
    if (branch_output_1!=channel_output_matrix[i-1])
		branch_metric++;
		    if (branch_output_2!=channel_output_matrix[i-1+depth_of_trellis])
		branch_metric++;
		    if (branch_output_3!=channel_output_matrix[i-1+2*depth_of_trellis])
		branch_metric++;
//--------------------------------------------------------------------
if(state_metric[nextstate[j*2+l]*2+1]>(state_metric[j*2]+branch_metric)||flag[nextstate[j*2+l]]==0)
{
state_metric[nextstate[j*2+l]*2+1]=state_metric[j*2]+branch_metric;
survivor_state[nextstate[j*2+l]*(depth_of_trellis+1)+i]=j;


//printf("%d\n",survivor_state[nextstate[j,l],i]);


flag[nextstate[j*2+l]]=1;
}
}
//---------------------------------------------	    
//	  for(a=0;a<64*2;a++)
//  printf("%d ",state_metric[a]);

//-------------------------------------------
  for (a=0;a<number_of_states;a++)
  {
 tempt=state_metric[a*2];
 state_metric[a*2]=state_metric[a*2+1];
 state_metric[a*2+1]=tempt;
  }
}

*/
//-----------------------------------------start decoding of non-tail channel outputs.

//--------------------------------------start decoding of the tail channel outputs.
/*
for(i=depth_of_trellis-L+2;i<=depth_of_trellis;i++)
{
    for(g=0;g<number_of_states;g++)
	  flag[g]=0;
   last_stop=number_of_states/pow(2,i-depth_of_trellis+L-2);
  // printf("%d\n",last_stop);
  for (j=0;j<last_stop;j++)
	  //for(l=0;l<=1;l++)
	  {
       branch_metric=0;
	   branch_output_1=out_put[j*2+0]&0x0001;

	  // printf("%d\n",out_put[j*2+l]);

	   branch_output_2=(out_put[j*2+0]&0x0002)>>1;
	   branch_output_3=(out_put[j*2+0]&0x0004)>>2;
 //for(ll=0;ll<n;ll++)
    if (branch_output_1!=channel_output_matrix[i-1])
		branch_metric++;
		    if (branch_output_2!=channel_output_matrix[i-1+depth_of_trellis])
		branch_metric++;
		    if (branch_output_3!=channel_output_matrix[i-1+2*depth_of_trellis])
		branch_metric++;
//--------------------------------------------------------------------
if(state_metric[nextstate[j*2]*2+1]>(state_metric[j*2]+branch_metric)||flag[nextstate[j*2]]==0)
{
state_metric[nextstate[j*2]*2+1]=state_metric[j*2]+branch_metric;

survivor_state[nextstate[j*2]*(depth_of_trellis+1)+i]=j;


//printf("%d\n",depth_of_trellis);


flag[nextstate[j*2]]=1;
}
}


  for (a=0;a<number_of_states;a++)
  {
 tempt=state_metric[a*2];
 state_metric[a*2]=state_metric[a*2+1];
 state_metric[a*2+1]=tempt;
  }
}


//-------------------------------------------------

//for (a=0;a<64;a++)
//if(input[a]==0||input[a]==1)
//{
//	i++;
//printf("%d ",survivor_state[a*(depth_of_trellis+1)+5]);
//}

//---------------------------------------







//-----------------------------------generate the decoder output from the optimal path
//-----------------------------frist one


for (i=0;i<=depth_of_trellis;i++)
  state_sequence[i]=0;
state_sequence[depth_of_trellis-1]=survivor_state[depth_of_trellis];

for(i=1;i<=depth_of_trellis;i++)
{
state_sequence[depth_of_trellis-i]=survivor_state[state_sequence[depth_of_trellis-i+1]*(depth_of_trellis+1)+depth_of_trellis-i+1];
//printf("%d\n",state_sequence[depth_of_trellis-i]);
}
 

for (i=0;i<=depth_of_trellis-L;i++)
   decodeder_output_matrix[i]=0;
 for (i=0;i<=depth_of_trellis-L;i++)
 {
    decodeder_output_matrix[i]=input[state_sequence[i]*number_of_states+state_sequence[i+1]];
//	printf("%d%d ",channel_input[i],decodeder_output_matrix[i]);
 }

 //---------------------------------frist two

//-------------------------------------------------over decodeder_output_matrix


 //-----------------------------------------------------------





	q=0;
	z=0;
while(q<in_length)
{
if((z&0x100)==0)
  z=(z<<1)|decodeder_output_matrix[q++];
else
    z=(z&0xff)^0x1D;
}

if((z&0x100)!=0)
 z=(z&0xff)^0x1D;


 if (z==0)
	 printf("right");


 /////////////////////////////////////////////////////CRC jiao yan




 
 for (i=0;i<in_length;i++){
	 if(channel_input[i]!=decodeder_output_matrix[i])
		 numerror++;
 }

 /*
 errorate[0]=numerror/88;
 printf("%.9f ",errorate[0]);
 numerror=0;
*/

/*
   if((fp=fopen("xxx.bin","wb"))==NULL)
 printf("cannot open infile\n");
   for(p=0;p<1000;p++)
 fwrite(&errorate[p],sizeof(double),1,fp);
 fclose(fp);
*/

  free (decodeder_output_matrix);
  free (state_sequence);
  free (survivor_state);
  free (channel_output_matrix);
  free (nextstate);
  free (input);
  free (out_put);
  free (state_metric);
  free (state_metric_temp);
   free (survivor_state_temp);
 


 //----------------------------------- free store




}




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -