直扩抗干扰-伪随机序列生成

本文详细介绍了m序列、Gold序列和Walsh序列的生成原理与性质验证,包括它们的基本概念、生成方法、相关性质如0-1分布、移位可加性和游程特性。同时,提供了MATLAB代码实现序列的生成,并通过实验验证了序列的自相关、互相关特性以及随机性评价。Gold序列通过优选的m序列对生成,具有低互相关特性,而Walsh序列是一种正交编码,用于通信系统中的信号分集。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.1 m序列生成

1.1.1 m序列基本原理

m序列结构上为线性反馈移位寄存器(Linear Feedback Shift Registers, LFSRs),如下图所示。
在这里插入图片描述
图1-1是 n 级线性反馈寄存器结构, c i c_i ci为反馈系数,1 表示连接,0 表示断开,n决定了序列的周期, a i a_i ai为移位寄存器的状态,上图产生的序列值为
a i = c 0 + c 1 a i − 1 + c 2 a i − 2 + … + c 0 a i {a_i} = {c_0} + {c_1}{a_{i - 1}} + {c_2}{a_{i - 2}} + \ldots + {c_0}{a_i} ai=c0+c1ai1+c2ai2++c0ai
调整 a i a_i ai的状态,当产生的序列周期达到 2 n − 1 2^{n-1} 2n1时,则为m序列。反馈系数由本原多项式得到,具体见下表所示。

阶数周期反馈系数阶数周期反馈系数
37137127203,211,217,235,277,313,325,345,367
415238255435,453,537,543,545,551,703,747
53145,67,7595111021,1055,1131,1157,1167,1175
663103,147,1551010232011,2033,2157,2443,2745,3471

m序列具有以下性质。
① 0-1 分布特性。m序列中“1”的个数为 2 n − 1 2^{n-1} 2n1,“ 0 ”的个数为 2 n − 1 − 1 2^{n-1}-1 2n11,这是码的平衡性。
②移位可加性。m序列循环移位后和其本身进行模2加运算,所得结果仍是m序列。
③游程特性。m序列一个周期内有 2 n − 1 2^{n-1} 2n1个元素游程,其中码元“0”的游程和“1”的游程相同,各占一半。

1.1.2 实验:m序列生成及性质验证

① n = 7 反馈系数 [0 0 0 0 1 1]
在这里插入图片描述
在这里插入图片描述
图 1-2 (a) m序列 ( n = 7) ;(b)游程;(c)自相关特性图 1-2 (a) m序列 ( n = 7) ;(b)游程;©自相关特性

② n = 8 反馈系数 [0 0 0 0 0 1 1]
在这里插入图片描述

在这里插入图片描述
图 1 3  (a) m序列 ( n = 7) ;(b)游程;(c)自相关特性
图 1-3 (a) m序列 ( n = 7) ;(b)游程;©自相关特性

1.2 Gold序列生成

1.2.1 Gold序列基本原理

