📄 convolution_encoder.c
字号:
/*****************************************************************************//* FIle Name : convolution_encoder.c *//* Description : WiMax OFDM FEC convolution_encoder for Encoder *//* g0=171o g1=133o *//* Rate 0:1/2 1:2/3 2:3/4 4:5/6 *//* author : miffie *//* Date : nov/01/05 *//* Copyright (c) 2005 miffie All rights reserved. *//*****************************************************************************/char conv_enc ( char shifter ) {//output[0] g0// [1] g1char tmp1, tmp2 ; //g1=171o tmp1 = (shifter &0x1) ; tmp1 ^= ((shifter>>1) &0x1) ; tmp1 ^= ((shifter>>2) &0x1) ; tmp1 ^= ((shifter>>3) &0x1) ; tmp1 ^= ((shifter>>6) &0x1) ; //g0=133o tmp2 = (shifter &0x1) ; tmp2 ^= ((shifter>>2) &0x1) ; tmp2 ^= ((shifter>>3) &0x1) ; tmp2 ^= ((shifter>>5) &0x1) ; tmp2 ^= ((shifter>>6) &0x1) ; tmp1 = tmp1 + ((tmp2&0x1)<<1) ; //printf("shifter=%x tmp1=%x\n", shifter, tmp1 ) ; return (tmp1) ;} //conv_encstruct binaryset convolution_encoder (struct binaryset datain, char rate) {int ii ;int size_p ; //size for puncturedchar shifter ;char tmp1, tmp2 ;char *p , *q;struct binaryset bset0 ; //Main if ((q = (char *)malloc(2*datain.size*sizeof(char)) ) == NULL) { PRINTF( " malloc failed in convolution_encoder.c\n") ; } //fail else { //allocated PRINTF( "convolution_encoder.c size=0x%x coding_rate=%d\n", datain.size, rate) ; p = datain.data ; bset0.format = 0 ; //a bit bset0.size = 2*datain.size ; // bset0.data = q ; // shifter =0 ; ///////////////////////////////////////// //convolution encode k=7 g0=171o g1=133o ///////////////////////////////////////// for(ii=0;ii<datain.size;ii++) { //for shifter = (shifter<<1) + *p++ ; tmp1 = conv_enc (shifter) ; *q++ = tmp1 &0x1 ; //g0 *q++ = (tmp1>>1) &0x1 ; //g1 } //for //print_binaryset( bset0 ) ; ///////////////////////////////////////////// //puncturing Rate 0:1/2 1:2/3 2:3/4 3:5/6 ///////////////////////////////////////////// p=bset0.data ; q=bset0.data ; size_p=0 ; switch ( rate ) {//switch case 1: { //2/3 for (ii=0;ii<bset0.size;ii++) { //for if ((ii%4)!=2) { *q++ = *p ; size_p++ ; } p++ ; //increment every ii } //for break ; } //2/3 case 2: { //3/4 for (ii=0;ii<bset0.size;ii++) { //for if (((ii%6)!=2)&&((ii%6)!=5)) { *q++ = *p ; size_p++ ; } //printf("%d/6 = %d %x\n", ii,(ii%6), *p ) ; p++ ; //increment every ii } //for break ; } //3/4 case 3: { //5/6 for (ii=0;ii<bset0.size;ii++) { //for if (((ii%10)!=2)&&((ii%10)!=5)&&((ii%10)!=6)&&((ii%10)!=9)) { *q++ = *p ; size_p++ ; } //printf("%d/6 = %d %x\n", ii,(ii%6), *p ) ; p++ ; //increment every ii } //for break ; } //5/6 default : { //1/2 size_p = bset0.size ; break ; } //1/2 }//switch bset0.size = size_p ; // } //allocated free ( datain.data ) ; return ( bset0 ) ;} //convolution_encoder
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -