-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFIR_Filter.vhd
More file actions
65 lines (54 loc) · 1.49 KB
/
Copy pathFIR_Filter.vhd
File metadata and controls
65 lines (54 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
-- package declaration for FIR_Coeff_type
package DSDtypes_pkg is
type FIR_Coeff_type is array (natural range <>) of unsigned(11 downto 0);
end package DSDtypes_pkg;
-- FIR_Filter behavioral description
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
use work.DSDtypes_pkg.all; -- use package defined abpve
entity FIR_Filter is
Generic (Coeff : FIR_Coeff_type; N : positive := 12);
Port ( clk : in STD_LOGIC;
Sample : in STD_LOGIC;
X : in STD_LOGIC_VECTOR (N-1 downto 0);
Y : out STD_LOGIC_VECTOR (N-1 downto 0));
end FIR_Filter;
architecture Behavioral of FIR_Filter is
signal xt0,xt1,xt2,Y_out : unsigned(N-1 downto 0) := (others => '0');
signal ResultFin,ResultPre,Add2,Add1,Add0 : unsigned(((2*N)-1) downto 0) := (others => '0');
begin
process(clk)
begin
if rising_edge(clk) then
if Sample = '1' then
xt0 <= unsigned(X);
xt1 <= xt0;
xt2 <= xt1;
else
xt0 <= xt0;
xt1 <= xt1;
xt2 <= xt2;
end if;
end if;
end process;
Add0 <= xt0*Coeff(0);
Add1 <= xt1*Coeff(1);
Add2 <= xt2*Coeff(2);
ResultPre <= Add0 + Add1;
ResultFin <= ResultPre + Add2;
process(clk)
begin
if rising_edge(clk) then
if Sample = '1' then
Y_out <= ResultFin(ResultFin'length-1 downto ResultFin'length-Y_out'length);
else
Y_out <= Y_out;
end if;
end if;
end process;
Y <= STD_LOGIC_VECTOR(Y_out);
end Behavioral;