-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathnoiseshaper.vhd
202 lines (144 loc) · 4.33 KB
/
noiseshaper.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
----------------------------------------------------------------------------------
-- Engineer: github.com/YetAnotherElectronicsChannel
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;
entity noiseshaper is
port (
clk : in std_logic;
ns_in : in signed (31 downto 0);
ns_valid_in : in std_logic;
ns_out : out signed(4 downto 0) := (others=>'0');
ns_valid_out : out std_logic := '0';
busy : out std_logic := '0';
limit : out std_logic := '0';
a1 : integer;
a2 : integer;
a3 : integer;
a4 : integer;
b1 : integer;
b2 : integer;
b3 : integer;
b4 : integer;
g1 : integer;
g2 : integer
);
end noiseshaper;
architecture Behavioral of noiseshaper is
--summing points after each node
signal x1 : signed(31 downto 0) := (others=>'0');
signal x2 : signed(31 downto 0) := (others=>'0');
signal x3 : signed(31 downto 0) := (others=>'0');
signal x4 : signed(31 downto 0) := (others=>'0');
signal x5 : signed(31 downto 0) := (others=>'0');
--delay registers for integrators
signal x1d : signed(31 downto 0) := (others=>'0');
signal x2d : signed(31 downto 0) := (others=>'0');
signal x3d : signed(31 downto 0) := (others=>'0');
signal x4d : signed(31 downto 0) := (others=>'0');
signal x5_24b : signed(23 downto 0) := (others=>'0');
signal state : integer := 0;
signal in_sample : signed(31 downto 0) := (others=>'0');
--multiplier signals
signal mul_inp_2 : signed(15 downto 0) := (others=>'0');
signal mul_inp_1 : signed(31 downto 0) := (others=>'0');
signal mul_result : signed(31 downto 0) := (others=>'0');
begin
process (mul_inp_1, mul_inp_2)
begin
--multiply and do right-shift by 15 (fixed-point mult with 32-bit int and q1.15 value)
mul_result <= resize(shift_right(mul_inp_1*mul_inp_2,15),32);
end process;
process (clk)
begin
if (rising_edge(clk)) then
--start and calculate through the structure as shown in the block diagram in documentation-pdf file
if (state = 0) then
ns_valid_out <= '0';
busy <= '0';
if (ns_valid_in = '1') then
in_sample <= ns_in;
state <= 1;
busy <= '1';
mul_inp_1 <= ns_in;
mul_inp_2 <= to_signed(b1,16);
end if;
elsif (state = 1) then
x1 <= mul_result;
state <= 2;
mul_inp_1 <= x5;
mul_inp_2 <= to_signed(a1,16);
elsif (state=2) then
x1 <= x1 + mul_result;
state <= 3;
mul_inp_1 <= x2;
mul_inp_2 <= to_signed(g1,16);
elsif (state=3) then
x1 <= x1 + mul_result + x1d;
mul_inp_1 <= in_sample;
mul_inp_2 <= to_signed(b2,16);
state <= 4;
elsif (state=4) then
x2 <= mul_result;
state <= 5;
mul_inp_1 <= x5;
mul_inp_2 <= to_signed(a2,16);
elsif (state = 5) then
x2 <= x2 + mul_result + x2d +x1;
state <= 6;
mul_inp_1 <= in_sample;
mul_inp_2 <= to_signed(b3,16);
elsif (state = 6) then
x3 <= mul_result;
state <= 7;
mul_inp_1 <= x5;
mul_inp_2 <= to_signed(a3,16);
elsif (state = 7) then
x3 <= x3 + mul_result;
state <= 8;
mul_inp_1 <= x4;
mul_inp_2 <= to_signed(g2,16);
elsif (state = 8) then
x3 <= x3 + mul_result + x3d + x2;
state <= 9;
mul_inp_1 <= in_sample;
mul_inp_2 <= to_signed(b4,16);
elsif (state = 9) then
x4 <= mul_result;
mul_inp_1 <= x5;
mul_inp_2 <= to_signed(a4,16);
state <= 10;
elsif (state = 10) then
x4 <= x4 + mul_result + x4d + x3;
state <= 11;
elsif (state = 11) then
x5 <= x4 + in_sample;
state <= 12;
--limit signal
elsif (state = 12) then
if (x5 > to_signed(8388607,31)) then
x5_24b <= to_signed(8388607,24);
limit <= '1';
elsif (x5 < to_signed(-8388607,31))then
x5_24b <= to_signed(-8388607,24);
limit <= '1';
else
x5_24b <= resize(x5,24);
end if;
state <= 13;
-- quantize signal to 5 bit (cut off lsb)
elsif (state = 13) then
x5 <= x5(31 downto 19) & "0000000000000000000";
ns_out <= x5_24b(23 downto 19);
x1d <= x1;
x2d <= x2;
x3d <= x3;
x4d <= x4;
ns_valid_out <= '1';
state <= 0;
limit <= '0';
end if;
end if;
end process;
end Behavioral;