一、生成m序列function[mseq]=m_sequence(fbconnection);n=length(fbconnection);N=2^n-1;%m序列的长度register=[zeros(1,n-1)1];%定义移位寄存器的初始状态mseq(1)=register(n);%m序列的第一个输出码元fori=2:Nnewregister(1)=mod(sum(fbconnection.*register),2);%寄存器与反馈的模2和forj=2:n,newregister(j)=register(j-1);end;register=newregister;%移位后的寄存器mseq(i)=register(n);%新的寄存器输出endclearall;closeall;clc;fbconnection=[00101];%输入本原多项式系数,从C1开始m_sequence=m_sequence(fbconnection);stem(m_sequence);%对m序列绘图axis([035-0.21.2]);gridon;二、生成gold序列functiongoldseq=g_sequence(connection1,connection2);msequence1=m_sequence(connection1);%生成第一个m序列msequence2=m_sequence(connection2);%生成第二个m序列N=2^length(connection1)-1;%gold序列长度fori=1:N;s=mod(msequence1+msequence2,2);%两个m序列模二加产生gold序列goldseq=s;endclearall;closeall;clc;connection1=[000011];connection2=[100111];goldseq=g_sequence(connection1,connection2);stem(goldseq);axis([065-0.21.2]);gridon;