听起来您需要首先弄清楚DSP方面,然后在FPGA中实现。
- 在C,Matlab,Excel或其他任何地方整理出DSP
- 尝试思考如何将从中学到的知识转移到FPGA领域
- 发现您已经对执行不佳的情况做出了一些假设(例如,使用浮点)
- 返回并更新您的离线DSP素材,以考虑到这一点。
- 重复n次:)
关于数据类型,您可以使用整数就可以了。
这是一些示例代码,助您一臂之力。请注意,它缺少许多实际问题(例如,重置,溢出管理)-但希望它能提供指导:
library ieee;
use ieee.std_logic_1164.all;
entity simple_fir is
generic (taps : integer_vector);
port (
clk : in std_logic;
sample : in integer;
filtered : out integer := 0);
end entity simple_fir;
----------------------------------------------------------------------------------------------------------------------------------
architecture a1 of simple_fir is
begin -- architecture a1
process (clk) is
variable delay_line : integer_vector(0 to taps'length-1) := (others => 0);
variable sum : integer;
begin -- process
if rising_edge(clk) then -- rising clock edge
delay_line := sample & delay_line(0 to taps'length-2);
sum := 0;
for i in 0 to taps'length-1 loop
sum := sum + delay_line(i)*taps(taps'high-i);
end loop;
filtered <= sum;
end if;
end process;
end architecture a1;
----------------------------------------------------------------------------------------------------------------------------------
-- testbench
----------------------------------------------------------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
entity tb_simple_fir is
end entity tb_simple_fir;
architecture test of tb_simple_fir is
-- component generics
constant lp_taps : integer_vector := ( 1, 1, 1, 1, 1);
constant hp_taps : integer_vector := (-1, 0, 1);
constant samples : integer_vector := (0,0,0,0,1,1,1,1,1);
signal sample : integer;
signal filtered : integer;
signal Clk : std_logic := '1';
signal finished : std_logic;
begin -- architecture test
DUT: entity work.simple_fir
generic map (taps => lp_taps) -- try other taps in here
port map (
clk => clk,
sample => sample,
filtered => filtered);
-- waveform generation
WaveGen_Proc: process
begin
finished <= '0';
for i in samples'range loop
sample <= samples(i);
wait until rising_edge(clk);
end loop;
-- allow pipeline to empty - input will stay constant
for i in 0 to 5 loop
wait until rising_edge(clk);
end loop;
finished <= '1';
report (time'image(now) & " Finished");
wait;
end process WaveGen_Proc;
-- clock generation
Clk <= not Clk after 10 ns when finished /= '1' else '0';
end architecture test;