📄 data_enc.c
字号:
/*****************************************************************************//* FIle Name : data_enc.c *//* Description : WLAN DATA symbols Encoder *//* S(x) = x^7 + x^4 + 1 ; *//* author : miffie *//* Date : aug/09/05 *//* Copyright (c) 2005 miffie All rights reserved. *//*****************************************************************************/struct complexset data_enc(struct binaryset datain, char RATE , short LENGTH, char pilot_shifter) { //main struct binaryset bset0,bset1 ;struct complexset cset0, cset1 ;struct complexset ctop ;struct complex ctmp1, ctmp2 ;char *tmp1 , *tmp2 ;char Nbpsc, coding_rate ;short Ncbps, Ndbps, Nsym, Ndata, Npad ;int ii ;// Rate(Mbps) RATE(R1-R4) Coding_Rate Modulation Nbpsc Ncbps Ndbps// 6 1101 0:1/2 BPSK 1 48 24 // 9 1111 2:3/4 BPSK 1 48 36 // 12 0101 0:1/2 QPSK 2 96 48 // 18 0111 2:3/4 QPSK 2 96 72 // 24 1001 0:1/2 QAM16 4 192 96 // 36 1011 2:3/4 QAM16 4 192 144 // 48 0001 1:2/3 QAM64 6 288 192 // 54 0011 2:3/4 QAM64 6 288 216 //Main switch ( RATE ) { //switch case 0xb: { //6Mbps Nbpsc = 1 ; coding_rate = 0 ; Ncbps = 48 ; Ndbps = 24 ; break ; } case 0xf: { //9Mbps Nbpsc = 1 ; coding_rate = 2 ; Ncbps = 48 ; Ndbps = 36 ; break ; } case 0xa: { //12Mbps Nbpsc = 2 ; coding_rate = 0 ; Ncbps = 96 ; Ndbps = 48 ; break ; } case 0xe: { //18Mbps Nbpsc = 2 ; coding_rate = 2 ; Ncbps = 96 ; Ndbps = 72 ; break ; } case 0x9: { //24Mbps Nbpsc = 4 ; coding_rate = 0 ; Ncbps = 192 ; Ndbps = 96 ; break ; } case 0xd: { //36Mbps Nbpsc = 4 ; coding_rate = 2 ; Ncbps = 192 ; Ndbps = 144 ; break ; } case 0x8: { //48Mbps Nbpsc = 6 ; coding_rate = 1 ; Ncbps = 288 ; Ndbps = 192 ; break ; } case 0xc: { //54Mbps Nbpsc = 6 ; coding_rate = 2 ; Ncbps = 288 ; Ndbps = 216 ; break ; } } //switch //Nsym , Ndata, Npad Nsym = (16 + 8* LENGTH +6+ Ndbps-1)/Ndbps ; Ndata = Nsym * Ndbps ; Npad = Ndata - ( 16 + 8*LENGTH + 6 ) ; //Make DATA bits //SERVICE field if ((tmp1 = (char *)malloc(2*sizeof(char)) ) == NULL) { PRINTF( " malloc failed in SERVICE\n") ; } //fail else { //allocated //bset1 for SERVICE field bset1.format = 1 ; //a byte octet bset1.size = 2 ; //a byte octet bset1.data = tmp1 ; // tmp2 = tmp1 ; *tmp2++ = 0 ; //first byte *tmp2++ = 0 ; //second byte } //allocated bset1 = byte2binary(bset1) ; //concatinate SERVICE & PSDU bset0 = cat_binaryset(bset1, datain) ; //Tail bit + pad bit bset1 = pad_binaryset(6+Npad) ; //concatinate (SERVICE & PSDU) & (tail&pad bit) bset0 = cat_binaryset(bset0, bset1) ; //COmpare with Table G.13 &G.14 for DATA bits //print_binaryset( bset0 ) ; //Scrambler bset0 = scrambler(bset0 , 0x5d ) ; //Tail bit locations are zeroed (please see p69 G.5.2) for (ii=0;ii<6;ii++) { //zeroed bset0.data[ 16 + 8*LENGTH + ii ] = 0 ; } //zeroed //Compare with Table G.16 &G.17 for scrambling //print_binaryset( bset0 ) ; //Convolution encoder bset0 = convolution_encoder(bset0 , coding_rate ) ; //rate 2:3/4 //Compare with Table G.18 for convolution encoder //print_binaryset( bset0 ) ; for(ii=0;ii<Nsym;ii++){ //every symbol PRINTF(" the %dth Symbol out of %d\n" , ii, Nsym ) ; //interleaver bset1 = extract_binaryset(bset0 , ii*Ncbps, Ncbps ) ; //Ncbps=192 bset1 = interleaver(bset1 , Nbpsc ) ; //Nbpsc=4 //Compare with Table G.21 for interleaved bits //print_binaryset( bset1 ) ; //OFDM mapper cset0 = mapper (bset1, Nbpsc, &pilot_shifter) ; //Compare with Table G.22 for Frequency Domain data print_complexset( cset0 ) ; //OFDM IFFT cset0 = idft64 ( cset0 ) ; //Compare with Table G.23 for Frequency Domain data //print_complexset( cset0 ) ; //save the first sample to ctmp1 ctmp1.realp = cset0.data[0].realp ; ctmp1.image = cset0.data[0].image ; //build a DATA symbol cset1 = extract_complexset(cset0 , 48 , 16 ) ; //Guard Interval cset1 = cat_complexset(cset1 , cset0 ) ; if (ii == 0) { //first symbol ctop = cset1 ; } //first symbol else { //others cset1.data[0].realp = (cset1.data[0].realp + ctmp2.realp)/2 ; cset1.data[0].image = (cset1.data[0].image + ctmp2.image)/2 ; ctop = cat_complexset(ctop, cset1) ; } //others ctmp2.realp = ctmp1.realp ; ctmp2.image = ctmp1.image ; } //every symbol //add the last sample cset0.size = 1 ; cset0.data = &ctmp1 ; ctmp1.realp = ctop.data[ ctop.size-64 ].realp/2 ; ctmp1.image = ctop.data[ ctop.size-64 ].image/2 ; ctop = cat_complexset(ctop, cset0) ; return( ctop ) ;} //data_enc
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -