循环编码.doc

上传人:wj 文档编号:675569 上传时间:2023-04-29 格式:DOC 页数:15 大小:237KB
下载 相关 举报
循环编码.doc_第1页
第1页 / 共15页
循环编码.doc_第2页
第2页 / 共15页
循环编码.doc_第3页
第3页 / 共15页
循环编码.doc_第4页
第4页 / 共15页
循环编码.doc_第5页
第5页 / 共15页
循环编码.doc_第6页
第6页 / 共15页
循环编码.doc_第7页
第7页 / 共15页
循环编码.doc_第8页
第8页 / 共15页
循环编码.doc_第9页
第9页 / 共15页
循环编码.doc_第10页
第10页 / 共15页
循环编码.doc_第11页
第11页 / 共15页
循环编码.doc_第12页
第12页 / 共15页
循环编码.doc_第13页
第13页 / 共15页
循环编码.doc_第14页
第14页 / 共15页
循环编码.doc_第15页
第15页 / 共15页
亲,该文档总共15页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

循环编码.doc

《循环编码.doc》由会员分享,可在线阅读,更多相关《循环编码.doc(15页珍藏版)》请在冰点文库上搜索。

循环编码.doc

汕头大学工学院

三级项目报告

课程名称:

信息论与编码          

课程题目:

 循环码的编码和译码程序设计

指导教师:

唐雅娟

系别:

电子工程系  专业:

电子信息工程  

学生姓名:

曾煌冠  

学号:

09141014

完成时间:

2012年5月4日至5月14日

成绩:

评阅人:

唐雅娟

循环码的编码和译码程序设计

一.循环码编码和译码原理简介:

1.RS循环码编码原理与特点:

首先令和分别表示信息多项式与校验多项式,则一个RS码的多项式表达式为:

如果为一个码字,则它必须为生成多项式的位数,即:

编码的过程就是从和中寻找,它可通过除法算法来完成。

即用除以得到:

(1式)

同时令=-,则有。

2.RS循环码译码原理与特点:

(1)能纠正t个符号差错的(n,k)RS码,数据段中包含k个信息符号和2t个校验符号。

设存贮器系统数据输出的多项式(妈接收字多项式)可以表达为,差错图样多项式为,纠错后的码多项式为,伴随式多项式为,差错定位多项式为。

3.RS循环码的基本步骤及实现循环码的程序流程图:

信源

分帧

Rs(7,3)编码

BPSK调制

AWGN信道

BPSK解调

Rs(7,3)译码

合帧

误码率计算

4.主要源程序:

/*输入的信息元:

m(x)*/

voidinformation_element(unsignedcharmx[K])

{

unsignedchartem;

srand((unsigned)time(0));

for(unsignedinti=0;i

tem=rand()%6+1;

if(tem==1) mx[i]='a';

else mx[i]=tem+48;

}

}

/*确定被除数:

x^(n-k)m(x)*/

voidcount_dividend(unsignedchardividend[],unsignedcharmx[])

{ for(inti=0;i

if(i>=K) { dividend[i]='0';

continue; }

dividend[i]=mx[i];

}

}

/*gx各项乘以被除数的第一项系数;注意:

符号'0'的ASCII码为48*/

voidfor_mod2(unsignedchartem[],unsignedcharc)

{ unsignedinti;

switch(c)

{ case'1':

for(i=0;i<5;i++) tem[i]=gx[i];

break;

case'a':

for(i=0;i<5;i++){

if(gx[i]=='1') tem[i]='a';

elseif(gx[i]=='a') tem[i]='2';

else tem[i]=gx[i]+1;

}

break;

default:

for(i=0;i<5;i++)

{ if(gx[i]=='1') tem[i]=c;

elseif(gx[i]=='a') tem[i]=(int)c+1;

else tem[i]=(int)gx[i]+(int)c-48;

}

break;

}

/*应用课本第153页的表6-7的关系式转换*/

for(i=0;i<5;i++)

{ if(tem[i]=='8') tem[i]='a';

if(tem[i]>'8'&&tem[i]!

='a') tem[i]-=7;

if(tem[i]=='7') tem[i]='1';

}

}

