SpinalHDL
1 / 1
View past submissionsLeaderboard

Description

Moving Average

Design a hardware module for the Moving Average problem.

Given an input stream and a window size n, output the integer moving average for each contiguous window of length n.

Use floor division for the average.

Hardware I/O Encoding

  • stream is a one-dimensional stream of unsigned 13-bit integers
  • n is a scalar unsigned 5-bit integer
  • the output is a one-dimensional stream of unsigned 13-bit integers
  • output element i is the average of input elements i through i + n - 1

Examples

Example 1

  • input stream = [10, 20, 30, 40, 50], n = 3
  • output: [20, 30, 40]

Example 2

  • input stream = [8, 4, 2], n = 2
  • output: [6, 3]

Input

stream

Stream of 13-bit Unsigned Integer (up to 300 elements)
Input sample stream.

n

5-bit Unsigned Integer
Window size.

Output

Stream of 13-bit Unsigned Integer
Floor of the average over each contiguous window of size n.