Cross Correlator (real-time, single lag)
Streaming cross-correlator that continuously computes a single-lag windowed cross correlation between two signed input samples X and Y. LAG (the delay applied to Y) and WIN_LEN (the length of the moving accumulation window) are both runtime input pins. II=1 pipeline: one new correlation value on R_OUT every clock.
Introduction
The block computes, on every clock, the sliding-window cross correlation
$$ R[n] = \sum_{i=0}^{\text{WIN_LEN}-1} X[n-i] \cdot Y[n-i-\text{LAG}] $$
using a moving-sum implementation. Only one MAC is required regardless
of window length: at each clock a new product X[n] * Y[n-LAG] is added
to the accumulator and the product that leaves the window (WIN_LEN clocks
earlier) is subtracted.
Both LAG and WIN_LEN are runtime input pins so the same synthesized IP
can serve many use cases. Their maximum values (LagMax, WindowMax) are
compile-time properties that size the two internal BRAMs (Y delay line and
product ring buffer).
Pin Description
Properties
Bit width of the signed X and Y input samples
Bit width of X and Y (signed). 4..32 bits. The internal product width is 2*InputSize bits.Default: 16
Range: 4 – 32
Maximum runtime value of LAG. Sizes the Y delay line (BRAM).
Maximum runtime value of the LAG pin. Sizes the Y delay-line BRAM toLagMax + 1 entries of InputSize bits. Trade-off: larger LagMax
allows more delay flexibility but consumes more BRAM.
Default: 256
Options: 16 32 64 128 256 512 1024 2048 4096
Maximum runtime value of WIN_LEN. Sizes the product ring buffer (BRAM).
Maximum runtime value of the WIN_LEN pin. Sizes the product ring-buffer BRAM toWindowMax entries of 2*InputSize bits.
This is normally the biggest BRAM in the IP.
Default: 1024
Options: 64 128 256 512 1024 2048 4096 8192 16384
Bit width of the R_OUT accumulator (signed).
Bit width of the R_OUT accumulator (signed). Must be wide enough to hold the worst-case sum:AccumBits >= 2*InputSize + ceil(log2(WindowMax))
to prevent overflow.
Default: 48
Range: 16 – 96
Functional description
Sliding-sum update
The classic direct-form cross correlation requires WIN_LEN MACs to compute every output sample. The moving-sum variant folds it to a single MAC per clock:
$$ R[n] = R[n-1] + X[n],Y[n-\text{LAG}] - X[n-W],Y[n-W-\text{LAG}] $$
where $W = \text{WIN_LEN}$. The two subtractions and the new product are independent, so the design pipelines to II = 1.
Memory
- Y delay line: BRAM of depth
LagMax + 1, holds the lastLagMax + 1samples of Y soY[n - LAG]can be read at any runtime lag. - Product ring buffer: BRAM of depth
WindowMax, holds the lastWindowMaxproducts so the “old” product that must be removed from the window can be read at any runtimeWIN_LEN.
The accumulator is a single register of AccumBits bits.
Warm-up
For the first WIN_LEN samples after a reset the ring buffer holds zeros
(BRAM is zero-initialised), so R_OUT grows monotonically until the
window is full. After that, the sliding sum tracks the current window
exactly.
Reset
A high RESET on any clock clears the accumulator to zero (but does not
clear the delay lines). Typical usage: hold RESET high while startup logic
brings LAG and WIN_LEN to their intended values, then release.