forked from filipamator/vu_meter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
windowfunction.vhd
208 lines (165 loc) · 4.26 KB
/
windowfunction.vhd
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;
entity windowfunction is
generic (
SIZE : natural := 1024
);
port (
i_clock : in std_logic;
i_reset : in std_logic;
i_data : in std_logic_vector(15 downto 0);
i_data_start: in std_logic;
i_data_en : in std_logic;
o_data : out std_logic_vector(15 downto 0);
o_data_en : out std_logic;
o_data_start: out std_logic
);
end entity windowfunction;
architecture rtl of windowfunction is
------------------------
-- Components ----------
------------------------
component hannwindow is
port (
i_sample : in STD_LOGIC_VECTOR(9 downto 0);
o_value : out STD_LOGIC_VECTOR(31 downto 0)
);
end component hannwindow;
component fp_mult IS
PORT
(
clock : IN STD_LOGIC ;
dataa : IN STD_LOGIC_VECTOR (31 DOWNTO 0);
datab : IN STD_LOGIC_VECTOR (31 DOWNTO 0);
result : OUT STD_LOGIC_VECTOR (31 DOWNTO 0)
);
END component fp_mult;
component int2fp
PORT
(
clock : IN STD_LOGIC ;
dataa : IN STD_LOGIC_VECTOR (15 DOWNTO 0);
result : OUT STD_LOGIC_VECTOR (31 DOWNTO 0)
);
end component;
component fp2int
PORT
(
clock : IN STD_LOGIC ;
dataa : IN STD_LOGIC_VECTOR (31 DOWNTO 0);
result : OUT STD_LOGIC_VECTOR (15 DOWNTO 0)
);
end component;
------------------------
-- Signals -------------
------------------------
SIGNAL r_data_fp : STD_LOGIC_VECTOR(31 downto 0) := (others => '0');
SIGNAL r_wdata_fp : STD_LOGIC_VECTOR(31 downto 0) := (others => '0');
SIGNAL r_window_fp : STD_LOGIC_VECTOR(31 downto 0) := (others => '0');
SIGNAL r_wdata : STD_LOGIC_VECTOR(15 downto 0) := (others => '0');
SIGNAL r_data : STD_LOGIC_VECTOR(15 downto 0) := (others => '0');
SIGNAL r_coefaddr : STD_LOGIC_VECTOR(9 downto 0) := (others => '0');
SIGNAL r_coef : STD_LOGIC_VECTOR(31 downto 0) := (others => '0');
signal r_counter : integer;
signal r_temp : integer := 0;
TYPE STATE_TYPE IS (ST_IDLE, ST_WRITE);
SIGNAL state : STATE_TYPE := ST_IDLE;
begin
process (i_clock, i_reset)
begin
if i_reset='1' then
r_counter <= 0;
state <= ST_IDLE;
elsif (i_clock='1' and i_clock'event) then
case state is
when ST_IDLE =>
if (i_data_start='1') then
r_counter <= 0;
state <= ST_WRITE;
end if;
when ST_WRITE =>
if (r_counter < 1024) then
r_data <= i_data;
r_counter <= r_counter + 1;
elsif r_counter = SIZE-1+18 then
r_counter <= 0;
state <= ST_IDLE;
else
r_counter <= r_counter + 1;
end if;
-- if (r_counter < 37) then -- From 0 to 35
-- r_counter <= r_counter + 1;
-- elsif (r_counter = 37 ) then
-- r_counter <= r_counter + 1;
-- o_data_start <= '1';
-- elsif (r_counter > 37 and r_counter < 1062) then -- From 37 to 1060
-- o_data_start <= '0';
-- o_data_en <= '1';
-- o_data <= r_wdata;
-- r_temp <= r_temp + 1;
-- r_counter <= r_counter + 1;
-- else
-- o_data_en <= '0';
-- r_counter <= 0;
-- state <= ST_IDLE;
-- end if;
end case;
end if;
end process;
process (i_clock, i_reset)
begin
if i_reset='1' then
elsif (i_clock='1' and i_clock'event) then
if (r_counter > 6 and r_counter < 1031) then
r_coefaddr <= std_logic_vector(to_unsigned(r_counter-6, r_coefaddr'length));
end if;
end if;
end process;
process (i_clock, i_reset)
begin
if i_reset='1' then
o_data_en <= '0';
o_data_start <= '0';
r_temp <= 0;
elsif (i_clock='1' and i_clock'event) then
o_data_en <= '0';
if r_counter = 17 then
o_data_start <= '1';
elsif (r_counter > 17 and r_counter < 1042) then
--r_temp <= r_temp + 1;
o_data_en <= '1';
o_data_start <= '0';
o_data <= r_wdata;
end if;
end if;
end process;
hannwindow_i1 : hannwindow
port map (
i_sample => r_coefaddr,
o_value => r_coef
);
int2fp_i1 : int2fp
PORT MAP
(
clock => i_clock,
dataa => r_data,
result => r_data_fp
);
fp2int_i1 : fp2int
PORT MAP
(
clock => i_clock,
dataa => r_wdata_fp,
result => r_wdata
);
fp_mult_i1 : fp_mult
PORT MAP
(
clock => i_clock,
dataa => r_data_fp,
datab => r_coef, -- 12.1602454933
result => r_wdata_fp
);
end rtl;