后期更新:matlab中产生m序列最简单的方法是调用idinput()函数,关于idinput()的具体用法可以在matlab中查看说明,这里举两个简单的例子:
src = idinput(8191,'RBS')'; % 产生随机的二进制数据 1 -1
m = idinput(8191,'PRBS')'; % 产生长度为8192的m序列
m序列的基本生成原理这里就不做介绍了,今天闲着没事时候就行统计一下m序列中00和11的个数,结果有点失望,竟然是完全相等的(手动再最前面或者最后面补了一个0),并且00和11的个数是m序列长度的1/4(微小浮动)。我尝试了将m序列循环移位再统计,结果还是只有这两组值!!!下面是我通过本原多项式产生所有n=9和n=10的m序列并统计00和11个数的代码。其中 primpoly(9,'all') 这个函数可以获得所有n=9的m序列的本原多项式。
产生m序列的函数,输入参数为:m序列的本原多项式的系数矩阵
function[mseq]=m_sequence(fbconnection)
% primpoly(9,'all')
n=length(fbconnection);
N=2^n-1;
newregister = zeros(1, n);
mseq = zeros(1, N);
register=[zeros(1,n-1) 1]; % 移位寄存器的初始状态
mseq(1)=register(n); % m序列的第一个输出码元
for i=2:N
newregister(1)=mod(sum(fbconnection.*register),2);
for j=2:n
newregister(j)=register(j-1);
end
register=newregister;
mseq(i)=register(n);
end
end
下面这代码是我统计m中00和11个数的代码
clear all;
syms D;
% primpoly(9,'all')
if 0
poly_str = [D^9+D^4+1, D^9+D^4+D^3+D^1+1, D^9+D^5+1, D^9+D^5+D^3+D^2+1, D^9+D^5+D^4+D^1+1, D^9+D^6+D^4+D^3+1, D^9+D^6+D^4+D^3+D^2+D^1+1, ...
D^9+D^6+D^5+D^3+1, D^9+D^6+D^5+D^3+D^2+D^1+1, D^9+D^6+D^5+D^4+D^2+D^1+1, D^9+D^6+D^5+D^4+D^3+D^2+1, D^9+D^7+D^2+D^1+1,D^9+D^7+D^4+ ...
D^2+1, D^9+D^7+D^5+D^1+1, D^9+D^7+D^5+D^2+1, D^9+D^7+D^5+D^3+D^2+D^1+1, D^9+D^7+D^5+D^4+D^2+D^1+1, D^9+D^7+D^5+D^4+D^3+D^2+1, D^9+ ...
+D^7+D^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+1, D^10+D^9+D^8+D^7+D^3+D^2+1, D^10+D^9+D^8+D^7+D^4+D^1+1, D^10+D^9+...
D^8+D^7+D^5+D^4+1, D^10+D^9+D^8+D^7+D^6+D^4+D^3+D^1+1, D^10+D^9+D^8+D^7+D^6+D^5+D^4+D^1+1, D^10+D^9+D^8+D^7+D^6+D^5+D^4+D^3+1];
end
m00 = zeros(2, length(poly_str));
m11 = zeros(2, length(poly_str));
fd = fopen('m_Seq_Cnt.txt','a+'); % 保存数据结果到文本文件
for i = 1 : 1 : length(poly_str)
tmp = fliplr(sym2poly(poly_str(i)));
s = tmp(2 : length(tmp));
m_seq_tmp = m_sequence(s);
m_seq1 = [0 m_seq_tmp];
m00_cnt = 0;
m11_cnt = 0;
t1 = m_seq1(1 : 2 : length(m_seq1));
t2 = m_seq1(2 : 2 : length(m_seq1));
for k = 1 : 1 : length(t1)
tmp = t1(k) + t2(k);
if(tmp == 0)
m00_cnt = m00_cnt + 1;
elseif(tmp == 2)
m11_cnt = m11_cnt + 1;
end
end
m00(1, i) = m00_cnt;
m11(1, i) = m11_cnt;
fprintf(fd, '前置: 00 -> %d 11 -> %d ', m00_cnt, m11_cnt);
m00_cnt = 0;
m11_cnt = 0;
m_seq2 = [m_seq_tmp 0];
t1 = m_seq2(1 : 2 : length(m_seq2));
t2 = m_seq2(2 : 2 : length(m_seq2));
for k = 1 : 1 : length(t1)
tmp = t1(k) + t2(k);
if(tmp == 0)
m00_cnt = m00_cnt + 1;
elseif(tmp == 2)
m11_cnt = m11_cnt + 1;
end
end
m00(2, i) = m00_cnt;
m11(2, i) = m11_cnt;
fprintf(fd, '后置: 00 -> %d 11 -> %d \n', m00_cnt, m11_cnt);
end
fclose(fd);
后来也统计了一下01和10的个数,这组的变化较大,总体浮动大概是00和11的两倍左右。