![]() |
[求助]编了个M序列的自相关函数的程序,麻烦大家检查一下
[CODE]% M序列的自相关函数仿真
% 特征多项式为f(x)=1+x^2+x^3+x^5 % *****初始化变量及寄存器***** clear all ; length = 31 * 4 ; count = 1 ; t = [1 1 1 1 1] ; % *************************** % ***对寄存器中的值进行移位*** for x = 1:1:length m_seq(count) = t(5) ; count = count + 1 ; temp = t(1) ; t(1) = xor(t(2), xor(t(3), t(5))) ; t(5) = t(4) ; t(4) = t(3) ; t(3) = t(2) ; t(2) = temp ; end % *************************** % ****计算M序列的自相关函数**** m_seq = m_seq.*2-1 ; [row, col] = size(m_seq) ; for ii = 1:col if ii==1 m_seq_ac(ii) = sum(m_seq.*m_seq) ; else m_seq_ac(ii) = sum(m_seq.*[m_seq(col-(ii-2):col),m_seq(1:col-(ii-1))]) ; end end m_seq_ac = m_seq_ac./max(m_seq_ac) ; % **************************** % *****绘制M序列自相关函数***** index = -(max(size(m_seq_ac))+1)/2:1:(max(size(m_seq_ac))-1)/2-1 ; plot(index,m_seq_ac) ; axis([-(max(size(m_seq_ac))+1)/2 (max(size(m_seq_ac))-1)/2-1 min(m_seq_ac)-0.05 max(m_seq_ac)]) ; title('M序列的自相关函数') ; xlabel('时间') ; ylabel('自相关函数') ; legend('生成多项式为f(x)=1+x^2+x^3+x^5') ; % ****************************[/CODE] 运行出来的图像不对,经过检查,问题出在if-else语句处,但是我检查了很多遍还是没有发现错误:ft: ,麻烦大家看一下到底是什么问题,谢谢! |
所有时间均为北京时间。现在的时间是 03:03。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.