📄 viterbi_cc.c
字号:
/*****************************************************************************//* FIle Name : viterbi_cc.c *//* Description : WiMax FEC Viterbi decoder *//* 64x64 search *//* g0=171o g1=133o *//* author : miffie *//* Date : Nov/03/05 *//* Copyright (c) 2005 miffie All rights reserved. *//*****************************************************************************/struct binaryset viterbi_cc (struct binaryset datain ) {int ii , jj ;short tmp0, tmp1, tmp2 ;struct binaryset bset ;char *p, *q ;char *top ;short brmetric[4] ;short metric0[64], metric1[64] ;short minimum_metric ;short won_metric ;char conv[64][4] ;char won[64] ;int size_q ;long long sdata0[64],sdata1[64] ;short MAX_METRIC = 0x7f ; //Main PRINTF("viterbi_cc size=%d\n", datain.size ) ; if ((top = (char *)malloc((datain.size/2)*sizeof(char)) ) == NULL) { PRINTF( " malloc failed in viterbi_cc.c\n") ; } //fail else { //allocated //initialize for(ii=0;ii<64;ii++) { //init metric0[ii] = MAX_METRIC ; conv[ii][0] = conv_enc(ii+0) ; conv[ii][1] = conv_enc(ii+0x40) ; } //init metric0[0] = 0 ; //assumed the shiftregister reset to 0 p = datain.data ; q = top ; size_q = 0 ; for(ii=0;ii<datain.size;ii=ii+2) { //each cycle //branch metric tmp1 = *p++ ; tmp2 = *p++ ; brmetric[0] = tmp1 + tmp2 ; brmetric[1] = (0xf-tmp1) + tmp2 ; brmetric[2] = tmp1 + (0xf-tmp2) ; brmetric[3] = (0xf-tmp1) + (0xf-tmp2) ; //metric minimum_metric = MAX_METRIC ; for(jj=0;jj<64;jj++) { //each metric1 tmp0 = (jj>>1) + 0 ; tmp1 = (jj>>1) + 0x20 ; //printf("%d %d metric[%d]=%d metric[%d]=%d\n", ii, jj, tmp0, metric0[tmp0], tmp1, metric0[tmp1] ) ; //printf("%d %d brmetric[%d]=%d brmetric[%d]=%d\n",ii, jj, conv[jj][0], brmetric[ conv[jj][0] ] , conv[jj][1], brmetric[ conv[jj][1] ] ) ; tmp0 = metric0[tmp0] + brmetric[ conv[jj][0] ] ; tmp1 = metric0[tmp1] + brmetric[ conv[jj][1] ] ; //printf("%d %d tmp0=%d tmp1=%d\n",ii, jj, tmp0, tmp1 ) ; won[jj] = 0 ; 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]) { sdata1[ jj ] = (sdata0[ (jj>>1) + 0x20 ]<<1) + 0x1 ; } else { sdata1[ jj ] = (sdata0[ (jj>>1) + 0x0 ]<<1) + 0x0 ; } } //each metric1 for(jj=0;jj<64;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 sdata0[jj] = sdata1[jj] ; } //each metric1 if (ii>136) {//output *q++ = (sdata1[won_metric]>>63) & 0x1 ; size_q++ ; } //output } //each cycle bset.format = 0 ; bset.size = size_q ; bset.data = top ; }//allocated free ( datain.data ) ; return ( bset ) ;} //viterbi_cc
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -