⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linear_feedback_shift_register.m

📁 构建CDMA通信系统
💻 M
字号:
<matlab> 实现线性反馈移位寄存器单元<LFSR>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                                                                %
%  该函数实现产生伪随机序列的部件 —— 线性反馈移位寄存器单元                        %
%                                                                                                                %
%  SFlog2为扩频因子的底数为2的对数值,cycle为PN序列的周期,其值为2^SFlog2    %
%  initial_state为移位寄存器的初始状态,generator_polynomial_coefficient为           %
%  生成PN序列所需的本原多项式,对应于移位寄存器的连接向量。                         %
%                                                                                                                %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [m_sequences] = linear_feedback_shift_register(SFlog2,cycle,...
    initial_state,generator_polynomial_coefficient)
if max(generator_polynomial_coefficient) > SFlog2
    error('本原多项式系数对应的最高阶不能大于移位寄存器的阶数');
end
if length(initial_state) > SFlog2
    error('移位寄存器的初始状态序列长度不能大于寄存器的阶数');
end
if SFlog2 > 32
    error('扩频因子超出仿真器处理范围!');
end
len = length(generator_polynomial_coefficient);    
m_sequences = zeros(1,cycle);                   % 初始化反馈序列
register_index = generator_polynomial_coefficient;
%%
% 开始线性反馈移位寄存器的迭代计算过程
h = waitbar(0,'m 序列生成中...................');
for m = 1:cycle 
    temp = initial_state(register_index(2));
    for n = 3:len
        temp = bitxor(initial_state(register_index(n)),temp);
    end
    m_sequences(m) = initial_state(1);                      % 线性反馈移位寄存器的输出
    initial_state = [temp,initial_state];       % 更新线性反馈移位寄存器的状态
    initial_state(SFlog2+1) = [];
    waitbar(m/cycle);
end
close(h);
%%
m_sequences = 2*m_sequences - 1;                % 生成双极性的随机序列

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -