《信道编码的纠错原理》由会员分享,可在线阅读,更多相关《信道编码的纠错原理(38页珍藏版)》请在金锄头文库上搜索。
1、信道编码的纠错原理:根据一定的规律在待发送的信息码元中人为的加入一些冗余码元,这些冗余码元与信息码元之间以某种确定的规则相互关联(约束) 。在接收端按照既定的规则检验信息码元与监督码元之间的关系。如果传输过程出错,则信息码元与监督码元之间的关系将受到破坏,从而可以发现错误乃至纠正错误。 Turbo 码是一种性能极好,接近 Shannon 极限的信道编码方案。其常见的 译码方式有四种:MAP,LOG-MAP,MAX-LOG-MAP,SOVA,LOG-MAP 算 法是 MAP 算法的对数域实现,本质上和 MAP 算法是完全一样的,MAX-LOG- MAP 算法是 LOG-MAP 算法的近似实现,相
2、比 MAP 算法而言,它的性能只有 很小的降低,但是译码的复杂度会大大的降低,因此,实际中常常使用的是 MAX-LOG-MAP 译码算法。 #include #include #define mm 4 /* RS code over GF(2*4) - change to suit */ #define nn 15 /* nn=2*mm -1 length of codeword */ #define tt 3 /* number of errors that can be corrected */ #define kk 9 /* kk = nn-2*tt */ int pp mm+1 = 1
3、, 1, 0, 0, 1 ; /* specify irreducible polynomial coeffts */ int alpha_to nn+1, index_of nn+1, gg nn-kk+1 ; int recd nn, data kk, bb nn-kk ; void generate_gf() register int i, mask ; mask = 1 ; alpha_tomm = 0 ; for (i=0; i= 1 ; for (i=mm+1; i= mask) alpha_toi = alpha_tomm (alpha_toi-1mask)0; j-) if (
4、ggj != 0) ggj = ggj-1 alpha_to(index_ofggj+i)%nn ; else ggj = ggj-1 ; gg0 = alpha_to(index_ofgg0+i)%nn ; /* gg0 can never be zero */ /* convert gg to index form for quicker encoding */ for (i=0; i=0; i-) feedback = index_ofdataibbnn-kk-1 ; if (feedback != -1) for (j=nn-kk-1; j0; j-) if (ggj != -1) b
5、bj = bbj-1alpha_to(ggj+feedback)%nn ; else bbj = bbj-1 ; bb0 = alpha_to(gg0+feedback)%nn ; else for (j=nn-kk-1; j0; j-) bbj = bbj-1 ; bb0 = 0 ; void decode_rs() register int i,j,u,q ; int elpnn-kk+2nn-kk, dnn-kk+2, lnn-kk+2, u_lunn-kk+2, snn-kk+1 ; int count=0, syn_error=0, roottt, loctt, ztt+1, err
6、nn, regtt+1 ; /* first form the syndromes */ for (i=1; i error */ si = index_ofsi ; if (syn_error) /* if errors, try and correct */ d0 = 0 ; d1 = s1 ; elp00 = 0 ; elp10 = 1 ; for (i=1; i0) q- ; /* have found first non-zero dq */ if (q0) j=q ; do j- ; if (dj!=-1) ; if (lulq+u-q) lu+1 = lu ;else lu+1
7、= lq+u-q ; /* form new elp(x) */ for (i=0; i tt errors and cannot solve */ for (i=0; itt hence cannot solve */ for (i=0; i no errors: output received codeword */ for (i=0; i #include “mex.h“void initiate(); int calc_state_transition(const int instate,const int input,int *parity); void initiate_rsc_t
8、able(); void createinterleave_large(int size); int mrab1(int a,int b,int* r); void createinterleave(int size); int gcd(int a,int b); void interleave(int *in_rsc2,int size); void deinterleave(int *in_rsc1,int size); void encode_tail(int *input,int *tail,int *parity_bits); void freemem();int K=4; int
9、m=3; int gen_pol_rev2=11,15; int Nstates; int N; int constraint_length;int *interleavearray; int *deinterleavearray;int *state_trans; int *rev_state_trans;int *output_parity; int *rev_output_parity;int *tail1,*tail2,*parity1,*parity2;void tx_turbo_code(double *infor_bit,double *bit_coded,int bit_inl
10、ength,int bit_outlength,double rate) int i; N=bit_inlength; int *infor,*coded_infor;infor=new intN; coded_infor=new intbit_outlength; for(i=0;i5114) createinterleave_large(N); else createinterleave(N); initiate_rsc_table();encode_tail(infor,tail1,parity1);interleave(infor,N); encode_tail(infor,tail2
11、,p arity2); deinterleave(infor,N); if(rate=1/3.0) for(i=0;i1; in=in input;parity_temp = (instate 1; *parity=parity_bit; return in+(instate MAX_INTERLEAVER_SIZE)mexErrMsgTxt(“wcdma_turbo_in terleaver_sequence: The interleaver size is too large“);if(interleaver_size =40) v = rootsi;break; if ( ( doubl
12、e(p) - double(K)/double(R) ) = 0.0 ) if ( ( double(p) - 1.0 - double(K)/double(R) ) = 0.0 ) C = p-1; else C = p; else C = p+1;s = new intp-1; s0 = 1;for (i=1; i6) break; static int Pat120 = 19,9,14,4,0,2,5,7,12,18,10,8,13,1 7,3,1,16,6,15,11;static int Pat220 = 19,9,14,4,0,2,5,7,12,18,16,13,1 7,15,3,
13、1,6,11,8,10;static int Pat310 = 9,8,7,6,5,4,3,2,1,0;static int Pat45 = 4,3,2,1,0;if (K=3211) T = Pat1; else if (K=3161) T = Pat2; else if (K=2481) T = Pat1; else if (K=2281) T = Pat2; else if (K=531) T = Pat1; else if (K=481) T = Pat3; else if (K=201) T = Pat1; else if (K=160) T = Pat3; else T = Pat
14、4;r=new intR;for (j=0; j0) q = u / v;t = u - v*q;u = v;v = t; return(u); void mexFunction(int nlhs,mxArray *plhs,int nrhs,const mxArray *prhs) int mex_inlength,mex_outlength; int mex_m; double *mex_bit_data,*mex_bit_codeded;double mex_rate; if(nrhs!=3) mexErrMsgTxt(“ 2 inputs required.the one is a v
15、ector,the other is rate,the last is constraintlength“); if(nlhs!=1) mexErrMsgTxt(“ there is only one output. it is coded vector.“); mex_bit_data=mxGetPr(prhs0);mex_rate=mxGetScalar(prhs 1);constraint_length=(int)mxGetScal ar(prhs2); mex_inlength=mxGetN(prhs 0); mex_m=constraint_length-1;if(mex_rate=1/3.0)mex_outlength=3*mex_inle ngth+4*mex_m;plhs0=mxCreateDoubleMatrix( 1,mex_outlength,mxREAL); if(mex_rate=1/2.