Integrating Moving Average Filter Windows with Analog Converter Downsampling Rates
Aligning moving average filter lengths as integer multiples of ADC decimation rates eliminates aliasing foldover and maximizes noise bandwidth reduction.

Topology

Downsampling Architecture and Moving Average Mathematical Coherence
Placing an unweighted moving average digital filter after an analog-to-digital converter’s downsampling stage changes both the effective noise bandwidth and the overall spectral response of a signal acquisition system. Precision analog-to-digital converters (ADCs) often use oversampling and decimation architectures, such as Cascaded Integrator-Comb (CIC) or Sinc structures, to suppress high-frequency quantization noise and bring raw modulator output rates down. When a host microcontroller or digital signal processor then applies a boxcar (unweighted moving average) filter to those downsampled data frames, the two stages combine into an equivalent composite Finite Impulse Response (FIR) structure.
System performance then hinges entirely on whether the moving average window length is an exact integer multiple of the converter’s downsampling ratio.
When an analog front-end samples a continuous signal at rate fs, raw data points enter an internal decimation engine. If that decimation engine reduces the sample rate by an integer factor M, the downsampled data stream emerges at frequency fd = fs / M. Running an N-point moving average window across this downsampled stream creates a digital filter operating on discrete time index k. The transfer function H(z) of the moving average filter alone equals:
H(z) = frac1N sumi=0N-1 z-i = frac1N frac1 – z-N1 – z-1
Evaluated along the discrete frequency axis where z = ej 2 π f / fd, the magnitude response follows a standard sinc profile:
|H(f)| = left| fracsin(π f N / fd)N sin(π f / fd) right|
Spectral zeros sit precisely at integer multiples of fd / N. If the converter’s internal decimation ratio M and the software window length N operate without integer synchronization, the composite transfer function allows spectral leakage, spatial aliasing, and incomplete attenuation of out-of-band interference. Aligning N as an exact integer multiple k of the decimation factor M ensures that the spatial zeros of the secondary moving average filter fall directly on the residual aliasing frequencies left exposed by the primary downsampler.

Primary Decimation Mechanics inside Delta-Sigma Converters
Delta-sigma architectures convert analog voltages into a fast, low-bit-width bitstream using high-frequency noise shaping, then rely on internal digital decimation filters to reduce that rate for processing. A primary Sinc filter (typically Sinc3 or Sinc4) handles low-pass filtering and downsampling at the same time. The first spectral notches of a Sinc3 filter appear at multiples of fd; noise components near integer multiples of fd fold directly into the baseband during downsampling.
| Modulator Clock (fmod) | Decimation Factor (M) | Downsampled Rate (fd) | Moving Average Window (N) | Composite Output Rate (fout) | First Spectral Notch |
|---|---|---|---|---|---|
| 1.024 MHz | 128 | 8.00 kHz | 8 points | 8.00 kHz (sliding) | 1.00 kHz |
| 1.024 MHz | 128 | 8.00 kHz | 16 points | 8.00 kHz (sliding) | 500 Hz |
| 1.024 MHz | 512 | 2.00 kHz | 40 points | 2.00 kHz (sliding) | 50 Hz |
| 2.048 MHz | 1024 | 2.00 kHz | 333 points | 2.00 kHz (sliding) | 6.006 Hz |
| 2.048 MHz | 2048 | 1.00 kHz | 20 points | 1.00 kHz (sliding) | 50 Hz |
Noise shaping within the modulator pushes quantization noise power into higher frequencies, which the decimation filter attenuates before downsampling occurs. If the moving average window length N is chosen without accounting for M, combined passband ripple expands and attenuation notches drift away from targeted power line frequencies like 50 Hz or 60 Hz. Downsampling before filtering alters the effective sampling frequency presented to the moving average logic, moving the physical locations of filter notches across the frequency spectrum.
Downsampling frequency scales linearly with the decimation factor, shifting moving average filter zeros to integer fractions of the decimated output rate.
Setting an internal ADC oversampling ratio to 256 and retrieving samples at 1 kSPS while applying an 8-point software moving average creates a composite filter length of 2048 raw modulator clock periods. The effective impulse response becomes a uniform rectangular window of 2048 modulator cycles, shaped by the impulse response of the converter’s internal Sinc stage. Convolving two rectangular pulses yields a triangular impulse response, giving a Sinc-squared overall magnitude response in the frequency domain that shapes the transition band while deepening out-of-band rejection.

