ALU - MOVING AVERAGE
Configurable moving average filter implemented via Vivado HLS. Computes the running average over a programmable window length (16-65536 samples). Supports signed and unsigned data with configurable bit width (4-64 bits). Features hold function for pause/resume operation.
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
Freeze control signal, active high.
0: Normal operation, buffer updates on each sample1: Hold current state, output frozen
LENGTH samples.
DATAOUT contains a valid average (after initial fill).
Properties
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
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). RuntimeLENGTH must be ≤ this value.
Default: 1024
Options: 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536
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_INy[n]→DATAOUTN→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 = 0without 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