Xilinx
Block Preview

Introduction

The Moving Average block computes the running mean of the input signal over a configurable window:

$$ \mathrm{OUT}[n] = \frac{1}{L} \sum_{i=0}^{L-1} \mathrm{IN}[n-i] $$

where L is the window length computed as $L = 2^{\text{LENGTH}}$, with LENGTH being the exponent input (runtime configurable). The block uses an efficient sliding window algorithm with internal circular buffer, making it suitable for real-time signal smoothing and noise reduction.

A HOLD input allows freezing the computation while maintaining internal state.

Pin Description

DATA_IN Input Variable bit BIT VECTOR
Input data stream to be averaged. Width: Input Data Size (4 – 64 bits). Arithmetic type set by Data Type.
Default: Must be connected
HOLD Input 1 bit BIT

Freeze control signal, active high.

  • 0: Normal operation, buffer updates on each sample
  • 1: Hold current state, output frozen
LENGTH Input 16 bit BIT VECTOR
Averaging window exponent, runtime programmable. Width: 16 bits (unsigned integer). Window size is computed as $2^{\text{LENGTH}}$. Valid range: 4 to 16 (window sizes: 16 to 65536 samples). Example: LENGTH = 5 → window of 32 samples. Changing this value adjusts the filter bandwidth.
CLK Input 1 bit BIT
System clock. Rising edge triggers pipeline advancement and buffer updates.
Default: Default Board Clock
RESET Input 1 bit BIT
Synchronous reset, active high. Clears internal buffer and resets state machine.
Default: Default Board Reset
DATAOUT Output Variable bit BIT VECTOR
Averaged output signal. Width: Input Data Size (same as input). Contains the mean of the last LENGTH samples.
VALID Output 1 bit BIT
Output valid signal, active high. Indicates when DATAOUT contains a valid average (after initial fill).

Properties

Property window

Input Data Size InputDataSize

Bit width of input and output data

Bit width of input and output data. Range: 4 – 64 bits. Determines precision and dynamic range.

Default: 16

Options: 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

Memory Length MemoryLength

Length of the averaging window (power of two)

Maximum averaging window length (memory depth). Allowed values: 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536 (powers of 2). Runtime LENGTH must be ≤ this value.

Default: 1024

Options: 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536

Data Type DataType

Signed or unsigned data type

Input/output arithmetic type:

  • SIGNED: Two’s-complement (ap_int), default
  • UNSIGNED: Non-negative integers (ap_uint)

Default: SIGNED

Options: SIGNED UNSIGNED

Functional description

The moving average implements a boxcar (rectangular) filter in the time domain:

$$ y[n] = \frac{1}{N} \sum_{k=0}^{N-1} x[n-k] $$

where:

  • x[n] → DATA_IN
  • y[n] → DATAOUT
  • N → LENGTH (runtime programmable)

Transfer function

In the frequency domain, the moving average has the response:

$$ H(e^{j\omega}) = \frac{1}{N} \cdot \frac{\sin(N\omega/2)}{\sin(\omega/2)} e^{-j\omega(N-1)/2} $$

This provides low-pass filtering with nulls at multiples of $2\pi/N$.

Window length

The LENGTH input is an exponent that determines the averaging window size as $L = 2^{\text{LENGTH}}$:

LENGTH (exponent) Window Size (samples)
4 16
5 32
6 64
7 128
8 256
9 512
10 1024
11 2048
12 4096
  • Valid range: 4 to 16 (corresponding to window sizes 16 to 65536)
  • Longer windows: better noise reduction, slower response
  • Shorter windows: faster response, less smoothing
  • Power-of-2 windows ensure efficient division (right-shift operation)

Hold function

When HOLD = 1, the filter:

  • Stops updating the internal circular buffer
  • Maintains the current average output
  • Resumes on HOLD = 0 without state loss

Latency

Fixed latency of 4 clock cycles (HLS pipeline).

Typical use cases

  • Noise reduction in sensor data
  • Signal smoothing before feature extraction
  • Baseline estimation in spectroscopy
  • Low-pass filtering in control loops