📄 fecenc.c
字号:
/*****************************************************************************//* FIle Name : fecenc.c *//* Description : WiFi OFDM FEC Encoder *//* author : miffie *//* Date : Nov/01/05 *//* Copyright (c) 2005 miffie All rights reserved. *//*****************************************************************************/struct binaryset fecenc(struct binaryset datain , char fec_code_type , short *randomizer_seed ) { register int ii , jj ; char num_erasure ; char RR ; short KK , num_data , size ; short row, column, tmp1 ; struct binaryset bset0, bset1, bset2 , bset3; unsigned char data[256] ; short BSID = 7 ; short DIUC = 1 ; short frame_number = 1 ; // rs_cc RS_K RS_T RATE Ncpc char rs_cc[7][4] = {{ 12, 0, 0, 1 }, { 24, 4, 1, 2 }, { 36, 2, 3, 2 }, { 48, 8, 1, 4 }, { 72, 4, 3, 4 }, { 96, 6, 2, 6 }, { 108, 6, 3, 6 } } ; char btc_block[] = { 23, 35, 58, 77, 96, 120 } ; char ctc_block[] = { 24, 32, 36, 48, 72, 96, 108 } ; char Nsub = 16 ; PRINTF("fecenc fec_code_type=%d size=0x%x\n", fec_code_type , datain.size) ; ////////////////////////////////////////////////////////////////////////////// // randomization ////////////////////////////////////////////////////////////////////////////// print_binaryset(datain) ; bset0 = byte2binary_MSB( datain ) ; bset0 = randomizer( bset0 , randomizer_seed ) ; //only accept format= 0 (binary); bset0 = binary2byte_MSB( bset0 ) ; bset3 = pad_binaryset( 1 ) ; //tail byte for convolution encoder bset0 = cat_binaryset( bset0, bset3 ) ; print_binaryset(bset0) ; ////////////////////////////////////////////////////////////////////////////// // Outer Code ( Reed-Solomon) ////////////////////////////////////////////////////////////////////////////// /* encode data[] to produce parity in bb[]. Data input and parity output is in polynomial form */ //KK= NN-RR ; //number of data inputs to encoder if(fec_code_type==0) { //BPSK bset2.size = bset0.size ; bset2.format = bset0.format ; bset2.data = bset0.data ; } //BPSK else if(fec_code_type<=6) { //RS bset2.size= 0 ; bset2.format= 1 ; //Byte size=bset0.size ; while (size >0 ) { //while if ( size > rs_cc[fec_code_type][0] ) { //fixed size bset1 = extract_binaryset( bset0, bset0.size-size, rs_cc[fec_code_type][0] ) ; bset1 = encode_rs(bset1, rs_cc[fec_code_type][1]*2 ) ; print_binaryset( bset1 ) ; bset2 = cat_binaryset( bset2, bset1 ) ; size -= rs_cc[fec_code_type][0] ; } else {//lastword bset1 = extract_binaryset( bset0, bset0.size-size, size ) ; bset3 = pad_binaryset( rs_cc[fec_code_type][0]-size ) ; //stuff bytes //bset1 = cat_binaryset( bset1, bset3 ) ; bset1 = encode_rs(bset1, rs_cc[fec_code_type][1]*2 ) ; //bset1.data[0] = 0x49 ; //bset1.data[1] = 0x31 ; //bset1.data[2] = 0x40 ; //bset1.data[3] = 0xbf ; print_binaryset( bset1 ) ; bset2 = cat_binaryset( bset2, bset1 ) ; size = 0 ; } //lastword } //while } //RS else if(fec_code_type<=12) { //BTC size=0 ; bset2.size= 0 ; bset2.format= 1 ; //Byte while (size < bset0.size ) { //while if ((bset0.size-size)<btc_block[fec_code_type-7]) {//shortened //This process is not the way written in p435 of 802.16.2004 //The way is the spec does not make sense to me , because //No way for the decoder to get Ix,Iy,B,Q parameters. bset1 = pad_binaryset( btc_block[fec_code_type-7] -(bset0.size-size) ) ; bset1.format =1 ; //Byte for(ii=0;ii<bset1.size;ii++) bset1.data[ii]=0xff ; //Stuff bset0 = cat_binaryset (bset0, bset1 ) ; }//shortened bset1 = extract_binaryset( bset0, size, btc_block[fec_code_type-7] ) ; bset1 = turboproduct(bset1, fec_code_type, Nsub ) ; bset2 = cat_binaryset( bset2, bset1 ) ; size += btc_block[fec_code_type-7] ; } //while }//BTC else { //CTC size=0 ; bset2.size= 0 ; bset2.format= 1 ; //Byte while (size < bset0.size ) { //while if ((bset0.size-size)<ctc_block[fec_code_type-13]) {//shortened bset1 = pad_binaryset( ctc_block[fec_code_type-13] -(bset0.size-size) ) ; bset1.format =1 ; //Byte for(ii=0;ii<bset1.size;ii++) bset1.data[ii]=0xff ; //Stuff bset0 = cat_binaryset (bset0, bset1 ) ; }//shortened bset1 = extract_binaryset( bset0, size, ctc_block[fec_code_type-13] ) ; bset1 = ctc_encoder(bset1, fec_code_type, Nsub ) ; bset2 = cat_binaryset( bset2, bset1 ) ; size += ctc_block[fec_code_type-13] ; } //while }//CTC print_binaryset(bset2) ; ////////////////////////////////////////////////////////////////////////////// // Inner Code ////////////////////////////////////////////////////////////////////////////// if (fec_code_type<=6) { bset2 = byte2binary_MSB( bset2 ) ; print_binaryset( bset2 ) ; bset2 = convolution_encoder(bset2, rs_cc[fec_code_type][2]) ; print_binaryset( bset2 ) ; } return( bset2 ) ;} //fecenc
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -