?? turbo_decoder.c
字號:
/*****************************************************************************//* FIle Name : turbo_decoder.c *//* Description : WiMax OFDM FEC turbo Product code for Decoder *//* author : miffie *//* Date : Nov/15/05 *//* Copyright (c) 2005 miffie All rights reserved. *//*****************************************************************************/struct binaryset turbo_decoder (struct binaryset datain,// struct binaryset exp, char fec_code_type, char Nsub ) {//input format must be 1 and each bit data is SOFT(0x0-0xf)//This solution is still not effcient.//This may be improved in follwoing ways://1) cross check // After the end of each itelation, the cross point between// errored row and errored column may be an error. So, the point's// data should be changed to 7 or 8.//2) Area// viterbi_turbo2 is consuming huge area, so it must reduce the size,// I guess 128 state should be reduced 32 using Marray method.int ii , jj , ll, repeat ;char tmp1 , tmp2 , shifter ;char *pp ;struct binaryset bset0, bset1 , metric , exp0 ;char bdat[ 64 ] ;char edat[ 64 ] ;char fdat[ 64 ] ;char parity, sum_parity, previous_sum ;char fail ;char rowtype, columntype ;char row, column , nx, ny;//rowtype, columntype// 1:(16,11), 2:(32,26), 3(64,57),// 4:(8,7) , 5(16,15), 6:(32,31) 7:(64,63)//short Nfull[] = {384, 384, 768,768, 1152, 1152} ;// row column Ix Iy B Qchar btc_parameters[6][6] = { { 2, 1, 4, 2, 8, 6}, { 2, 5, 0, 4, 0, 6}, { 2, 2, 0, 8, 0, 4}, { 3, 5, 7, 2, 30, 4}, { 7, 2, 3, 13, 7, 5}, { 6, 3, 13, 3, 7, 5} } ; //Main //X sizes rowtype = btc_parameters[fec_code_type-7][0] ; nx = (rowtype==1) ? 5 : (rowtype==2) ? 6 : (rowtype==3) ? 7 : 1 ; row = (rowtype==1) ? 11 : (rowtype==2) ? 26 : (rowtype==3) ? 57 : (rowtype==4) ? 7 : (rowtype==5) ? 15 : (rowtype==6) ? 31 : 63 ; row -= btc_parameters[fec_code_type-7][2] ; //row-Ix nx = row + nx ; //Y sizes columntype = btc_parameters[fec_code_type-7][1] ; ny = (columntype==1) ? 5 : (columntype==2) ? 6 : (columntype==3) ? 7 : 1 ; column = (columntype==1) ? 11 : (columntype==2) ? 26 : (columntype==3) ? 57 : (columntype==4) ? 7 : (columntype==5) ? 15 : (columntype==6) ? 31 : 63 ; column -= btc_parameters[fec_code_type-7][3] ; //column-Iy ny = column + ny ; if ((pp = (char *)malloc((nx*ny)*sizeof(char)) ) == NULL) { PRINTF( " malloc failed in turbo_decoder.c\n") ; } //fail else { //allocated PRINTF( "turbo_decoder.c size=0x%x\n", datain.size ) ; repeat = 0 ; sum_parity = 0x7e ; previous_sum = 0x7f ; //add padding bset1 = pad_binaryset ( btc_parameters[fec_code_type-7][4] ) ; datain = cat_binaryset( bset1, datain ) ; //Loop while ((previous_sum>sum_parity) & (sum_parity>0)) { //repeat previous_sum = sum_parity ; ///////////////////////////////////////////////////////// //column check "This must be first" // Because correcting checks first can get better result. ///////////////////////////////////////////////////////// for(jj=0;jj<nx;jj++) { //each column printf("\n %d itelation Column%d decoding...\n" , repeat , jj ) ; //Extract column to bset1 //bset1 = extract_binaryset( datain, jj*nx, nx ) ; bset1.data = &bdat[0] ; bset1.format = 1 ; bset1.size = ny ; for(ii=0;ii<ny;ii++) { //each bit bset1.data[ii] = datain.data[ii*nx+jj] ; } //each bit //Extract expectation to exp0 //exp0.data = &edat[0] ; //exp0.format = 0 ; //exp0.size = ny ; //for(ii=0;ii<ny;ii++) { //each bit // exp0.data[ii] = exp.data[ii*nx+jj] ; //} //each bit //print_binaryset( bset1) ; if (columntype<4) { //lfsr metric = viterbi_turbo1(columntype, bset1 , &parity) ; //if (metric.data[0]>0) { bset1 = viterbi_turbo2(columntype, bset1, metric, &parity ) ; //} //print_binaryset( bset1) ; }//lfsr bset0.format=0 ; bset0.size=ny ; bset0.data=&fdat[0] ; //writeback to datain for(ii=0;ii<ny;ii++) { //each bit datain.data[ii*nx+jj] = bset1.data[ii] ; bset0.data[ii] = (bset1.data[ii]>=8) ? 1 : 0 ; //printf("%d data=%x parity=%x\n", ii, bset1.data[ii], parity) ; } //each bit sum_parity += parity ; //printf(" %d itelation Column%d parity=%x\n", repeat, jj, parity) ; //fail = compare_binaryset( exp0, bset0 ) ; } //each column //print_binaryset( datain ) ; ///////////////////////////////////////////////////////// //row check sum_parity= 0 ; for(jj=0;jj<column;jj++) { //each row printf("\n %d itelation Row%d decoding...\n" , repeat , jj ) ; bset1 = extract_binaryset( datain, jj*nx, nx ) ; //exp0 = extract_binaryset( exp, jj*nx, nx ) ; //print_binaryset( bset1) ; metric = viterbi_turbo1(rowtype, bset1, &parity ) ; //if (metric.data[0]>0) { bset1 = viterbi_turbo2(rowtype, bset1, metric, &parity ) ; //} //print_binaryset( bset1 ) ; //writeback to datain bset0.format=0 ; bset0.size=nx ; bset0.data=&fdat[0] ; for(ii=0;ii<nx;ii++) { //each bit datain.data[jj*nx+ii] = bset1.data[ii] ; bset0.data[ii] = (bset1.data[ii]>=8) ? 1 : 0 ; } //each bit sum_parity += parity ; printf(" %d itelation Row%d parity=%x\n", repeat, jj, parity) ; //fail = compare_binaryset( exp0, bset0 ) ; } //each row printf(" %d itelation sum_parity=%x\n", repeat, sum_parity) ; //print_binaryset( datain ) ; repeat++ ; } //repeat ///////////////////////////////////////////////////////// //Soft to Hard Decision bset0.data = pp ; bset0.size = row*column ; bset0.format = 0 ; ll=0 ; for(jj=0;jj<column;jj++) { //each row for(ii=0;ii<row;ii++) { //each bit if(ll<bset0.size) bset0.data[ll++] = (datain.data[jj*nx+ii]>=8) ? 1 : 0 ; } //each bit } //each row ///////////////////////////////////////////////////////// //remove padding bset0 = extract_binaryset( bset0, btc_parameters[fec_code_type-7][4] + btc_parameters[fec_code_type-7][5], bset0.size-btc_parameters[fec_code_type-7][4] - btc_parameters[fec_code_type-7][5]) ; } //allocated free ( datain.data ) ; bset0 = binary2byte( bset0 ) ; return ( bset0 ) ;} //turbo_decoder
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -