m 序列生成电路的 FPGA 实现

m 序列是一种伪随机码,或伪噪声码(PN 码),其输出在一个周期内具有随机性。本文讨论 m 序列生成电路的 FPGA 实现方法。

目录

1 基本概念

2 设计实现

3 仿真验证


1 基本概念

        在 n 级移位寄存器的基础上,增加一个反馈环节,如果反馈函数 gif.latex?f 是现态 gif.latex?a_0%2C%20%5C%2C%20a_1%2C%20%5C%2C%20%5Ccdots%20%2C%20%5C%2C%20a_%7Bn-1%7D 的线性组合,即

gif.latex?f%28a_0%2Ca_1%2C%5Ccdots%2Ca_%7Bn-1%7D%29%20%3D%20%5Csum%20_%7Bi%3D1%7D%5E%7Bn%7D%20c_i%20%5Ccdot%20a_%7Bn-i%7D%20%5C%2C%20%2C%20%5Cquad%20c_1%2C%20c_2%2C%20%5Ccdots%20c_%7Bn-1%7D%5Cin%20%5C%7B0%2C1%5C%7D%20%5C%2C%20%2C%20c_n%20%3D%201

就得到一个线性反馈移位寄存器(Linear Feedback Shift Register, LFSR)。

e8a937ac095047c8af08d5aa9e98cdc6.png

15c86c95b2c34467bc58f22acc1b9d5f.png

        对于 n 级 LFSR,除去 “0” 态,最多有 gif.latex?2%5En-1 个状态,这  gif.latex?2%5En-1 个状态可以产生一个周期为 gif.latex?2%5En-1 的序列,称之为 m 序列。m 序列是 n 级 LFSR 所有能产生的序列中,周期最长的序列。
       

2 设计实现

        关于 m 序列的理论研究已经很成熟了,m 序列 LFSR 的反馈系数由本原多项式给出。

6abb125f1e494588b046af1b92bdd0e3.png

        使用 constant 存储本原多项式的系数,由于本原多项式最后一项固定为 1,只需要存储 gif.latex?x%5E1 ~ gif.latex?x%5En 前面的系数即可。

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;

entity lfsr is
   generic(
      N_VALUE   : integer := 4;
      LFSR_INIT : integer := 1
   );
   port(
      rst  : in std_logic;
      clk  : in std_logic;
      qout : out std_logic
   );
end lfsr;
architecture behav of lfsr is
   -- internal signal declarations
   type array_1x15 is array(0 to 14) of std_logic_vector(15 downto 0);
   constant PolyCoeff: array_1x15 := (X"0003", X"0005", X"0009", X"0012", X"0021", 
                                      X"0044", X"008E", X"0108", X"0204", X"0402", 
                                      X"0829", X"100D", X"2221", X"4001", X"8805");
   signal coeff: std_logic_vector(15 downto 0);
   signal q: std_logic_vector(N_VALUE-1 downto 0);
   signal q0: std_logic;
begin
   -- todo
   coeff <= PolyCoeff(N_VALUE-2);
   qout <= q(N_VALUE-1);

   process(q,coeff)
      variable tmp: std_logic;
   begin
      tmp := '0';
      for i in 0 to N_VALUE-1 loop 
         if coeff(i) = '1' then
            tmp := tmp xor q(i);
         end if;
      end loop;
      q0 <= tmp;
   end process;

   process(rst,clk)
   begin
      if rst = '1' then
         q <= conv_std_logic_vector(LFSR_INIT,q'LENGTH);
      elsif rising_edge(clk) then
         q <= q(q'HIGH-1 downto 0) & q0;
      end if;
   end process;
end;

3 仿真验证

        搭建仿真环境,使用 Modelsim 仿真验证逻辑功能,其中 LFSR 的初始状态设为 1。

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;

entity lfsr_tb is
end entity;
architecture behav of lfsr_tb is
   -- internal signal declarations
   signal rst: std_logic := '1';
   signal clk: std_logic := '1';
begin
   -- todo
   rst <= '1', '0' after 196 ns;
   clk <= not clk after 4000 ps;

   lfsr_inst: entity work.lfsr
   generic map(
      N_VALUE   => 4,
      LFSR_INIT => 1
   )
   port map(
      rst  => rst,
      clk  => clk,
      qout => open
   );
end architecture;

1cabe3b0ec2a4f9aa5d8432fd2cc0849.png

        可以看到,LFSR 有 15 个状态,输出序列 qout 也是以 15 为周期。

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

洋洋Young

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值