当前位置:编程学习 > Matlab >>

谁知道如何用matlab生成m序列,不用simulink。。。。急求程序。。。谢谢了

追问:感觉出的图不对呀。。。。正确的图形应该是矩形波。。。。M和m是不一样的,我要的是m序列的。。。。好像结果就是矩形波。。。。您再看看呀我想要的是m序列(小m的),这种图出来好像不对。。。。怎么不出图呀
答案:下面是最简化的程序,参考书目《系统辨识》》
1.m序列
clear
p=5
np=(2^p-1)
x=[1 0 1 0 0 0 1]
for i=10:2*(np+1)
    x(i)=xor(x(i-4),x(i-9))
end
xi=x/np
plot(xi)
2.逆m序列
clear
p=5
np=(2^p-1)
x=[1 0 1 0 0 0 1]
for i=10:2*(np+1)
    x(i)=xor(x(i-4),x(i-9))
end
plot(x)

s=[]
for i=1:(np+1)
 s=[s,[1,0]]
end
plot(s)
%###################
m(i)=xor(x,s)
plot(m)
有问题了请补充
其他:X1=1;X2=0;X3=1;X4=0; X5=0;X6=0; %移位寄存器输入Xi初T态(010100), Yi为移位寄存器各级输出
m=63;                %置M序列总长度
for i=1:m    %1#
   Y6=X6;Y5=X5;Y4=X4;  Y3=X3;  Y2=X2;   Y1=X1;
   X6=Y5;X5=Y4;X4=Y3;  X3=Y2;   X2=Y1; 
 
   X1=xor(Y6,Y5);  %异或运算
   if Y6==0   
       U(i)=-1;
   else
   U(i)=Y6;
end 
end
M=U
%绘图
i1=i
k=1:1:i1;
plot(k,U,k,U,'rx')
xlabel('k')
ylabel('M序列')
title('移位寄存器产生的M序列') adaqwee clear all
len=3; 
L=128; 
registersone=[0 0  1]; 
seqone(1)=registersone(1); 
registerstwo=[0 0  1]; 
seqtwo(1)=registerstwo(1); 
for i=2:L 
    newregistersone(2:len) = registersone(1:len-1); 
    newregistersone(1) = mod((registersone(2)+registersone(3)),2); %系数为5321; 

    
    registersone=newregistersone; 
    seqone(i)=registersone(1); 
%     newregisterstwo(2:len) = registerstwo(1:len-1); 
%     newregisterstwo(1) = mod((registerstwo(5)+registerstwo(4)+registerstwo(3)+registerstwo(1)),2);  %系数为5431;
% 
%     
%     registerstwo=newregisterstwo; 
%     seqtwo(i)=registerstwo(1); 
end  
%     translocationone=seqone; 
%     
%      for n=1:31 
%         translocationone(n+31)=translocationone(n); 
%      end 
%      for n=32:62 
%         translocationone(n+31)=translocationone(n-31); 
%      end
%      
%      %码序列循环延长,便于自互相关计算;
% for k=1:61 
%        for j=1:31 
%             trans(j)=translocationone(j+k); 
% %             mxor(j)=xor(seqone(j),trans(j)); 
%             mxoronetwo(j)=xor(seqtwo(j),trans(j)); 
%        end     
%        cor(k)=31-2*sum(mxor); 
% coronetwo(k)=31-2*sum(mxoronetwo); 
% %相关值为:两序列对应模二加,相同的个数减去不同的个数; 
% end  
% subplot(2,1,1):plot(cor); 
% subplot(2,1,2):plot(coronetwo); 

上一个:怎么样让matlab中的结果横排显示
下一个:急:matlab plot 画线问题!

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,