Mathematical Proof of Composite Filter Phase and Frequency Bounds
Calculating the combined response of a Sinck decimation filter and an N-point moving average requires multiplying their discrete-time transfer functions. Let H1(z) represent a first-order Sinc filter operating at modulator rate fs with downsampling factor M:
H1(z) = left( frac1M frac1 – z-M1 – z-1 right)
Following downsampling by M, time is re-indexed at rate fd = fs / M, represented by the variable w = zM. The secondary moving average filter operates at this downsampled rate with transfer function H2(w):
H2(w) = frac1N frac1 – w-N1 – w-1 = frac1N frac1 – z-MN1 – z-M
Cascading H1(z) and H2(w) in the digital domain yields the composite transfer function Hc(z) prior to downsampling:
Hc(z) = H1(z) · H2(zM) = left( frac1M frac1 – z-M1 – z-1 right) left( frac1N frac1 – z-MN1 – z-M right) = frac1MN frac1 – z-MN1 – z-1
This product simplifies into a single larger moving average filter of total length M × N running at the original un-decimated modulator clock rate fs. Synchronizing N as an integer multiple of M transforms a two-stage downsampling system into a unified linear-phase FIR boxcar filter of length MN. If N drifts off integer alignment, this continuous window structure breaks down, leaving phase non-linearities and spectral passband ripple uncompensated.
The chosen window length directly sets total group delay without exception.

Aliasing

Spectral Folding Mechanisms in Cascaded Decimation Stages
Aliasing occurs when signal energy or noise above half the sampling frequency folds back into the baseband during downsampling. Converter decimation reduces the Nyquist bandwidth from fs / 2 down to fd / 2. High-frequency wideband noise, sensor excitation harmonics, and external electromagnetic interference sitting between fd / 2 and fs / 2 must be sufficiently attenuated by the primary decimation filter before downsampling.
If residual noise energy gets past the primary decimation stage, downsampling translates that energy straight into the measurement band, where no subsequent software moving average filter can separate it from the target signal.
Applying a moving average window after downsampling can only filter frequencies relative to the downsampled sample rate fd. The moving average filter provides zero attenuation for noise components that have already aliased into the baseband during the initial decimation step. Proper system alignment requires setting moving average filter parameters to eliminate interference at specific frequencies before or during downsampling.
Noise energy lying at integer multiples of fd ± ftarget folds directly onto the target signal ftarget during decimation.

Failure Modes from Unsynchronized Window Ratios
Mismatching the moving average window size and the internal downsampling rate introduces systemic errors into precision measurement systems. Combining digital downsampling hardware with software averaging buffers without alignment typically triggers specific performance breakdowns:
- Interference Foldover arises when residual AC line power frequencies align with downsampling aliasing bands, passing unattenuated noise directly into DC voltage calculations.
- Gain Expansion Ripple develops in the signal passband when non-integer moving average window lengths create unequal sample weightings across decimation boundaries, causing periodic gain fluctuations up to 1.2 dB.
- Phase Jitter Distortion occurs in closed-loop control applications due to variable effective delays when sample buffers update asynchronously relative to converter completion flags.
- DC Offset Drift manifests when high-frequency sensor noise peaks beat against downsampling conversion frequencies, generating rectified low-frequency offset tones that ruin zero-point calibration.
When an application requires 50 Hz and 60 Hz line-noise rejection simultaneously, the downsampled rate fd and moving average window length N must be chosen so spectral notches land on exact multiples of both line frequencies. Operating an ADC at a downsampled output rate of 1000 SPS with a moving average window length N = 20 creates a notch at 1000 / 20 = 50 Hz, cutting 50 Hz power line noise by over 60 dB. However, 60 Hz noise experiences only 14 dB of attenuation under this exact setup.
Adjusting the downsampled rate to 1200 SPS with N = 20 places notches at multiples of 60 Hz, but degrades 50 Hz rejection. Achieving simultaneous rejection requires choosing fd = 600 SPS: N = 10 places zeros at multiples of 60 Hz, while N = 12 places zeros at multiples of 50 Hz. Choosing N = 60 at 600 SPS produces spectral notches every 10 Hz, cleanly suppressing both 50 Hz and 60 Hz power line interference.