/*与GF(2^3)扩域(课本153页)匹配*/

unsignedcharmath(unsignedcharctem[])

{

unsignedcharc='0';//当两系数相同时(即a^i+a^i=0)为0

if(ctem[0]=='0'&&ctem[1]=='0'&&ctem[2]=='1') c='1';

if(ctem[0]=='0'&&ctem[1]=='1'&&ctem[2]=='0') c='a';

if(ctem[0]=='1'&&ctem[1]=='0'&&ctem[2]=='0') c='2';

if(ctem[0]=='0'&&ctem[1]=='1'&&ctem[2]=='1') c='3';

if(ctem[0]=='1'&&ctem[1]=='1'&&ctem[2]=='0') c='4';

if(ctem[0]=='1'&&ctem[1]=='1'&&ctem[2]=='1') c='5';

if(ctem[0]=='1'&&ctem[1]=='0'&&ctem[2]=='1') c='6';

returnc;

}

/*mod2加*/

voidmod2(unsignedchardividend[],unsignedchartem[],unsignedcharremainder[])

{ unsignedintk;

for(unsignedintj=1;j<5;j++)

{ unsignedchartem1[3]; unsignedchartem2[3];

/*被除数对应到GF(2^3)扩域,增加三位都是'0'的情况*/

switch(dividend[j])

{case'1':

for(k=0;k<3;k++) tem1[k]=GF[0][k];

break;

case'a':

for(k=0;k<3;k++) tem1[k]=GF[1][k];

break;

case'0':

for(k=0;k<3;k++) tem1[k]='0';

break;

default:

unsignedintn=dividend[j]-48;

for(k=0;k<3;k++) tem1[k]=GF[n][k];

}

/*gx各项乘以被除数的第一项系数后对应到GF(2^3)扩域,增加三位都是'0'的情况*/

switch(tem[j])

{case'1':

for(k=0;k<3;k++) tem2[k]=GF[0][k];

break;

case'a':

for(k=0;k<3;k++) tem2[k]=GF[1][k];

break;

case'0':

for(k=0;k<3;k++) tem1[k]='0';

break;

default:

unsignedintm=tem[j]-48;

for(k=0;k<3;k++) tem2[k]=GF[m][k];

}

/*异或运算*/

unsignedcharctem[3];

for(k=0;k

{ if(tem1[k]==tem2[k]) ctem[k]='0';

else ctem[k]='1';}

remainder[j-1]=math(ctem);/*匹配*/

}

}

/*多项式相除*/

voidpolynomial_division(unsignedchardividend[],unsignedcharremainder[],intflag)

{

unsignedchartem[5];unsignedinti,n=5;

for(i=0;i

{

for_mod2(tem,dividend[0]);

mod2(dividend,tem,remainder);

/*准备下次除法的被除数,如果被除数的第一项为0则被除数数组左移一位,第一,二项都为0则停止*/

for(unsignedintj=0;j

dividend[4]=dividend[n++];

if(dividend[0]=='0')

{

if(dividend[1]=='0')break;

for(unsignedintk=0;k

i++;n++;

dividend[3]='0'; }

}

}

/*求余式*/

voidcount_remainder(unsignedcharremainder[R])

{

information_element(mx);unsignedchardividend[N];

count_dividend(dividend,mx);

polynomial_division(dividend,remainder,K);

}

/*RS码映射成7个二进制3bit组,对应GF表*/

voidcreate_rsc(unsignedcharrsc[],unsignedcharremainder[],unsignedcharrsc_GF[N][K])

{

unsignedinti,k;

for(i=0;i<3;i++){rsc[i]=mx[i]; }

for(i=3;i

for(i=0;i

{ switch(rsc[i])

{ case'1':

for(k=0;k<3;k++)rsc_GF[i][k]=GF[0][k];

break;

case'a':

for(k=0;k<3;k++)rsc_GF[i][k]=GF[1][k];

break;

case'0':

for(k=0;k<3;k++)rsc_GF[i][k]='0';

break;

default:

unsignedintm=rsc[i]-48;

for(k=0;k<3;k++)rsc_GF[i][k]=GF[m][k];

}

}

}

/*BPSK映射:

符号‘1’映射成‘1’,符号‘0’映射成‘-’;注意:

符号‘-’输出为‘-1’*/

voidBPSK_mapping(unsignedcharrsc_GF[N][K],unsignedcharrsc_BPSK[N][K])

{ unsignedinti,j;

for(i=0;i

{for(j=0;j

{if(rsc_GF[i][j]=='1')rsc_BPSK[i][j]='1';

elsersc_BPSK[i][j]='-';

if(rsc_BPSK[i][j]=='-') }

}

}

/*加噪声干扰*/

voidadd_noise(unsignedcharrsc_BPSK[N][K])

{ srand(unsigned(time(0)));unsignedintn1=1,n2=2;unsignedintm1=1,m2=1;

while

(1)

{

n1=rand()%7;

n2=rand()%7;

m1=rand()%3;

m2=rand()%3;

if(n1!

=n2)

break;

}//*/

/*对应的位置取反*/

if(rsc_BPSK[n1][m1]=='-') rsc_BPSK[n1][m1]='1';

else rsc_BPSK[n1][m1]='-';

if(rsc_BPSK[n2][m2]=='-') rsc_BPSK[n2][m2]='1';

else rsc_BPSK[n2][m2]='-';

}

/*解映射*/

voidde_mapping(unsignedcharrsc_BPSK[N][K],unsignedcharde_rsc[N])

{ unsignedinti,j;

for(i=0;i

{ for(j=0;j

if(rsc_BPSK[i][j]=='-')rsc_BPSK[i][j]='0';}

de_rsc[i]=math(rsc_BPSK[i]); }

}

/*匹配GF扩域*/

voidmath_GF(unsignedcharc,unsignedcharc_tem[K])

{ unsignedintk;

while

(1)

{

if(c=='8')c='a';

if(c>'8'&&c!

='a')c-=7;

if(c=='7')c='1';

if(c<'7'||c=='a')break;

}

switch(c)

{ case'1':

for(k=0;k<3;k++)c_tem[k]=GF[0][k];

break;

case'a':

for(k=0;k<3;k++)c_tem[k]=GF[1][k];

break;

case'0':

for(k=0;k<3;k++)c_tem[k]='0';

break;

default:

unsignedintm=c-48;

for(k=0;k<3;k++)c_tem[k]=GF[m][k];

}

}

/*求伴随多项式*/

unsignedcharcount_sx(unsignedcharde_rsc[N],unsignedintf)

{ unsignedchartem='0',result='0';unsignedcharc_tem1[K];unsignedcharc_tem2[K];unsignedcharc_tem[K];

for(unsignedinti=0;i

{if(de_rsc[i]=='0')continue;

elseif(de_rsc[i]=='a')tem='1'+(6-i)*f;

elseif(de_rsc[i]=='1')

{if((6-i)!

=0)tem='0'+(6-i)*f;

elsetem='1';}

elsetem=de_rsc[i]+(6-i)*f;

math_GF(tem,c_tem1);

math_GF(result,c_tem2);

for(unsignedintk=0;k

{

if(c_tem1[k]==c_tem2[k])c_tem[k]='0';

elsec_tem[k]='1';

}

result=math(c_tem);

}

returnresult;

}

/*求错误多项式count_ex()的子程序,实现异或运算*/

voidnor(unsignedchartemp1[K],unsignedchartemp2[K],unsignedcharresult[K])

{for(unsignedinti=0;i

{if(temp1[i]==temp2[i])result[i]='0';

elseresult[i]='1';}

}

/*求错误多项式count_ex()的子程序,返回两个行列式相减的结果*/

intfun(unsignedcharc1,unsignedcharc2)

{ unsignedchartemp1[K],temp2[K],result[K];

if(c1=='0')c1='1';

elseif(c1=='1') c1='a';

if(c2=='0') c2='1';

elseif(c2=='1') c2='a';

math_GF(c1,temp1);

math_GF(c2,temp2);

nor(temp1,temp2,result);

unsignedcharc=math(result);

if(c=='1') return0;

elseif(c=='a') return1;

else returnc-48;

}

/*求错误多项式*/

voidcount_ex(unsignedchars[R],unsignedcharqx[K-1],intn)

{ unsignedchartem1,tem2; unsignedcharsx[R]; inttem;

for(unsignedinti=0;i

if(s[i]=='1') sx[i]='0';

elseif(s[i]=='a') sx[i]='1';

else sx[i]=s[i]; }

/*采用行列式法*/

if(s[0]!

='0'&&s[2]!

='0') tem1=sx[0]+sx[2]-48;

else tem1='0';

if(s[1]!

='0') tem2=sx[1]+sx[1]-48;

else tem2='0';

tem=fun(tem1,tem2);

/*Q2=(s3s3-s2s4)/(s1s3-s2s2)*/

if(s[2]!

='0') tem1=sx[2]+sx[2]-48;

else tem1='0';

if(s[1]!

='0'&&s[3]!

='0') tem2=sx[1]+sx[3]-48;

else tem2='0';

inta=fun(tem1,tem2);

qx[0]=a-tem+48;

if(qx[0]<'0') qx[0]=qx[0]+7;

/*Q1=(s1s4-s2s3)/(s1s3-s2s2)*/

if(s[0]!

='0'&&s[3]!

='0') tem1=sx[0]+sx[3]-48;

else tem1='0';

if(s[1]!

='0'&&s[2]!

='0') tem2=sx[1]+sx[2]-48;

else tem2='0';

intb=fun(tem1,tem2);

qx[1]=b-tem+48;

if(qx[1]<'0') qx[1]=qx[1]+7;

}

/*搜索错误位置*/

voidwrong_position(unsignedchartem[2])

{ unsignedcharqx[K]; unsignedinti,j; unsignedchartem1[K],tem2[K],tem3[K]; unsigned

chartemp='0',result;

for(i=0;i

for(unsignedintj=0;j

intn=2; result='0';

for(j=0;j

{ if(qx[j]=='1') qx[j]='0';

elseif(qx[j]=='a') qx[j]='1';

qx[K-1]='1';/*错误多项式的最后一位是‘1’*/

temp=qx[j]+i*n;/*实现x^i*a^i*/

n-=1;

math_GF(temp,tem1);

math_GF(result,tem2);

for(unsignedintk=0;k

{ if(tem1[k]==tem2[k]) tem3[k]='0';

else tem3[k]='1';

}

result=math(tem3); }

}

}

/*译码与纠错*/

voiddecode_rsc(unsignedcharde_rsc[N],unsignedcharsx[R])

{ for(unsignedinti=0;i

unsignedcharqx[K-1];

count_ex(sx,qx,R);

for(unsignedintj=0;j

{ if(qx[j]=='8') qx[j]='a';

elseif(qx[j]>'8'&&qx[j]!

='a') qx[j]-=7;

elseif(qx[j]=='7') qx[j]='1';

elseif(qx[j]<'0') qx[j]=qx[j]+7;

}

wrong_position(qx);

}

voidmain()

{

charGX[R+1];

voidcount_gx(charGX[R+1]);

count_gx(GX);

unsignedcharrsc[N];

unsignedcharrsc_GF[N][K];

unsignedcharremainder[R];

count_remainder(remainder);

create_rsc(rsc,remainder,rsc_GF);

unsignedcharrsc_BPSK[N][K];

BPSK_mapping(rsc_GF,rsc_BPSK);

add_noise(rsc_BPSK);

unsignedcharde_rsc[N];

de_mapping(rsc_BPSK,de_rsc);

unsignedcharsx[R];

decode_rsc(de_rsc,sx

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 人文社科 > 法律资料

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2