-- A recursive moving average calculation is given as
-- y[n] = y[n - 1] + (x[n] - x[n - N]) / N
-- which is easily implemented in digital logic (again with the caveat that N is
-- restricted to powers-of-two), but requires additional block RAM resources that
-- are otherwise not necessary in a simple arithmetic mean.
--==============================================================================--
entity moving_average is
GENERIC
(
DATA_W : integer := 32;
MAX_POINTS : integer := 64;
SCALING_BY_2 : integer := 0;
N_W : integer := integer(ceil(log2(real(MAX_POINTS))))
);
PORT
(
reset_n : in std_logic;
clk : in std_logic;
N : in std_logic_vector(N_W downto 0);
valid_in : in std_logic;
x : in std_logic_vector(DATA_W-1 downto 0);
valid_out : out std_logic;
y : out std_logic_vector(DATA_W-1 downto 0)
);
end moving_average;
--==============================================================================--
...