m序列缺点:数量有限。对于由两个n阶本源多项式生成的m序列a和b,如果它们的互相关函数的绝对值的最大值满足公式所示的关系,则m序列a和b构成优选对。
∣ R a , b ( τ ) ∣ m a x = { 2 n + 1 2 + 1 , n = o d d s 2 n + 2 2 + 1 , n = e v e n s |R_{a,b}(\tau)|_{\rm{max}} = \left \{ \begin{array} {l} 2^{\frac{n+1}{2}+1},{n = {\rm{odds}}}\\ 2^{\frac{n+2}{2}+1},{n = {\rm{evens}}}\\ \end{array} \right. Ra,b(τ)max={22n+1+1,n=odds22n+2+1,n=evens

阶数长度序列a反馈系数序列b反馈系数
37[1 0 1 1][1 0 0 1]
531[1 0 0 1 0][1 1 0 1 1]
663[1 0 0 0 0 1][1 1 0 0 1 1]
7127[1 0 0 0 1 0 0][1 0 0 0 1 1 1]
9511[1 0 0 0 0 1 0 0 0][1 0 0 1 0 1 1 0 0]
101023[1 0 0 0 0 0 0 1 0 0][1 0 1 0 0 0 0 1 1 0]
112047[1 0 0 0 0 0 0 0 1 0][1 0 0 1 0 0 1 0 1 0

Gold序列是由2个码长相等、码时钟速率相同的m序列优选对模二加和构成的,每改变2个m序列相对位移就可以得到一个新的Gold序列。对于n阶本原多项式生成的m序列优选对,周期为 2 n − 1 2^{n-1} 2n1 。固定1个m序列,对另一个m序列循环移位,因此有 2 n − 1 2^{n}-1 2n1个组合,加上原来的2个m序列,因此可以得到 2 n + 1 2^{n}+1 2n+1个Gold序列。

1.2.2 实验:Gold序列生成及性质验证

① m序列优选对
在这里插入图片描述
图 1-4 n = 3 (a) 序列a;(b)序列b;© 互相关
在这里插入图片描述
图 1-5 n = 6 (a) 序列a;(b)序列b;© 互相关
② Gold序列生成
以n=6的2个m序列优选对,生成Gold序列,长度为63,Gold序列个数为65。固定序列1,对序列2进行循环移位。选第5个和第7个Gold序列,时域及互相关如下图所示。
在这里插入图片描述
图 1-6 n = 6 (a) 第5条Gold序列;(b) 第7条Gold序列;© 互相关
在这里插入图片描述
图 1-7 Gold序列互相关函数最大值及最小值
进一步,计算65条Gold序列两两之间的互相关最大值和最小值,存入一个65*65的矩阵,得到3维柱状图如图所示,互相关最大值取值均为15,最小值为-17(个别为 -1),说明得到Gold序列互相关有三值特性。

③ Gold序列随机性评价与平衡Gold序列优选
虽然Gold序列可以由2条m序列生成 2 n + 1 2^n+1 2n+1条序列,但并非每一条序列的随机性都很好。根据m序列的性质,满足平衡性和游程性,如下图所示。第1条Gold序列即为m序列a本身,第3条序列由m序列a与循环右移1位的m序列b模加得到,其0、1比特不平衡且游程不满足理想游程。因此,需要进行平衡Gold序列的优选。
在这里插入图片描述
在这里插入图片描述
图 1-8 第1条Gold序列与第3条Gold序列游程

1.3 Walsh序列生成

1.3.1 Walsh序列基本原理

正交编码定义:编码C中的任意两个不同码字为 x = ( x 1 , x 2 , … , x n ) x = ({x_1},{x_2}, \ldots ,{x_n}) x=(x1,x2,,xn) y = ( y 1 , y 2 , … , y n ) y = ({y_1},{y_2}, \ldots ,{y_n}) y=(y1,y2,,yn),其中 x i , y i ∈ { ± 1 } {x_i},{y_i} \in \{ \pm 1\} xi,yi{±1},定义互相关系数为
ρ x y = 1 n ∑ i n x i y i {\rho _{xy}} = \frac{1}{n}\sum\limits_i^n {{x_i}} {y_i} ρxy=n1inxiyi
如果C为正交编码,则任意码字 x , y ∈ C ( x ≠ y ) x,y \in C(x \ne y) x,yC(x=y),有 ρ x y = 0 {\rho _{xy}} = 0 ρxy=0
Walsh序列是一类常用的正交编码,通过Hadamard矩阵递推进行构造。递推过程如下:
2阶Hadamard矩阵
H 2 = [ 1 1 1 − 1 ] {{\bf{H}}_2} = \begin{bmatrix} 1 & 1 \\ 1 & { - 1} \\ \end{bmatrix} H2=[1111]
2 N 2^N 2N阶Hadamard矩阵
H 2 N = [ H 2 N − 1 H 2 N − 1 H 2 N − 1 − H 2 N − 1 ] {{\bf{H}}_{2^N}} = \begin{bmatrix} {{\bf{H}}_{2^{N-1}}} & {{\bf{H}}_{2^{N-1}}} \\ {{\bf{H}}_{2^{N-1}}} & {-{{\bf{H}}_{2^{N-1}}}} \\ \end{bmatrix} H2N=[H2N1H2N1H2N1H2N1]
2 N 2^N 2N阶的Walsh序列为第i行序列。

1.3.2 实验:Walsh序列生成及性质验证

图 1-9 6阶Walsh序列时域
在这里插入图片描述
在这里插入图片描述图 1-10 Walsh序列(i=10)与其他序列点积结果
在这里插入图片描述
图 1-11 Walsh序列(i=2\3)互相关结果

1.4 相关代码

1.4.1 m序列
clear;close all;
Coef = {'13','23','45','103','203','435','1021','2011','4005','10123','20033'}; % 8进制反馈系数 n = 3:14
nInput = 4;
n = nInput - 1;
fx = (de2bi(base2dec(Coef(n-2),8),n+1,2)); %8进制反馈系数转2进制序列
fx = fliplr(fx(1:end-1));
N = 2^(n)-1;                        %m序列长度 
reg = [zeros(1,n-1) 1];             %移位寄存器初始状态 
mseq = zeros(N,1);                  %初始化序列 
mseq(1)= reg(n);
for i = 2:N 
    regTemp = zeros(1,n);
    regTemp(1)= mod(sum(fx.*reg),2);%模加 
    for j = 2:n 
        regTemp(j)= reg(j-1);       %移位更新
    end
    reg = regTemp;                  %移位后的寄存器 
    mseq(i) = reg(n);               %新的寄存器输出 
end

% 时域序列
figure;set(gcf,'Color','w','Position',[400 300 400 150]);
stairs(mseq,'-','LineWidth',0.8); title(['m sequence n=',num2str(n+1)]);
xlim([0,N+1]);ylim([-0.2 1.2]);
xlabel('$i$','Interpreter','latex');ylabel('$a_i$','Interpreter','latex');

% 平衡性
Num1 = length(find(mseq == 1));
Num0 = length(find(mseq == 0));

% 游程
Posi = find(mseq == 1);
Pos1DifNum(1) = length(Posi);
for i = 2:n
    PosiDif = diff(Posi);
    PosiDifN1 = find(PosiDif~=1);
    Pos1DifNum(i) = length(PosiDifN1);
    Posi = PosiDifN1;
end
Posi = find(mseq == 0);
Pos0DifNum(1) = length(Posi);
for i = 2:n
    PosiDif = diff(Posi);
    PosiDifN0 = find(PosiDif~=1);
    Pos0DifNum(i) = length(PosiDifN0);
    Posi = PosiDifN0;
end

benchmark = 2.^(-(1:n))*N;
figure;set(gcf,'Color','w','Position',[400 300 400 150]);
plot(1:n,benchmark,'--','LineWidth',0.8); hold on;
plot(1:n,Pos1DifNum,'-','LineWidth',0.8); hold on;
plot(1:n,Pos0DifNum,'-','LineWidth',0.8); hold off;
legend('theo.','1','0');
title(['Run test of m sequence n=',num2str(n+1)]);
xlim([0,n+1]);
xlabel('$i$','Interpreter','latex');ylabel('Len(i)');
% 自相关特性
mseq = 2*mseq - 1;
[xc,lags] = periodic_corr(mseq,mseq);
figure;set(gcf,'Color','w','Position',[400 300 400 150]);
plot(lags,xc,'LineWidth',0.6);
title(['auto correlation of m sequence n=',num2str(n+1)]);
xlabel('$\tau$','Interpreter','latex');ylabel('$R(\tau)$','Interpreter','latex');

function [r,lags] = periodic_corr(x,y)
% returns the periodic cross-correlation or autocorrelation of two discrete-time sequences.
% Rxy(m) = sum(i) x(i)Y((i+m) mod L)
% x input array
% y input array
% r periodic cross-correlation or autocorrelation
% lags Lag indices
if size(x,2) == 1 && ~isscalar(x)
    x = x';
end
if size(y,2) == 1 && ~isscalar(y)
    y = y';
end
if size(x,2)~=size(y,2)
    error(message('x y dimension mismatch'));
end
L = size(x,2);
r = zeros(1,2*L-1);
for m = 1:L
    if m == 1
        r(L) = x*y'/L;
    else
        r(L+m-1) = x*y'/L;
        r(m-1) = x*y'/L;
    end
    y = circshift(y,-1);
end
lags = -(L-1):L-1;
end
1.4.2 Gold序列
clear;close all;
%产生m序列优选对
CoefaSet = [11,0,18,33]; % m序列优选对系数 % 10进制反馈系数 n = 3:6
CoefbSet = [9,0,27,51];
nInput = 6; % 阶数输入
N = 2^nInput -1;
mseq1=mSeqGen(nInput,CoefaSet(nInput-2)); % 序列a
mseq2=mSeqGen(nInput,CoefbSet(nInput-2)); % 序列b

figure;set(gcf,'Color','w','Position',[400 300 400 400]);
subplot(311);
stairs(mseq1,'-','LineWidth',0.8); title(['m sequence n=',num2str(nInput)]);
xlim([0,N+1]);ylim([-0.2 1.2]);
xlabel('$i$','Interpreter','latex');ylabel('$a_i$','Interpreter','latex');
subplot(312);
stairs(mseq2,'-','LineWidth',0.8); title(['m sequence n=',num2str(nInput)]);
xlim([0,N+1]);ylim([-0.2 1.2]);
xlabel('$i$','Interpreter','latex');ylabel('$b_i$','Interpreter','latex');
mseq1Bi = 2*mseq1 - 1; % BiPolor
mseq2Bi = 2*mseq2 - 1;
[xc,lags] = periodic_corr(mseq1Bi,mseq2Bi); % 互相关
subplot(313);
plot(lags,xc*N,'LineWidth',0.8);
xlim([-N-1,N+1]);
title(['cross correlation of m sequence n=',num2str(nInput)]);
xlabel('$\tau$','Interpreter','latex');ylabel('$R(\tau)$','Interpreter','latex');

%% 产生Gold序列
GoldMatrix = zeros(N+2,N);
GoldMatrix(1,:) =  mseq1;
GoldMatrix(2,:) =  mseq2;
for i = 1:N
    GoldMatrix(i+2,:)=xor(mseq1,circshift(mseq2,i));% 循环移位序列b
end

% 互相关评价
GoldMatrixBi = 2*GoldMatrix-1; % BiPolor
GoldCrossMaxMat = zeros(N+2,N+2);
GoldCrossMinMat = zeros(N+2,N+2);
for i = 1:N+2
    for j = i+1:N+2
    [xc,~] = periodic_corr(GoldMatrixBi(i,:),GoldMatrixBi(j,:)); 
    GoldCrossMaxMat(i,j) = max(xc)*N;
    GoldCrossMinMat(i,j) = min(xc)*N;
    end
end
GoldCrossMaxMat = GoldCrossMaxMat + GoldCrossMaxMat';
GoldCrossMinMat = GoldCrossMinMat + GoldCrossMinMat';

TestSeq1 = GoldMatrix(3,:);
TestSeq2 = GoldMatrix(13,:);
[xc,lags] = periodic_corr(2*TestSeq1-1,2*TestSeq2-1); 

figure;set(gcf,'Color','w','Position',[400 300 400 400]);
subplot(311);
stairs(TestSeq1,'-','LineWidth',0.8); title(['Gold sequence i=',num2str(5)]);
xlim([0,N+1]);ylim([-0.2 1.2]);
xlabel('$i$','Interpreter','latex');
subplot(312);
stairs(TestSeq2,'-','LineWidth',0.8); title(['Gold sequence i=',num2str(7)]);
xlim([0,N+1]);ylim([-0.2 1.2]);
xlabel('$i$','Interpreter','latex');
subplot(313);
plot(lags,xc*N,'LineWidth',0.8);
xlim([-N-1,N+1]);
title('cross correlation of Gold sequence');
xlabel('$\tau$','Interpreter','latex');ylabel('$R(\tau)$','Interpreter','latex');

figure;set(gcf,'Color','w','Position',[400 300 400 300]);
barfig = bar3(GoldCrossMaxMat);
for n=1:numel(barfig)
   cdata=get(barfig(n),'zdata');
   cdata=repmat(max(cdata,[],2),1,4);
   set(barfig(n),'cdata',cdata,'facecolor','flat')
end
hold on;
barfig = bar3(GoldCrossMinMat);
for n=1:numel(barfig)
   cdata=get(barfig(n),'zdata');
   cdata=repmat(max(cdata,[],2),1,4);
   set(barfig(n),'cdata',cdata,'facecolor','flat')
end
hold off;
xlabel('i');ylabel('i');zlabel('$\rm{max}(R(\tau))$','Interpreter','latex');

%% 平衡性评价
n = nInput;
index = 3;
mseq =  GoldMatrix(index,:);
Posi = find(mseq == 1);
Pos1DifNum(1) = length(Posi);
for i = 2:n
    PosiDif = diff(Posi);
    PosiDifN1 = find(PosiDif~=1);
    Pos1DifNum(i) = length(PosiDifN1);
    Posi = PosiDifN1;
end

Posi = find(mseq == 0);
Pos0DifNum(1) = length(Posi);
for i = 2:n
    PosiDif = diff(Posi);
    PosiDifN0 = find(PosiDif~=1);
    Pos0DifNum(i) = length(PosiDifN0);
    Posi = PosiDifN0;
end

benchmark = 2.^(-(1:n))*N;
figure;set(gcf,'Color','w','Position',[400 300 400 150]);
plot(1:n,benchmark,'--','LineWidth',0.8); hold on;
plot(1:n,Pos1DifNum,'-','LineWidth',0.8); hold on;
plot(1:n,Pos0DifNum,'-','LineWidth',0.8); hold off;
legend('theo.','1','0');
title(['Run test of Gold sequence i=',num2str(index)]);
xlim([0,n+1]);
xlabel('$i$','Interpreter','latex');ylabel('Len(i)');

%% m序列生成
function mseq = mSeqGen(nInput,Coef)
fx = int2bit(Coef,nInput+1)'; %8进制反馈系数转2进制序列
fx = (fx(2:end));
n = nInput;
N = 2^(n)-1;                        %m序列长度 
reg = [zeros(1,n-1) 1];             %移位寄存器初始状态 
mseq = zeros(N,1);                  %初始化序列 
mseq(1)= reg(n);
for i = 2:N 
    regTemp = zeros(1,n);
    regTemp(1)= mod(sum(fx.*reg),2);%模加 
    for j = 2:n 
        regTemp(j)= reg(j-1);       %移位更新
    end
    reg = regTemp;                  %移位后的寄存器 
    mseq(i) = reg(n);               %新的寄存器输出 
end
end

1.4.3 Walsh序列生成
%% Walsh序列生成
clear;close all;
H1 = 0;   % H1 矩阵
m = 6;    % 阶数
N = 2^m;  % 长度
Hi = H1;
for i = 1:m
    Hi1 = [Hi,Hi;Hi,~Hi]; % 迭代
    Hi = Hi1;
end

% 时域序列
figure;set(gcf,'Color','w','Position',[400 300 400 400]);
for i = 1:5
    subplot(5,1,i);
    index = 5*i;
    stairs( Hi1(index,:),'-','LineWidth',0.8);
    xlim([0,N+1]);ylim([-0.2 1.2]);
    title(['Walsh sequence i=',num2str(index)]);
end

% 点积
WHNBi = -1*(2*Hi1 - 1);
DotMul = zeros(1,N);
for i = 2:N
    DotMul(i) = WHNBi(10,:)*WHNBi(i,:)';
end

figure;set(gcf,'Color','w','Position',[400 300 400 150]);
stem(DotMul,'filled','MarkerSize',3); title('Walsh sequence dot multiplication i = 10');
xlim([0,N+1]);
ylim([-10 N+2]);
xlabel('$i$','Interpreter','latex');ylabel('$a_i$','Interpreter','latex');

% 互相关
[xc,lags] = periodic_corr(WHNBi(2,:),WHNBi(3,:));
figure;set(gcf,'Color','w','Position',[400 300 400 150]);
plot(lags,xc,'LineWidth',0.6);
title(['Cross correlation of Walsh sequence i=2 and i= 3']);
xlabel('$\tau$','Interpreter','latex');ylabel('$R(\tau)$','Interpreter','latex');

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值