Sie sind auf Seite 1von 7

library ieee;

use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.jet_finder;
use work.matrix;
entity algorithm is
port( clock : in std_logic;
-- in11, in12, in13, in14, in21, in22, in23, in24, in31, in32, in33
, in34, in41, in42, in43, in44
in1 : in std_logic_vector(47 downto 0);
-- : in std_logic_vector(2 downto 0);
out11, out12, out13, out14, out21, out22, out23, out24, out31, o
ut32, out33, out34, out41, out42, out43, out44
: out std_logic_vector(2 downto 0));
end algorithm;
architecture behavior of algorithm is
type mat is array(7 downto 0, 7 downto 0) of std_logic_vector(2 downto 0);
type mat2 is array(7 downto 0, 7 downto 0) of std_logic_vector(2 downto 0);
signal mat_of_in : mat;
signal mat_of_out : mat2;
begin
ROW: for i in 0 to 7 generate
begin
COLUMN: for j in 0 to 7 generate
begin
-- C: for k in 0 to 15 generate
-- begin
ZEROS: if (i = 0 or i = 1 or i = 6 or i = 7 or j
= 0 or j = 1 or j = 6 or j = 7) generate
begin
matrix_maker : matrix
port map(
clock => clock,
matelem => mat_of_in(i,j),
inthing =>(others=>'0'));
-- end generate;
--mat_of_in(i,j) <= (others => '0');
MATRIX_BODY: if (i /= 0 and i /= 1 and i /= 6 an
d i /= 7 and j /= 0 and j /= 1 and j /= 6 and j /= 7) generate
begin
matrix_body_make : matrix
port map(
clock => clock,
matelem => mat_of_in(i,j),
inthing => in1(((i-2)*3+(j-2)*4*3+3) dow
nto ((i-2)*3+(j-2)*4*3)));
--(i-2)*3+(j-2)*4*3 (+3)
--end process;
SCANNER:
for l in 2 to 5 generate
begin
SCAN:
for m in 2 to 5 generate
begin
jet_find : jet_find
er
port map(
clock => clock,
a => mat_of_in(i, j),
b => mat_of_in(i-1, j),
c => mat_of_in(i+1, j),
d => mat_of_in(i, j-1),
e => mat_of_in(i, j+1),
f => mat_of_in(i-1, j-1),
g => mat_of_in(i+1, j-1),
h => mat_of_in(i-1, j+1),
z => mat_of_in(i+1, j+1),
sum => mat_of_out(i, j));
end generate;
end generate;
end generate;
end generate;
end generate;
end generate;
--end generate;
out11 <= mat_of_out(2,2);
out12 <= mat_of_out(2,3);
out13 <= mat_of_out(2,4);
out14 <= mat_of_out(2,5);
out21 <= mat_of_out(3,2);
out22 <= mat_of_out(3,3);
out23 <= mat_of_out(3,4);
out24 <= mat_of_out(3,5);
out31 <= mat_of_out(4,2);
out32 <= mat_of_out(4,3);
out33 <= mat_of_out(4,4);
out34 <= mat_of_out(4,5);
out41 <= mat_of_out(5,2);
out42 <= mat_of_out(5,3);
out43 <= mat_of_out(5,4);
out44 <= mat_of_out(5,5);
end behavior;
entity jet_finder is
port ( clock : in std_logic;
in2 : in std_logic_vector(7 downto 0);
jet_found : out std_logic_vector(15 downto 0
);
mean : in std_logic_vector(7 downto 0);
noise_found : out std_logic_vector(7 downto 0)
--tester : out std_logic_vector(4 downto 0)
);
end jet_finder;
architecture behavior of jet_finder is
constant row : integer := 5; --This d
efines the number of rows in the matrix, including the buffer made up of zeros
constant column : integer := 5; --Dido for colum
ns
constant max_bit : integer := 1; --This d
efines what the position of the maximum bit is of the input data for each CELL (
so one less than the lenth)
type matrix is array(row downto 0, column downto 0) of std_logic_vector(max_bit
downto 0);
type matrix2 is array(row downto 0, column downto 0) of std_logic_vector((max_bi
t + 1) downto 0);
type matrix4 is array(row downto 0, column downto 0) of std_logic_vector((max_bi
t + 2) downto 0);
begin
process(clock) is
variable mat_of_in : matrix4;
variable output : std_logic_vector(15 downto 0) := (others => '0');
variable noise : std_logic_vector(7 downto 0);
variable mat_of_out : matrix4;
variable mat_of_mean : matrix;
variable mat_of_4sigma : matrix4;
variable mat_of_2sigma : matrix2;
--constant mean : std_logic_vector(7 downto 0) := "01010101";
constant std_dev : std_logic_vector(7 downto 0) := "00000000";
begin
for a in 0 to 5 loop
for b in 0 to 5 loop
if (a = 0 or a = 1 or a = 5 or a = 4 or b = 0 or b = 1 or b = 5
or b = 4) then
mat_of_mean(a,b) := (others => '0');
else
mat_of_mean(a,b) := mean(((a-2)*2+(b-2)*2*2+1) downto ((
a-2)*2+(b-2)*2*2));
end if;
end loop;
end loop;
for c in 0 to 5 loop
for d in 0 to 5 loop
if (c = 0 or c = 1 or c = 4 or c = 5 or d = 0 or d = 1 or d = 4
or d = 5) then
mat_of_2sigma(c,d) := (others => '0');
else
mat_of_2sigma(c,d) := std_logic_vector(unsigned(mat_of_m
ean(c,d))+unsigned(std_dev(((c-2)*2+(d-2)*2*2+1) downto ((c-2)*2+(d-2)*2*2)) & '
0'));
end if;
end loop;
end loop;
for e in 0 to 5 loop
for f in 0 to 5 loop
if (e = 0 or e = 1 or e = 4 or e = 5 or f = 0 or f = 1 or f = 4
or f = 5) then
mat_of_4sigma(e,f) := (others => '0');
else
mat_of_4sigma(e,f) := std_logic_vector(unsigned(mat_of_m
ean(e,f))+(unsigned(std_dev(((e-2)*2+(f-2)*2*2+1) downto ((e-2)*2+(f-2)*2*2)) &
'0' & '0')));
end if;
end loop;
end loop;
if (rising_edge(clock)) then
for l in 0 to 5 loop
for m in 0 to 5 loop
if (l = 0 or l = 1 or l = 4 or l = 5 or m = 0 or m = 1 or m = 4
or m = 5) then
mat_of_in(l,m) := (others => '0');
else
mat_of_in(l,m) := ('0' & '0' & in2(((l-2)*2+(m-2)*2*2+1)
downto ((l-2)*2+(m-2)*2*2)));
end if;
end loop;
end loop;
end if;
if (rising_edge(clock)) then
for i in 0 to 5 loop
for j in 0 to 5 loop
if (i = 0 or i = 1 or i = 4 or i = 5 or j = 0 or j = 1 o
r j = 4 or j = 5) then
mat_of_out(i, j) := (others => '0');
elsif (mat_of_in(i,j) >= mat_of_4sigma(i,j)) and
((mat_of_in(i,j) >= mat_of_2sigma(i,j)) or (mat_
of_in(i-1, j) >= mat_of_2sigma(i-1, j)) or (mat_of_in(i+1, j) >= mat_of_2sigma(i
+1, j)) or (mat_of_in(i, j-1) >= mat_of_2sigma(i, j-1))
or (mat_of_in(i, j+1) >= mat_of_2sigma(i, j+1))
or (mat_of_in(i-1, j-1) >= mat_of_2sigma(i-1, j-1)) or (mat_of_in(i+1, j-1) >= m
at_of_2sigma(i+1, j-1)) or (mat_of_in(i-1, j+1) >= mat_of_2sigma(i-1, j+1))) the
n

mat_of_out(i, j) := std_logic_vector(unsigned(ma
t_of_in(i,j)) + unsigned(mat_of_in(i-1, j)) + unsigned(mat_of_in(i+1, j)) + unsi
gned(mat_of_in(i, j-1))
+ unsigned(mat_of_in(i, j+1)) + unsigned(mat_of_
in(i-1, j-1)) + unsigned(mat_of_in(i+1, j-1)) + unsigned(mat_of_in(i-1, j+1))
+ unsigned(mat_of_in(i+1, j+1)));
noise := (others => '0');
else
mat_of_out(i,j) := (others => '0');
noise := in2;
end if;
end loop;
end loop;
end if;
if (rising_edge(clock)) then
for i in 2 to 3 loop
for j in 2 to 3 loop
output(((i-2)*4+(j-2)*4*2+3) downto ((i-2)*4+(j-2)*4*2)) := mat_
of_out(i,j);
end loop;
end loop;
end if;
--tester <= mat_of_4sigma(2,2);
jet_found <= output;
noise_found <= noise;
end process;
end behavior;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity noise is
port( clock : in std_logic;
in_noise : in std_logic_vector(7 downto 0);
out_average : out std_logic_vector(7 downto 0)
);
end noise;
architecture behavior of noise is
type mean_mat is array (1 downto 0, 1 downto 0) of std_logic_vector(1 downto 0);
type total_mat is array (1 downto 0, 1 downto 0) of std_logic_vector(3 downto 0)
;
--type average_mat is array(1 downto 0, 1 downto 0) of std_logic_vector(1 downto
0);
begin
process(clock) is
--variable total : std_logic_vector(11 downto 0) :=
(others => '0');
variable average : std_logic_vector(11 downto 0) := (others
=> '0');
variable i : integer := 0;
variable mean_matrix : mean_mat;
variable total_matrix : total_mat;
variable average_matrix : mean_mat;
begin
--if (rising_edge(clock)) then
-- if in_noise >= "00000001" then
-- for x in 0 to 1 loop
-- for y in 0 to 1 loop
-- mean_matrix(x,y) := in_noise((x+y+1) downto (x +
y));
-- total_matrix(x,y) :=
-- if i < 4 then
-- i := i + 1;
-- mean_matrix(x,y) := mean_matrix(
x,y) +
if (rising_edge(clock))then
if i = 0 then
for a in 0 to 1 loop
for b in 0 to 1 loop
total_matrix(a,b) := ("0000");
end loop;
end loop;
end if;
if in_noise >= "00000001" then
i := i + 1;
for x in 0 to 1 loop
for y in 0 to 1 loop
total_matrix(x,y) := std_logic_vector(unsigned(total_mat
rix(x,y)) + unsigned(in_noise((x+(y*2)+1) downto (x+(y*2)))));
end loop;
end loop;
if i = 4 then
i := 0;
-- mean_matrix(x,y) := std_logic_ve
ctor(shift_right(unsigned(total(x+y+1 downto x+y)), 2));
for s in 0 to 1 loop
for t in 0 to 1 loop
total_matrix(s,t) := std_logic_vector(sh
ift_right(unsigned(total_matrix(s,t)), 2));
for c in 0 to 1 loop
for d in 0 to 1 loop
average_matrix(c,d) := t
otal_matrix(c,d)(1 downto 0);
end loop;
end loop;
average((s+(t*2)+1) downto (s+(t*2))) :=
average_matrix(s,t);
end loop;
end loop;
end if;
-- end loop;
-- end loop;
-- end if;
end if;
end if;
out_average <= std_logic_vector(average(7 downto 0));
end process;
end behavior;

Das könnte Ihnen auch gefallen