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

📄 lms_ad_filt.vhd

📁 自适应滤波器adaptive的vhdl实现的源代码。
💻 VHD
字号:
-- Adaptive Filter Package


library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_SIGNED.ALL;
library work;
use work.ad_filt.ALL;
entity lms_ad_filt is
Port ( clk : in std_logic;
rst : in std_logic;
train : in std_logic; -- 1 for yes, 0 for no
data_in : in std_logic_vector(15 downto 0);
new_data : in std_logic_vector(15 downto 0);
desired : in std_logic_vector(15 downto 0);
data_out : out std_logic_vector(15 downto 0) );
end lms_ad_filt;
architecture Behavioral of lms_ad_filt is
type states is (s0,s1,s2,s3,s4);
signal state : states;
signal coeffs : sh_reg;
signal inputs : sh_reg;
signal tmp : tmp_reg;
signal tmp1 : tmp_reg;
signal add_0 : std_logic_vector(31 downto 0);
signal add_1 : std_logic_vector(31 downto 0);
signal desired_0r : std_logic_vector(15 downto 0);
signal desired_1r : std_logic_vector(15 downto 0);
signal error : std_logic_vector(15 downto 0);
signal nd_0, nd_1 : std_logic_vector(15 downto 0);
begin
process(clk, rst, new_data)
variable output : std_logic_vector(31 downto 0);
begin
if rst = '1' then
state <= s0;
for i in 0 to NUM_TAPS-1 loop
inputs(i) <= (others=>'0');
tmp(i) <= (others=>'0');
coeffs(i) <= x"0001";
end loop;
data_out <= (others=>'0');
error <= (others=>'0');
desired_0r <= (others=>'0');
elsif rising_edge(clk) then
nd_0 <= new_data;
nd_1 <= nd_0;
case state is
when s0 =>
if (nd_0 /= nd_1) then -- new data available
state <= s1;
-- register desired output
desired_0r <= desired;
desired_1r <= desired_0r;
-- shift down input array
for i in NUM_TAPS-1 downto 1 loop
inputs(i) <= inputs(i-1);
end loop;
-- put new value in array
inputs(0) <= data_in;
-- compute direct form FIR
for i in 0 to NUM_TAPS-1 loop
tmp(i) <= inputs(i) * coeffs(i);
end loop;
else
-- wait for new data
state <= s0;
end if;
when s1 =>
state <= s2;
-- first adder stage
add_0 <= tmp(0)+tmp(1)+tmp(2)+tmp(3);
add_1 <= tmp(4)+tmp(5)+tmp(6)+tmp(7);
when s2 =>
-- second adder stage
output := add_0 + add_1;
data_out <= output(22 downto 7);
if train = '1' then
-- compute error
error <= desired_1r - output(22 downto 7); --divide by scale
state <= s3;
else
state <= s0;
end if;
when s3 =>
state <= s4;
-- update coefficients - first stage
for i in 0 to NUM_TAPS-1 loop
tmp1(i) <= inputs(i) * error;
end loop;
when s4 =>
state <= s0;
-- update coefficients
for i in 0 to NUM_TAPS-1 loop
coeffs(i) <= coeffs(i) + tmp1(i)(26 downto 11);--divide by scale & mu
end loop;
when others => state <= s0;
end case;
end if;
end process;
end Behavioral;

⌨️ 快捷键说明

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