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

📄 viterbi_turbo.c

📁 这个文件包括wimax中所有的编解码源代码
💻 C
字号:
/*****************************************************************************//*   FIle Name : viterbi_turb2.c                                             *//*   Description : WiMax FEC Viterbi Decoder for Block Turbo Code            *//*   author : miffie                                                         *//*   Date   : sep/26/05                                                      *//*   Copyright (c) 2005 miffie   All rights reserved.                        *//*****************************************************************************///One line correction in turbo decoder will be done through 2 pipeline stages//#1  Error estimation in normal order //    write into Soft memory//    write into path memory//#2  trace back with SoftOutput//    read from both Soft memory & pathmemory//    write back to Soft memorystruct binaryset viterbi_turbo (char type, struct binaryset datain ) {int 	ii , jj , kk ;char    nn , pp ;short 	tmp0, tmp1, tmp2 ;struct 	binaryset bset ;short	brmetric[4] ;short 	metric0[64], metric1[64] ;short	minimum_metric ;short	won_metric ;char	previous_state[128][4] ;char	branch[64] ;char	won[128] ;char    pathmem[128][64] ; short	MAX_METRIC = 0x7f ;char    SISO_SHIFT = 3 ;char    BRANCH_OFFSET = 4 ;char    parity ;  //Main    //initialize     PRINTF( "viterbi_turbo.c size=%x \n", datain.size ) ;    nn =  (type==1) ? 0xf :          (type==2) ? 0x1f : 0x3f ;    pp =  (type==1) ? 0x5 :   //lfsr+parity length          (type==2) ? 0x6 : 0x7 ;    for(ii=0;ii<=nn;ii++) { //init      tmp0 = lfsr( type, 0 , ii ) & nn ;      tmp1 = lfsr( type, 1 , ii ) & nn ;      previous_state[ tmp0 ][0] = ii ;      previous_state[ tmp1 ][1] = ii ;    } //init    for(ii=0;ii<=nn;ii++) printf("pstate(%x %x) %x\n", ii, 0, previous_state[ii][0] ) ;    for(ii=0;ii<=nn;ii++) printf("pstate(%x %x) %x\n", ii, 1, previous_state[ii][1] ) ;////////////////////////////////////////////////////////////////////#1  Error estimation in normal order//////////////////////////////////////////////////////////////////  if (type<4) { //error///////////////////////////////////////////////////////////////////    //initialize    for(ii=0;ii<=nn;ii++) metric0[ii] = MAX_METRIC ;    metric0[0] = 0 ;    for(ii=0;ii<datain.size-1;ii++) { //each cycle in REVERSE order      //branch metric      //state0-31      brmetric[0] = (datain.data[ii]>=8)  ? 0xf-datain.data[ii]: datain.data[ii]  ;      brmetric[0] += BRANCH_OFFSET ;      brmetric[1] = 0xf - brmetric[0] ;      minimum_metric = MAX_METRIC ;      //metric      for(jj=0;jj<=nn;jj++) { //each state         tmp0 = previous_state[jj][0] ;         tmp1 = previous_state[jj][1] ;         //printf("%d %x brmetric[0]=%x brmetric[1]=%x\n",ii, jj,  brmetric[0] , brmetric[1] ) ;         tmp0 = metric0[tmp0] + brmetric[0]  ;         tmp0 = (tmp0>MAX_METRIC) ? MAX_METRIC : tmp0 ;         tmp1 = metric0[tmp1] + brmetric[1]  ;         tmp1 = (tmp1>MAX_METRIC) ? MAX_METRIC : tmp1 ;         won[jj] = 0 ;         pathmem[ii][jj] = tmp0-tmp1 ;         //printf("%d %d tmp0=%d tmp1=%d pathmem=%d\n",ii, jj, tmp0, tmp1, pathmem[ii][jj] ) ;         if (tmp0>=tmp1) {            tmp0 = tmp1 ; //tmp0 =min(tmp0,tmp1) ;            won[jj] = 1 ;         }         metric1[jj] = tmp0 ;         //limitter         if (metric1[jj] > MAX_METRIC ) metric1[jj] = MAX_METRIC ;         //printf("%d metric[%d]=%d\n", ii, jj,  metric1[jj] ) ;                  if (metric1[jj] < minimum_metric) {             minimum_metric = metric1[jj] ;             won_metric = jj ;         }         ////serial data process         //if (won[jj]) {         //    pathmem1[ jj ] = (pathmem0[ state[jj][1] ]<<1) + 0x1 ;         //} else {         //    pathmem1[ jj ] = (pathmem0[ state[jj][0] ]<<1) + 0x0 ;         //}         //printf("%d %x pathmem1 = %x\n", ii, jj, pathmem1[jj]) ;               } //each state      printf("%d won_metric = %x\n", ii, won_metric ) ;      //printf("%d pathmem1(%x) = %x\n", ii, won_metric, pathmem1[won_metric]) ;      for(jj=0;jj<=nn;jj++) { //each metric1        //Normalization       // metric1[jj] -= minimum_metric ; //force the won_metric to zero        //copy metric1 to metric0 for the next cycle operation        metric0[jj] = metric1[jj] ;        //copy metric1 to metric0 for the next cycle operation        //pathmem0[jj] = pathmem1[jj] ;      } //each metric1    } //each cycle    printf("won_metric = %x\n",  won_metric ) ;    ////////////////////////////////////////////////////////////////////#3  trace back with SoftOutput in Reverse order//////////////////////////////////////////////////////////////////      //output       //won_metric=0 ; //because check should be zero at the end of calcuration      for(jj=datain.size-2;jj>=0;jj--)  { //output        tmp1 = pathmem[jj][won_metric] ;        printf("datain.data(%d)=%x path(%x)=%x ", jj,  datain.data[jj], won_metric, tmp1) ;        //SISO Softin Softout        datain.data[jj] = ((tmp1<0)&(datain.data[jj]==0))  ? 0 :                          ((tmp1<0)&(datain.data[jj]<8))  ? datain.data[jj]+(tmp1>>SISO_SHIFT) :                          ((tmp1<0)&(datain.data[jj]==0xf))  ? 0xf :                           (tmp1<0) ? datain.data[jj]-(tmp1>>SISO_SHIFT) :                           ((tmp1>=0)&(datain.data[jj]<8))  ? 8+(tmp1>>SISO_SHIFT) :                       /* (tmp1==1)  ? */ 7-(tmp1>>SISO_SHIFT) ;        datain.data[jj] = (datain.data[jj]<0 ) ? 0 :                          (datain.data[jj]>0xf) ? 0xf : datain.data[jj] ;        printf("=>%x\n", datain.data[jj]) ;        if ( tmp1 >= 0  ) won_metric = previous_state[won_metric][1]  ;         else  won_metric = previous_state[won_metric][0] ;      } //output  } //error   else { //parity only      parity = 0 ;       for(jj=0;jj<datain.size;jj++)          parity ^= (datain.data[jj]>=8)  ? 1 : 0 ;      if (parity==0) { //no error        for(jj=0;jj<datain.size;jj++)  { //output          datain.data[jj] = (datain.data[jj]==0 ) ? 0 :                            (datain.data[jj]==0xf) ? 0xf :                            (datain.data[jj]>=8)  ? datain.data[jj] +1  : datain.data[jj] -1 ;        } //output      } else { //error        for(jj=0;jj<datain.size;jj++)  { //output          datain.data[jj] = (datain.data[jj]>=8)  ? datain.data[jj] -1  :                             datain.data[jj] +1 ;        } //output      } //error  } //parity only  return ( datain ) ;} //viterbi_turbo

⌨️ 快捷键说明

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