📄 viterbi_turbo1.c
字号:
/*****************************************************************************//* FIle Name : viterbi_turbo1.c *//* Description : WiMax FEC Viterbi Decoder #1pipe for Code Type4 *//* author : miffie *//* Date : sep/26/05 *//* Copyright (c) 2005 miffie All rights reserved. *//*****************************************************************************///One line correction in turbo decoder will be done through 3 pipeline stages//#1 check metrics calculation in normal order// write into Soft memory (in first row iteration )//#2 Error estimation in reverse order// read from Soft memory// write into path memory//#3 trace back with SoftOutput// read from both Soft memory & pathmemory// write back to Soft memory//In this viterbi_turbo1, #1 is exercised.struct binaryset viterbi_turbo1(char type, struct binaryset datain, char *parity ) {int ii , jj , kk ;short tmp0, tmp1, tmp2 ;struct binaryset bset ;char *top ;short brmetric[4] ;short metric0[64], metric1[64] ;short minimum_metric ;short won_metric ;char state[64][4] ;char pmetric0[2], pmetric1[2] ;char previous_state[64][4] ;char branch[64] ;char won[64] ;short MAX_METRIC = 0x7f ;char nn ; //Main PRINTF("viterbi_turbo1 size=%d\n", datain.size ) ; if ((top = (char *)malloc(64*sizeof(char)) ) == NULL) { PRINTF( " malloc failed in viterbi_turbo1.c\n") ; } //fail else { //allocated //initialize nn = (type==1) ? 0xf : (type==2) ? 0x1f : 0x3f ; 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 check metrics calculation in normal order/////////////////////////////////////////////////////////////////// //initialize for(ii=0;ii<=nn;ii++) metric0[ii] = MAX_METRIC ; metric0[0] = 0 ; pmetric0[0] = 0 ; pmetric0[1] = MAX_METRIC ; for(ii=0;ii<datain.size;ii++) { //each cycle //NO calculate parity //branch metric tmp1 = datain.data[ii] ; brmetric[0] = tmp1 ; brmetric[1] = (0xf-tmp1) ; minimum_metric = 0xff ; if ((ii<(datain.size-1)) &(type<4)) { //not parity //metric for(jj=0;jj<=nn;jj++) { //each state tmp0 = previous_state[jj][0] ; tmp1 = previous_state[jj][1] ; //printf("%d %x metric[%x]=%x metric[%x]=%x\n", ii, jj, tmp0, metric0[tmp0], tmp1, metric0[tmp1] ) ; //printf("%d %x brmetric[0]=%x brmetric[1]=%x\n",ii, jj, brmetric[0] , brmetric[1]) ; tmp0 = metric0[tmp0] + brmetric[0] ; tmp1 = metric0[tmp1] + brmetric[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 ; } } //each state //printf("viterbi1 (%d) won_metric %x\n", ii, 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] ; } //each metric1 } //not parity //parity metric tmp0 = pmetric0[0] +brmetric[0] ; tmp1 = pmetric0[1] +brmetric[1] ; pmetric1[0]=(tmp0>tmp1) ? tmp1 : tmp0 ; pmetric1[0]=(pmetric1[0]>MAX_METRIC) ? MAX_METRIC : pmetric1[0] ; tmp0 = pmetric0[0] +brmetric[1] ; tmp1 = pmetric0[1] +brmetric[0] ; pmetric1[1]=(tmp0>tmp1) ? tmp1 : tmp0 ; pmetric1[1]=(pmetric1[1]>MAX_METRIC) ? MAX_METRIC : pmetric1[1] ; //normalization tmp0 = (pmetric1[0]>pmetric1[1]) ? pmetric1[1] : pmetric1[0] ; pmetric1[0] = pmetric1[0] -tmp0 ; pmetric1[1] = pmetric1[1] -tmp0 ; //printf("pmetric %d %d\n", pmetric1[0], pmetric1[1]) ; pmetric0[0] = pmetric1[0] ; pmetric0[1] = pmetric1[1] ; } //each cycle //output printf("viterbi1 won_metric %x\n", won_metric ) ; for(jj=0;jj<=nn;jj++) { //each state top[jj] = (metric0[jj]==0) ? 0 : metric0[jj] +8 ; top[jj] = (top[jj]>MAX_METRIC) ? MAX_METRIC : top[jj] ; }//each state //parity //printf("pmetric %d %d\n", pmetric1[0], pmetric1[1]) ; *parity = pmetric1[0]-pmetric1[1] ; bset.size =nn +1 ; bset.format = 1 ; bset.data = top ; } //allocated return ( bset ) ;} //viterbi_turbo1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -