www.pudn.com > Golay-new.rar > withoutECC.cpp
#include#include #include #define znew (z=36969*(z&65535)+(z>>16)) #define wnew (w=18000*(w&65535)+(w>>16)) #define MWC ((znew<<16)+wnew ) #define SHR3 (jsr^=(jsr<<17), jsr^=(jsr>>13), jsr^=(jsr<<5)) #define CONG (jcong=69069*jcong+1234567) #define KISS ((MWC^CONG)+SHR3) #define UNI (KISS*2.328306e-10) typedef unsigned long UL; /* Global static variables: */ static UL z=362436069, w=521288629, jsr=123456789, jcong=380116160; //Generate Gaussian distributed random variates double G(double U,double S2) { double U1,U2,V1,V2,W,Y,X1,X2; do{ U1=UNI; U2=UNI; V1=2*U1-1; V2=2*U2-1; W=V1*V1+V2*V2; }while(W>1); Y=sqrt((-2*log(W)/W)); X1=V1*Y; X2=V2*Y; X1=X1*sqrt(S2)+U;X2=X2*sqrt(S2)+U; return X1; } /* Function to compute the Hamming weight of a 12-bit integer */ int weight(int vector) { int i, aux; aux = 0; for (i=0; i<12; i++) if ( (vector>>i)&1 ) aux++; return(aux); } void main() { int t,r; //t:every 12 bits transmited; r:every 12 bits received int i; int weight(int vector); int ebno,loop; int errbit; //errbit:without ECC double ber,attn,sigma;//ber:without ECC int code[24],decode[24]; double mocode[24]; //long seed; cout<<"Caculating BER over AWGN channel (without ECC)"< >i)&0x001; mocode[i]=2*code[i]-1; } /*--------------------- AWGN channel --------------------*/ for(i=0;i<12;i++) { mocode[i]=mocode[i]+G(0,1)*sigma; } /* --------------------- BPSK demodulation ------------------------- */ for(i=0;i<12;i++) { if(mocode[i]>=0) { decode[i]=1; } else { decode[i]=0; } } /* ---------------------- Received word --------------------------- */ //r[0] = c[0]^e[0]; //r[1] = c[1]^e[1]; r=0; for(i=0;i<=11;i++) { r+=pow(2,i)*decode[i]; } errbit+=weight(t^r); loop++; }//while end /*--------------------Caculate ber and output------------------------------*/ ber=errbit/(12.0*loop); cout<<"ebno="<