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

📄 turboproduct.c

📁 这个文件包括wimax中所有的编解码源代码
💻 C
字号:
/*****************************************************************************//*   FIle Name : turboproduct.c                                              *//*   Description : WiMax OFDM FEC turbo Product code for Encoder             *//*   author : miffie                                                         *//*   Date   : Nov/16/05                                                      *//*   Copyright (c) 2005 miffie   All rights reserved.                        *//*****************************************************************************///Parity calculation with LinearFeedbackShiftRegisterchar lfsr ( char type , char datain, char shifter ) {char check , tmp1 ;     if(type==3)  { //x^6+x+1             tmp1 = ((datain^(shifter>>5)) &0x1) ;             check = (tmp1) ? ((shifter^0x01)<<1) + tmp1 :                    (shifter<<1) ;             check &= 0x3f ;     } //x^6+x+1     else if (type==2) { //x^5+x^2+1             tmp1 = ((datain^(shifter>>4)) &0x1) ;             check = (tmp1) ? ((shifter^0x02)<<1) + tmp1 :                    (shifter<<1) ;             check &= 0x1f ;     }  //x^5+x^2+1     else if (type==1) { //x^4+x^1+1             tmp1 = ((datain^(shifter>>3)) &0x1) ;             check = (tmp1) ? ((shifter^0x01)<<1) + tmp1 :                    (shifter<<1) ;             check &= 0x0f ;     }  //x^4+x^1+1     else { //x^3+x^1+1             tmp1 = ((datain^(shifter>>2)) &0x1) ;             check = (tmp1) ? ((shifter^0x01)<<1) + tmp1 :                    (shifter<<1) ;             check &= 0x07 ;     }  //x^3+x^1+1     //printf("shifter=%x datain=%x check=%x\n", shifter, datain , check ) ;     return ( check ) ;} //lfsrstruct binaryset turboproduct (struct binaryset datain,                               char fec_code_type, char Nsub ) {//input format must be 1 int 	ii , jj , kk ;char 	tmp1 , tmp2 , shifter, parity ;char    nx, ny ;char	*qq;struct binaryset bset0 , bset1 ;char    rowtype, columntype ;char  row, column ;//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  Q char  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 ;    //build BTC    if ((qq = (char *)malloc((nx*ny)*sizeof(char)) ) == NULL) {        PRINTF( " malloc failed in turboproduct.c\n") ;    } //fail    else { //allocated       PRINTF( "turboproduct.c size=%x\n", datain.size ) ;       bset0  = byte2binary( datain ) ;       bset1 = pad_binaryset ( btc_parameters[fec_code_type-7][4] +                             btc_parameters[fec_code_type-7][5] ) ;       bset1 = cat_binaryset( bset1, bset0 ) ;       bset0.format = 0 ; //a bit       bset0.size = nx * ny  ; //       bset0.data = qq ; //       //row encoder       for(jj=0;jj<column;jj++) { //each  row          printf("\n Row%d encoding..\n", jj) ;         shifter = 0 ; //Linear Feedback Shift Register         parity = 0 ;         //data         for(ii=0;ii<row;ii++) { //each bit           kk=jj*row + ii ;           if (kk <bset1.size)               *qq = bset1.data[kk] & 0x1 ;           else *qq = 0 ; //padding           //printf("(%d %d) " , jj, ii ) ;           shifter = lfsr(rowtype, *qq, shifter ) ;           parity ^= *qq &0x1 ;           *qq++ ;         } //each bit         //checks           if (rowtype<4) { //lfsr            tmp1= nx-row-1 ;             for(ii=0;ii<tmp1;ii++) { //each bit             *qq = (shifter>>(tmp1-1-ii)) & 0x1 ;             parity ^= *qq &0x1 ;             *qq++ ;            } //each bit          } //lfsr         //overall parity         *qq++ = parity ;       } //each row       /////////////////////////////////////////////////////////       //column encoder       for(jj=0;jj<nx;jj++) { //each  column          printf("\n Column%d encoding..\n", jj) ;         shifter = 0 ; //Linear Feedback Shift Register         parity = 0 ;         //data         for(ii=0;ii<column;ii++) { //each bit           kk=ii*nx + jj ;           //printf("(%d %d) kk=%d " , jj, ii , kk ) ;           tmp2 =  bset0.data[kk] & 0x1 ;           shifter = lfsr(columntype, tmp2, shifter ) ;           parity ^= tmp2 &0x1 ;         } //each bit         //checks          if (columntype<4) { //lfsr           tmp1= nx-row-1 ;            for(ii=0;ii<tmp1;ii++) { //each bit             bset0.data[jj+(column+ii)*nx] = (shifter>>(tmp1-1-ii)) & 0x1 ;             parity ^= bset0.data[jj+(column+ii)*nx] &0x1 ;           } //each bit         } //lfsr         //overall parity         bset0.data[jj+(column+tmp1)*nx]  = parity ;       } //each column       //remove B individual bits from the first row       bset0 = extract_binaryset ( bset0, btc_parameters[fec_code_type-7][4],                                           nx*ny-btc_parameters[fec_code_type-7][4] ) ;    } //allocated    //free ( datain.data ) ;    return ( bset0 ) ;} //turboproduct

⌨️ 快捷键说明

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