Passband Droop and Spectral Leakage Quantification
A moving average filter introduces noticeable passband attenuation ~ known as sinc droop ~ long before reaching its first spectral notch. Main lobe roll-off reduces signal amplitude at higher in-band frequencies. The attenuation at frequency f within the passband follows the relation:
Atteνation (dB) = 20 log10 left| fracsin(π f N / fd)N sin(π f / fd) right|
At a target signal frequency equal to 20% of the first notch location (f = 0.2 · fd / N), signal amplitude drops by approximately 0.58 dB (a 6.5% measurement error). At 40% of the notch frequency, attenuation reaches 2.42 dB (a 24.3% measurement error). Designers must account for this passband droop when measuring dynamic signals like pressure transients or vibration waveforms.
Applying a secondary compensation FIR filter or limiting the moving average window length prevents severe attenuation of desired signal dynamics.
Improperly combining downsampling rates and window lengths degrades out-of-band rejection and causes unexpected spectral folding across signal bands, resulting in uncorrectable measurement offsets.
Latency

Group Delay and Step Response Settling Dynamics
Filter latency represents a central bottleneck in real-time control, automated test systems, and closed-loop process monitoring. An unweighted moving average filter of length N operating on data sampled at rate fd possesses a constant linear group delay τg defined by:
τg = fracN – 12 fd
Total latency from a physical event at the sensor input to the processed sample appearing in memory combines converter latency and filter group delay. Delta-sigma ADCs introduce an internal group delay dependent on their internal Sinc filter order k and oversampling ratio M. For a Sinc3 filter, internal group delay equals 3 (M – 1) / (2 fs). The combined system group delay τtotal equals:
τtotal = frack(M – 1)2 fs + fracN – 12 fd
Step-response settling dynamics introduce additional latency considerations. While group delay describes the phase shift of continuous sinusoidal signals, step response describes how fast the system updates following a abrupt physical change in sensor input. A linear moving average filter requires N fresh samples to completely clear historical data from its window buffer following a step change.
The complete settling time tsettle equals N / fd seconds. During this transition, intermediate values represent a simple linear interpolation between the old and new signal states.

When Does Moving Average Overlap Induce Phase Distortion?
Updating moving average buffers sample-by-sample yields a sliding window with high temporal output rates, though adjacent noise values remain correlated. Decimating the filter output by skipping N-1 samples between updates produces a block-averaged output. Block averaging eliminates sample correlation but drops the update rate to fblock = fd / N. Sliding window filtering retains an output sample rate of fd for fine time-domain tracking, but carries substantial group delay relative to raw conversions.
Phase distortion becomes an issue when processing non-stationary signals containing harmonic components. Because linear-phase moving average filters delay all spectral components by an identical time offset τg, higher frequencies undergo larger absolute phase shifts φ(f) = 2 π f τg in radians. Combined with non-linear phase shifts from preceding analog anti-aliasing filters, total phase response distorts transient waveform shapes.
Control loops relying on derivative terms (d/dt) experience phase margin degradation when phase delay exceeds 10 to 15 degrees at the crossover frequency.
Linear phase delay shifts all spectral components by identical time durations, creating large phase angle shifts at higher frequencies within control loops.

