1、伪随机码的生成及相关函数的计算院系:信息学院专业:通信工程姓名: 王卓席倩薛珈萍(1)函数ms_generator(registers,connections)是m序列的生成函数,其中参数registers给出了移位寄存器的初始状态,connections给出了m序列的发生器代码:function seq=ms_generator(registers,connections)%registers=0 0 0 0 1;%设置初始状态%connections=1 0 0 1 0 1;%设置反馈逻辑n=length(connections) ;L=2(n-1)-1;seq(1)=registers(。
2、n-1);for i=2:Lsum=0;for m=1:(n-1)sum=mod(sum+registers(m)*connections(m+1),2);endfor k=(n-1):-1:2;registers(k)=registers(k-1);end registers(1)=sum;seq(i)=registers(n-1);end调用程序:function seq=ms_generator(registers,connections)clcclearregisters=0 0 0 0 1;connections=1 0 0 1 0 1;seq=ms_generator(regist。
3、ers,connections)结果:seq =1 0 0 0 0 1 0 0 1 0 1 1 0 0 1 1 1 1 1 0 0 0 1 1 0 1 1 1 0 1 0ans =1 0 0 0 0 1 0 0 1 0 1 1 0 0 1 1 1 1 1 0 0 0 1 1 0 1 1 1 0 1 0(2)auto_corr( )代码:function auto_correlation=auto_corr(seq)registers=1 0 0 0 0;%设置初始状态connections=1 0 1 0 0 1;%设置反馈逻辑seq=ms_generator(registers,connec。
4、tions);seq=-1*(seq*2-1);%负逻辑映射len=length(seq);temp=seq seq;for i=0:len-1auto_correlation(i+1)=seq*(temp(i+1:i+len);endauto_correlationplot(0:len-1,auto_correlation);结果:auto_correlation =31 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1ans =31 -1 -1 -1 -1 -1。
5、 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1(3)cross_corr( )代码:function cross_correlation=cross_corr(seq1,seq2)registers1=0 0 0 0 1;%设置初始状态connections1=1 0 0 1 0 1;%设置反馈逻辑seq1=ms_generator(registers1,connections1);seq1=-1*(seq1*2-1);%负逻辑映射registers2=1 1 1 1 1;%设置初始状态co。
6、nnections2=1 1 1 1 0 1;%设置反馈逻辑seq2=ms_generator(registers2,connections2);seq2=-1*(seq2*2-1);%负逻辑映射temp=seq2 seq2;len=length(seq2);for i=0:len-1cross_correlation(i+1)=seq1*(temp(i+1:i+len);endauto_correlation=auto_corr(seq1)plot(0:len-1,auto_correlation,-.,0:len-1,cross_correlation);结果: (4)GOLD码代码fun。
7、ction gold=gold()registers1=1 0 0 0 0 0;connections1=1 1 0 0 0 0 1;seq1=ms_generator (registers1,connections1);registers2=1 0 0 0 0 0;connections2=1 1 1 0 0 1 1;seq2=ms_generator(regerters2,connections2);temp=seq2 seq2;len=length(seq2);for i=1:lengold(i,:)=mod(seq1+temp(i:i+len-1),2);endgold(len+1,:。
8、)=seq1;gold(len+2,:)=seq2;plot(0:len-1,auto_corr(gold(1,:),-,0:len-1,cross_corr(gold(1.:),gold(2,:),-.);结果:相关特性:(5)Walsh 函数:代码:function walsh = walsh(L)L=64n=log2(L);temp=0;temp2=zeros(4,4);for i=1:ntemp2=zeros(2.n,2.n);temp1=inverse(temp);temp2=temp temp;temp temp1;temp=zeros(2.n,2.n);temp=temp2;temp1=zeros(2.n,2.n);endwalsh=temp2;correlation=(walsh*2-1)*(walsh*2-1)function result=inverse(temp)len=size(temp);for i=1:lenfor j=1:len;if(temp(i,j)=0)temp(i,j)=1;elsetemp(i,j)=0;endendendresult=temp;结果:因篇幅受限只截取其中一部分。
如果觉得《matlab产生伪随机码 MATLAB实现伪随机码的生成及相关函数的计算》对你有帮助,请点赞、收藏,并留下你的观点哦!