M序列及逆M序列程序及仿真图一.程序:clearall;closeall;%二值伪随机信号(M序列)p=2000;x1=1;x2=1;x3=1;x4=1;x5=1;x6=1;x7=1;x8=1;s=1;fork=1:pms1(k)=xor(x1,s);ms2(k)=xor(ms1(k),x3);ms(k)=xor(x5,ms2(k));x8=x7;x7=x6;x6=x5;x5=x4;x4=x3;x3=x2;x2=x1;x1=ms(k);ifms==0u(k)=-1;elseu(k)=1;ends=not(s);ims(k)=xor(s,x8)endsubplot(2,1,1)stairs(ms);grid;xlabel('k');ylabel('M序列幅值');title('M序列');subplot(2,1,2)stairs(ims);grid;xlabel('k');ylabel('逆M序列幅值');title('逆M序列');二.仿真图:020040060080010001200140016001800200000.51kM序列幅值M序列020040060080010001200140016001800200000.51k逆M序列幅值逆M序列图一204060801001200.960.981kM序列幅值M序列4004204404604805000.960.981k逆M序列幅值逆M序列图二10012014016018020000.020.04kM序列幅值M序列14016018020022024000.020.04k逆M序列幅值逆M序列图三