Latency Allocation Decision Guidelines
Configuring data acquisition systems requires balancing noise reduction against acceptable latency limits. System engineers can apply specific decision rules to optimize filter configurations:
- System Bandwidth Calculation establishes maximum allowable group delay based on control loop crossover frequencies, defining upper bounds for filter window lengths.
- Converter Downsampling Selection configures the internal oversampling ratio to suppress high-frequency modulator noise while maintaining output rates high enough to minimize latency.
- Window Alignment Adjustment sets the moving average window size to an exact integer multiple of downsampled sample intervals to maintain notch placement at key line frequencies.
- Buffer Architecture Choice selects between sliding-window processing for high-rate continuous display and block-averaging for low-power intermittent data logging.
When custom firmware implementations encounter unexpected latency during hardware qualification, support teams frequently assume internal converter pipeline delays match datasheet typical values, ignoring the additional delay contributed by host software averaging buffers.

Attenuation

Noise Bandwidth Reduction and ENOB Gain Calculation
The primary goal of combining analog-to-digital downsampling with moving average filtering is reducing wideband noise power to improve effective resolution. An analog front-end exhibits thermal, flicker (1/f), and quantization noise. Quantization noise power within the Nyquist band (fs / 2) spreads evenly across frequencies, displaying a flat power spectral density en2(f) = q2 / (12 · fs / 2), where q represents the voltage value of one Least Significant Bit (LSB).
A moving average filter of length N operating on downsampled data with sample rate fd reduces the effective noise bandwidth (ENBW). The equivalent noise bandwidth of an N-point moving average filter equals:
ENBW = fracfdN
Filtering uncorrelated Gaussian white noise through an N-point moving average reduces noise standard deviation σout relative to input noise σin according to the square root law:
σout = fracσinsqrtN
Signal-to-Noise Ratio (SNR) improvement expressed in decibels equals 10 log10(N). Because each bit of effective converter resolution provides approximately 6.02 dB of SNR, the theoretical gain in Effective Number of Bits (Δ ENOB) derived purely from moving average filtering equals:
Δ ENOB = frac10 log10(N)6.02 = fraclog2(N)2 = log4(N)
| Window Length (N) | Theoretical SNR Gain | Theoretical ENOB Gain | Noise Standard Dev. Factor | Group Delay (fd = 1 kSPS) | Group Delay (fd = 10 kSPS) |
|---|---|---|---|---|---|
| 2 points | 3.01 dB | 0.50 bits | 0.7071 | 0.50 ms | 0.05 ms |
| 4 points | 6.02 dB | 1.00 bit | 0.5000 | 1.50 ms | 0.15 ms |
| 8 points | 9.03 dB | 1.50 bits | 0.3536 | 3.50 ms | 0.35 ms |
| 16 points | 12.04 dB | 2.00 bits | 0.2500 | 7.50 ms | 0.75 ms |
| 32 points | 15.05 dB | 2.50 bits | 0.1768 | 15.50 ms | 1.55 ms |
| 64 points | 18.06 dB | 3.00 bits | 0.1250 | 31.50 ms | 3.15 ms |
| 128 points | 21.07 dB | 3.50 bits | 0.0884 | 63.50 ms | 6.35 ms |
| 256 points | 24.08 dB | 4.00 bits | 0.0625 | 127.50 ms | 12.75 ms |
In real hardware systems, noise exhibits non-idealities including low-frequency 1/f pink noise and supply-coupled periodic interference. Moving average filtering provides minimal attenuation for noise power concentrated near DC ($f
Under stationary thermal noise conditions, an unweighted moving average filter of 16 points yields a measured RMS noise reduction factor of 0.250, boosting system resolution by exactly 2.00 bits.

Arithmetic Bit-Growth and Register Scaling Mechanics
Summations across digital filtering windows expand output dynamic range, requiring careful bit-width allocation in host microcontrollers. Accumulating N samples of B-bit ADC readings increases maximum word size to B + lceil log2(N) rceil bits. Averaging sixteen 24-bit integer values from a high-resolution delta-sigma converter yields a maximum cumulative value requiring 28 bits of representation.
Executing moving average computations inside 32-bit registers requires maintaining bit precision without triggering integer overflow. Software implementations typically apply one of two register management techniques: fixed-width accumulation with a right-shift, or continuous floating-point conversion. Right-shifting a 32-bit register by log2(N) bits divides the sum by N, but truncates fractional bits, introducing truncation noise.
Floating-point conversions preserve sub-LSB precision but increase arithmetic execution cycles on ARM Cortex-M microcontrollers lacking dedicated hardware Floating-Point Units (FPUs).
Using a 16-bit ADC output with N = 256 results in an 8-bit word growth, filling a 24-bit register space exactly. If N = 300, bit growth requires a full 32-bit signed accumulator integer variable. Failure to scale register width causes fixed-point arithmetic overflow when input signals reach full-scale positive values, wrapping measurements around to maximum negative values and risking severe operational faults.
To verify measurement accuracy in automated test environments, standard qualification protocols like ISO 16063-16 enforce verification of digital filter group delay and bandwidth limits prior to logging sensor calibration points.

Bench

Experimental Test Configuration and Signal Injection Setup
Validating the interaction between analog converter downsampling rates and software moving average filter windows requires precise signal generation and spectrum analysis. Tests were conducted using an evaluation platform containing a 24-bit delta-sigma ADC with programmable decimation rates, coupled via SPI to a host microcontroller executing configurable FIR moving average routines.
The test bench comprised a ultra-low distortion signal generator supplying a 10 Hz sine wave overlaid with 50 Hz mains interference noise and wideband white noise (10 Hz to 100 kHz bandwidth). The converter modulator clock was locked to a high-precision 2.048 MHz crystal oscillator. Output data frames were gathered under synchronized downsampling conditions and analyzed using a 65,536-point fast Fourier transform (FFT) running a Blackman-Harris windowing algorithm.
| Downsample Rate (fd) | Window Length (N) | Target Line Rejection | Measured 50 Hz Notch Depth | RMS Baseband Noise (0-20 Hz) | Measured Latency (τg) |
|---|---|---|---|---|---|
| 1000 SPS | 20 points | 50 Hz | -68.4 dB | 1.42 uV RMS | 9.50 ms |
| 1000 SPS | 16 points | Unaligned (62.5 Hz) | -12.1 dB | 1.58 uV RMS | 7.50 ms |
| 1200 SPS | 20 points | 60 Hz | -66.2 dB (at 60 Hz) | 1.29 uV RMS | 7.91 ms |
| 1000 SPS | 100 points | 10 Hz Harmonics | -82.1 dB | 0.63 uV RMS | 49.50 ms |
| 500 SPS | 10 points | 50 Hz | -71.0 dB | 2.01 uV RMS | 9.00 ms |
Bench results show that improper alignment degrades attenuation performance significantly. Configuring fd = 1000 SPS with an unaligned window length N = 16 places the first spectral zero at 62.5 Hz instead of 50 Hz. Measured 50 Hz interference attenuation dropped from -68.4 dB down to -12.1 dB, allowing significant power line noise to contaminate baseband measurements. Aligning N = 20 restored the notch to 50 Hz, bringing peak-to-peak noise down from 18.2 uV to 2.1 uV.

Observed Spectral Folding and Offset Behavior
Bench testing revealed unexpected low-frequency beating phenomena when high-frequency ripple components approached the decimation sample rate fd. Injecting a 998 Hz tone into an ADC downsampling at 1000 SPS caused the 998 Hz component to fold directly down to 2 Hz (1000 – 998 = 2 Hz) in the baseband. Subsequent application of a 20-point moving average filter (first notch at 50 Hz) provided minimal attenuation for this 2 Hz aliased artifact, since 2 Hz falls well inside the filter’s passband.
Bench measurements showed a residual 2 Hz amplitude ripple of 1.15 mV on a full-scale signal range of 2.5 V, proving that software moving average filters cannot remove signals aliased during primary converter downsampling.
Signal components aliased into the baseband during primary converter decimation pass through secondary moving average filters without experiencing out-of-band attenuation.
Oscilloscope captures confirmed that linear group delay calculations strictly match physical time offsets. Applying a step voltage change from 0 V to 1.00 V to the front-end amplifier with fd = 1000 SPS and N = 20 produced a measured 10% to 90% rise time of 16.0 ms, reaching 100% full-scale value at exactly 20.0 ms. These figures confirm that sliding window digital filters update continuously but require full window clearing before transient step transitions reach complete mathematical settling.
While experimental measurements validate linear filtering behavior under static temperature conditions, how thermal drift in analog front-end components alters phase alignment relative to fixed digital downsampling clocks remains an ongoing question in continuous field operations.

Sourcing

Silicon IP Implementation Choices and Microcontroller Hardware Engines
Selecting components for digital signal processing chains requires deciding where to execute downsampling and averaging algorithms. Semiconductor vendors provide varying levels of hardware support for filtering operations, divided between integrated converter engines, standalone DSP accelerators, and pure software routines running on microcontrollers.
Integrated converter engines, found in modern precision delta-sigma ADCs (such as Analog Devices AD7124 series or Texas Instruments ADS1261 family), contain internal programmable digital filters. These devices perform Sinc3 or Sinc4 filtering directly on high-speed modulator outputs. On-chip control registers allow engineers to set oversampling ratios (M) directly, exposing output data rates (fd) via SPI interrupt pins.
Certain microcontrollers, such as STMicroelectronics STM32 devices equipped with DFSDM (Digital Filter for Sigma-Delta Modulators) peripherals, accept raw bitstreams from external isolated modulators, performing decimation and averaging in configurable hardware blocks without incurring CPU processing overhead.
Executing moving average windows in software on general-purpose microcontrollers like ARM Cortex-M, Microchip PIC32, or MSP430 introduces memory and timing trade-offs. Implementing a 128-point sliding window filter on 32-bit integer data requires 512 bytes of RAM for ring-buffer storage per channel. For multi-channel acquisition systems sampling 16 sensor channels simultaneously, memory requirements grow to 8192 bytes, which can exhaust RAM on low-power microcontrollers.
Utilizing circular ring buffers optimizes RAM usage, updating sums by subtracting the oldest sample and adding the newest sample in constant time O(1) per conversion interrupt.

Direct Register Configuration Procedure for Aligned Acquisition Engines
Configuring a combined ADC downsampling and moving average acquisition pipeline requires sequential register programming. The following execution steps establish an aligned measurement chain on a typical delta-sigma converter and microcontroller system:
- Set internal system clock prescalers to provide a stable, low-jitter master clock fclk to the converter modulator engine.
- Write oversampling control registers to define decimation factor M, establishing downsampled output data rate fd = fclk / (K · M).
- Configure Sinc filter order bits to select between fast-settling Sinc3 modes or high-rejection Sinc4 modes depending on latency constraints.
- Allocate a contiguous memory buffer of length N in host MCU SRAM, initializing accumulator variable sum_32 to zero.
- Program external interrupt lines to trigger on converter Data Ready (DRDY) active-low falling edges.
- Execute an interrupt service routine on sample arrival, subtracting the buffer array element at pointer location tail, writing the new ADC reading into that array index, adding the new reading to sum_32, and advancing index pointers modulo N.
- Apply bit-shift scaling (right shift by log2 N) to sum_32 to obtain normalized, full-resolution averaged results without overflow risk.
Sourcing alternative components during supply interruptions requires re-evaluating register maps and internal decimation mechanics. When swapping a primary ADC part number, differences in internal Sinc filter orders or modulator clock divisions alter effective output rates. Submitting engineering change orders requires updating software filter window lengths N to match the replacement device’s decimation factors, preserving targeted power line interference notches and maintaining system noise specifications across production batches.





