📄 main_partstest.c
字号:
/*****************************************************************************//* FIle Name : main.c *//* Description : WLAN FEC scrambler for Encoder/Decoder *//* S(x) = x^7 + x^4 + 1 ; *//* author : miffie *//* Date : aug/04/05 *//* Copyright (c) 2005 miffie All rights reserved. *//*****************************************************************************/#include <stdio.h>#include <math.h>struct binaryset { int size ; char format ; //0:binary(1bit) 1:byte(8bit) char *data ;} ;struct complex { double realp ; //real part double image ;} ;struct complexset { int size ; struct complex *data ;} ;struct complex multiply_complex( struct complex a, struct complex b ) {struct complex product ; product.realp = a.realp*b.realp - a.image*b.image ; product.image = a.realp*b.image + a.image*b.realp ;return (product) ;} //multiply_complexvoid print_complexset(struct complexset datain ) { struct complex *p ;int ii ; PRINTF("print_complexset size=%d\n", datain.size ) ; p = datain.data ; ii = 0 ; for( ii=0;ii<datain.size;ii++) {//for PRINTF("%d %f + j * %f\n", ii, p->realp, p->image ) ; p++ ; } //for}//print_complexset struct binaryset read_hexfile(char *fname ) { FILE *fp ;char *p ;char *top ;int size ;struct binaryset bset ; if ((fp = fopen( fname, "r" ))==NULL) { //not opened PRINTF("file %s cannot be opened\n", fname ) ; }//not opened else { //opened PRINTF(" %s opend\n" , fname) ; //1000 byte can be read from a file if ((top = (char *)malloc(1000*sizeof(char)) ) == NULL) { PRINTF( " malloc failed in read_hexfile\n") ; } //fail else { //allocated p = top ; size = 0 ; while( fscanf( fp, "%x", p)!=EOF ) {//while size++ ; PRINTF("%d %x \n", size, *p ) ; p++ ; }//while p = NULL ; //the Last byte } //allocated } //opened if (((char *)realloc(top,(size+1)*sizeof(char)) ) == NULL) { PRINTF( " realloc failed in read_hexfile\n") ; } //fail bset.format =1 ; bset.size = size ; bset.data = top ; return(bset) ;}//read_hexfile struct binaryset byte2binary(struct binaryset datain) { char *p , *q ;char *top ;int ii ,jj ;int size ;struct binaryset bset ; //size is number of byte PRINTF(" byte2binary size = %d\n" , datain.size ) ; if ((top = (char *)malloc(datain.size*8*sizeof(char)) ) == NULL) { PRINTF( " malloc failed in byte2binary\n") ; } //fail else { //allocated p = datain.data ; q = top ; for (jj=0;jj<datain.size;jj++) { //for //LSBfirst for (ii=0;ii<8;ii++) { //for *q++ = ((*p>>ii) & 0x1) ; } //for ii p++ ; }//for jj bset.format = 0 ; bset.size = datain.size*8 ; bset.data = top ; } //allocated return(bset) ;}//byte2binary void print_binaryset(struct binaryset datain ) { char *p ;int ii ; PRINTF("print_binaryset format=%d size=%d\n", datain.format, datain.size ) ; p = datain.data ; ii = 0 ; for( ii=0;ii<datain.size;ii++) {//for PRINTF("%d %x\n", ii, *p ) ; p++ ; } //for}//print_binaryset struct binaryset pad_binaryset(int size ) { //pad_binaryset //size is the number of bitstruct binaryset bset ;char *tmp1, *tmp2 ;int ii ; if ((tmp1 = (char *)malloc(size*sizeof(char)) ) == NULL) { PRINTF( " malloc failed in pad_binaryset\n") ; } //fail else { //allocated //bset1 for padding bit bset.format = 0 ; //a binary bset.size = size ; // bset.data = tmp1 ; // tmp2 = tmp1 ; for (ii=0;ii<size;ii++) {//for *tmp2++ = 0 ; } //for } //allocated return( bset ) ;}//pad_binaryset struct binaryset cat_binaryset(struct binaryset data1, struct binaryset data2) { char *p , *q ;char *top ;int ii ,jj ;int size ;struct binaryset bset ; //size is number of bit size = data1.size + data2.size ; if ((top = (char *)malloc(size*sizeof(char)) ) == NULL) { PRINTF( " malloc failed in cat_binaryset\n") ; } //fail else { //allocated p = data1.data ; q = top ; for (jj=0;jj<data1.size;jj++) { //for *q++ = *p++ ; }//for jj p = data2.data ; for (jj=0;jj<data2.size;jj++) { //for *q++ = *p++ ; }//for jj bset.format = 0 ; bset.size = size ; bset.data = top ; } //allocated return(bset) ;}//cat_binarysetstruct binaryset extract_binaryset(struct binaryset datain, short offset, short size ) {struct binaryset bset ;char *tmp ;short ii ;//extract_binaryset does not change "format" if ((offset+size) > datain.size ) { //error bset.size = 0 ; bset.data = NULL ; } //error else { //ok tmp = datain.data ; bset.size = size ; bset.data = &datain.data[ offset ] ; } //ok //printf("extract_binaryset offset=%d size=%d\n", offset, bset.size) ; return(bset) ;}//extract_binarysetstruct binaryset fec_noise(struct binaryset datain, char level ) { char *p ;int ii ; PRINTF("fec_noise\n", datain.size ) ; p = datain.data ; ii = 0 ; for( ii=0;ii<datain.size;ii++) {//for *p++ = *p*0xf; //No noise } //for return( datain ) ;}//fec_noise #include "scrambler.c"#include "convolution_encoder.c"#include "interleaver.c"#include "../fec_dec/deinterleaver.c"#include "../fec_dec/depuncturing.c"#include "../fec_dec/viterbi.c"#include "../ofdm_enc/mapper.c"#include "../ofdm_enc/idft64.c"main() { //main int ii ;struct binaryset bset0,bset1 ;struct complexset cset0, cset1 ;char shifter ;char *tmp1 , *tmp2 ;char *the_message = "Joy, bright spark of divinity,Daughter of Elysium,Fire-insired we tread Thy sanctualy.The magic power re-unites All that custom has divided, All men become brothers Under the sway of the gentle wings.." ; //Main //tmp1 = the_message ; //while (*tmp1 != '\0') { //while // PRINTF("%x\n", *tmp1++ ) ; //} //while //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) ; //The message(PSDU) bset0 = read_hexfile("the_message.dat") ; bset0 = byte2binary(bset0) ; //concatinate SERVICE & PSDU bset0 = cat_binaryset(bset1, bset0) ; //Tail bit + pad bit bset1 = pad_binaryset(6+42) ; //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 ) ; //COmpare with Table G.16 &G.17 for scrambling print_binaryset( bset0 ) ; //Convolution encoder bset0 = convolution_encoder(bset0 , 2 ) ; //rate 2:3/4 //COmpare with Table G.18 for convolution encoder print_binaryset( bset0 ) ; //interleaver //Ncbps=192 //Nbpsc=4 bset1 = extract_binaryset(bset0 , 0, 192 ) ; //Ncbps=192 bset1 = interleaver(bset1 , 4 ) ; //Nbpsc=4 //Compare with Table G.21 for interleaved bits print_binaryset( bset1 ) ; //OFDM mapper cset0 = mapper (bset1, 4, 1) ; //Nbpsc=4, pilot_polarity=1 //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 ) ; //add Noise for FEC Decoder Test bset1 = fec_noise(bset1 , 0x0 ) ; //deinterleaver //Ncbps=192 //Nbpsc=4 bset1 = deinterleaver(bset1 , 4 ) ; //Nbpsc=4 //Compare with Table G.18 for deinterleaved data print_binaryset( bset1 ) ; //depuncturing bset1 = depuncturing(bset1 , 2 ) ; //rate 2:3/4 // print_binaryset( bset1 ) ; //viterbi decoder bset1 = viterbi(bset1) ; // print_binaryset( bset1 ) ;} //main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -