📄 生成m序列[1].txt
字号:
% 生成m序列(初相为[0 0 ... 0 1])
% [in]: m序列的阶数
% [out]: 生成的m序列
% lfb 2006.04
function PN_Seq = gen_m_Seq(m)
switch m
case 3
pntags=[1 0 1];
case 4
pntags=[1 0 0 1 ];
case 5
pntags=[0 1 0 0 1];
case 6
pntags=[1 0 0 0 0 1 ];
case 7
pntags=[ 0 0 1 0 0 0 1];
case 8
pntags=[ 0 1 1 1 0 0 0 1];
case 9
pntags=[0 0 0 1 0 0 0 0 1];
case 10
pntags=[0 0 1 0 0 0 0 0 0 1];
case 11
pntags=[0 1 0 0 0 0 0 0 0 0 1];
case 12
pntags=[1 0 0 1 0 1 0 0 0 0 0 1];
case 13
pntags=[1 0 1 1 0 1 0 0 0 0 0 0 1];
case 14
pntags=[1 0 0 0 0 1 0 0 0 1 0 0 0 1];
end
pninitial(1:length(pntags))=0; pninitial(length(pntags))=1;
pndata=zeros(1,2^m-1);
samp_per_sym=1;
pnregister=pninitial;
n=0;
kk=0;
while kk==0
n=n+1;
pndata(1,n)=pnregister(1,m);
feedback=rem((pnregister*pntags'),2);
pnregister=[feedback pnregister(1,1:m-1)];
if pnregister==pninitial;
kk=1;
end
end
PN_Seq=pndata;
%PN_Seq = 2*pndata-1;
% plot(xcorr(PN_Seq))
以下是我借鉴了一个程序,然后写的一个4阶gold序列生成程序
%function goldpn=goldgen(GoldGenPoly) %GoldGenPoly是由两个m序列的生成多项式组成的矩阵
GoldGenPoly=[1 0 0 1 ;0 0 1 1 ];
%pn_len = 2^(size(GoldGenPoly,2))-1; %size(GoldGenPoly,2)为阶数
%ini1_state = [zeros(1,3),1]; % m1序列的初始状态
%ini2_state = [1,zeros(1,3)]; % m2序列的初始状态
ini1_state = [0 0 1 1];
ini2_state = [0 1 0 1];
%--------------------------------------------------------------------------------------
% -- to generate the 1st and 2nd m sequences. then the gold sequence is generated
%for i=1:pn_len
for i=1:15
m1_out(i) = ini1_state(length(ini1_state));
m2_out(i) = ini2_state(length(ini2_state));
%for i01=1size(GoldGenPoly,2)-1)
s1_step = sum(GoldGenPoly(1,1:4).*ini1_state);
s2_step = sum(GoldGenPoly(2,1:4).*ini2_state);
for j=4:-1:2
ini1_state(j) = ini1_state(j-1);
ini2_state(j) = ini2_state(j-1);
end
ini1_state(1) = mod(s1_step,2);
ini2_state(1) = mod(s2_step,2);
goldpn(i) = xor(m1_out(i),m2_out(i));
end
m1_out;
m2_out;
m1_out=m1_out.*2-1;
m2_out=m2_out.*2-1;
% m1_out=[m1_out m1_out];
% m2_out=[m2_out m2_out];
%
% for indx=1:15
% tmp=0;
% for i=1:15
% tmp=tmp+m1_out(i)*m2_out(i+indx);
% end
% tcf(indx)=tmp;
% end
%
%
goldpn = goldpn.*2-1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -