# Principles of Boxcar Averaging

## Introduction

Capturing low-duty-cycle pulsed signals with high quality and real-time feedback are crucial requirements in many applications in optics and photonics, nanotechnology and materials science, quantum technologies, scanning probe microscopy, and sensing. Boxcar averagers are attractive tools to achieve a high signal-to-noise ratio (SNR) in a minimal amount of measurement time when working with low-duty-cycle signals. Such signals contain relevant information only in a fraction of each period; outside of that short interval only noise is present. A boxcar averager captures the signal from a well-defined temporal window in each period, meaning that all signal components outside of that window are rejected.

Unlike a digitizer or an oscilloscope, the measurement results are immediately available in the digital domain and as analog signals with a user-defined offset and scaling factor. Moreover, integrated PID controllers can process the results to create feedback loops and a lock-in amplifier unit can perform demodulation on the boxcar results if an additional modulation is present.

In this white paper, we illustrate the working principle of a digital boxcar averager, elucidate the relevant measurement parameters, present the state of the art, and provide guidelines for the best choice of measurement technique when working with periodic signals.

## Basic Working Principle

In a typical periodic pulsed signal the information is contained in a short pulse of duration T_{p}, with a significant waiting time between individual pulses, as shown in Figure 1 (a). The signal can be characterized by its duty cycle d = T_{p}/T_{rep}, where T_{rep} = 1/f_{rep} is the inverse of the repetition rate f_{rep} of the pulses. If the duty cycle is low, measuring continuously in time results in a low SNR, as the time intervals between individual pulses contribute to the captured noise but not to the signal.

With a boxcar averager it is possible to acquire the signal only during the pulse duration, ignoring the time intervals between pulses. This corresponds to a multiplication of the input signal with a boxcar function, which is a rectangular pulse train as shown in Figure 1 (b). By matching the period of the boxcar function T_{rep}, the boxcar window width T_{box}, and its position with respect to the signal pulses, the noise between signal pulses can be discarded as illustrated in Figure 1 (c). The signal is then integrated over the duration of T_{box}. Finally, the integrated signal is averaged over N periods as indicated in Figure 1 (d).

## Boxcar Parameters and Their Effects

### Boxcar window

While the repetition rate of the boxcar averager is determined by the repetition rate of the input signal, the boxcar window and the number of averaging periods can be adjusted to optimize the SNR.

The width of the boxcar window T_{box} and its position with respect to the signal pulses are important parameters when optimizing the SNR. Assuming white noise, the ideal boxcar window width can be calculated for a known pulse shape and repetition rate. In Figure 2 (a) we show one period of a periodic signal with Gaussian pulses given by p(t) = A exp(-0.5t^{2}/σ^{2}), where σ = 0.04T_{rep} is the root mean square width. We can now calculate the fraction of the signal s_{box} captured when the signal is integrated over a boxcar window of width T_{box}. For a rectangular boxcar window centered at the Gaussian pulse, s_{box} is given by

\[\mathrm{s_{box}=\int_{-T_{box}/2}^{T_{box}/2}p(t)dt}\]

and increases with T_{box} until the full pulse is captured. However, the captured noise also increases with T_{box}. In the case of white noise, the captured noise n_{box} increases proportionally to the square root of the boxcar window width, namely n_{box} \(\mathrm{\propto}\) √T_{box}.

Figure 2 (b) shows examples of s_{box}, n_{box}, and SNR = s_{box}/n_{box} as functions of T_{box}. Here, the noise was scaled such that SNR = 0.6 if the whole period is captured, i.e., when T_{box} = T_{rep} . One can observe that the captured signal increases with the boxcar window width until it approaches an amplitude of 1 when the full pulse is captured by the boxcar window. Once the signal is completely captured, the SNR scales with √(T_{rep}/T_{box}) due to the rejection of noise outside of the boxcar window. The maximum SNR can be achieved by choosing a boxcar window that does not capture the full pulse. In this example, the SNR is maximized when 84% of the signal is captured, which corresponds to T_{box} ≈ 2.8σ ≈ 0.11T_{rep} as illustrated in Figure 2 (a).

In a real measurement, it is convenient to optimize the SNR by starting with a large boxcar window and then reduce its width until the SNR peaks.

### Averaging periods

After discarding the noise contributions between pulses, the signal is integrated over the duration of each boxcar window and then averaged over multiple periods using a moving average filter. Instead of defining an averaging time T_{avg}, it is convenient to define the number of boxcar periods N = T_{avg}/T_{rep} over which the signal is averaged. Assuming a white noise floor and an ideal boxcar window, the captured signal increases linearly with N, whereas the noise contribution increases as the square root of the sum of the squares of the captured noise. For N boxcar periods, the resulting SNR is therefore given by

\[\mathrm{SNR = \frac{\sum_{i=1}^{N}s_{box}}{\sqrt{\sum_{i=1}^{N}{n^2_{box}}}}=\frac{Ns_{box}}{\sqrt{N{n^2_{box}}}}=\frac{s_{box}}{n_{box}}\sqrt{N}}\]

where we assume that the signal s_{box} and noise n_{box} are the same in each period.

### Spectral response

The output of the boxcar averager Out_{box} can be calculated in the time and the frequency domains using the Plancherel theorem [1]:

where B(t) and S(t) are the boxcar function and the input signal in the time domain, respectively, and \(\hat{\mathrm{B}}\mathrm{(\omega)}\) and \(\hat{\mathrm{S}}\mathrm{(\omega)}\) are their Fourier transforms. To account for the finite number of averaging periods, we introduced \(\hat{\mathrm{B}}\mathrm{_{N}(\omega)}\) as the Fourier transform of a boxcar function with N pulses. To understand the spectral response of a boxcar averager, we discuss B(t), \(\hat{\mathrm{B}}\mathrm{(\omega)}\), and \(\hat{\mathrm{B}}\mathrm{_{N}(\omega)}\) in more detail.

We start by considering an infinite number of averaging periods and use the Fourier theorem stating that a periodic function can be expressed as a sum of sine and cosine terms. The boxcar function B(t) can thus be expressed as

\[\mathrm{B(t)=a_0 + }\sum_{\mathrm{m=1}}^{\mathrm{\infty}}\mathrm{a_m \cos(m\omega_0t)}\]

where the sine terms are zero because B(t) is an even function.

The fundamental frequency ω_{0} = 2π f_{rep} is determined by the repetition rate of the pulses. The coefficient a_{0} = d = T_{box}/T_{rep} corresponds to the duty cycle, and the coefficients a_{m} are given by

Hence the Fourier transform of a boxcar function corresponds to a series of delta peaks at the harmonics of the fundamental frequency f_{rep}, weighted by the coefficients a_{m}. Equation 3 elucidates that a boxcar averager captures the signal - and the noise - contained in the harmonics, and it efficiently rejects other frequency components.

For a large number of averaging periods, \(\hat{\mathrm{B}}\mathrm{_{N}(\omega)}\) approaches \(\hat{\mathrm{B}}\mathrm{(\omega)}\). Figure 3 (a) shows an example of \(\hat{\mathrm{B}}\mathrm{_{N}(\omega)}\) for N = 200 with almost delta-like peaks at the harmonics. The envelope of the Fourier transform, i.e., the weighting of the peaks given by a_{m}, can be identified as the normalized sinc function sinc(x) = sin(π x)/(π x), with zero points given by f/f_{rep} = 1/d. To illustrate the effect of the duty cycle, we show Equation 5 for three different values of duty cycle: d = 0.05, d = 0.1 and d = 0.2 (see Figure 3 (b)). It can be observed that a lower duty cycle puts more relative weight on contributions from higher harmonics.

For a finite number of averaging periods, each peak of \(\hat{\mathrm{B}}\mathrm{_{N}(\omega)}\) turns into a sinc functions itself, with a distance between zeros given by f_{rep}/N. Figure 3 (c) provides an example of \(\hat{\mathrm{B}}\mathrm{_{N}(\omega)}\) with N = 5 periods. The signal is captured at the harmonics, but the side lobes of the sinc function can result in leakage of noise components into the measured signal. Adjusting the number of averaging periods is therefore crucial for the SNR. Without any averaging, i.e., for N = 1, the sum of sinc functions becomes a single sinc function corresponding to the envelope plotted in Figure 3 (b).

The measurement bandwidth f_{3dB} is defined as the frequency where the signal is attenuated by 3 dB, corresponding to approximately 0.71 of the amplitude. For a boxcar averager, f_{3dB} can be calculated from the amplitude decrease of the sinc function centered at zero frequency:

\[\mathrm{sinc\left(\frac{N}{f_{rep}} f_{3dB}\right)} = \mathrm{\sqrt{10^{-3/10}} \approx 0.71},\]

which gives

\[\mathrm{ f_{3dB}}= \mathrm{c\,\frac{f_{rep}}{N}}\]

with c = sinc^{-1}(√(10^{-3/10})) ≈ 0.44. The measurement bandwidth depends linearly on the averaging periods N and the repetition rate f_{rep}.

### Temporal response

The temporal response of a boxcar averager is determined by the calculation of the average over N periods. For a moving average filter, the temporal response is linear in time, with a slope determined by N as illustrated in Figure 3 (d). After a change in the signal, 100% settling is obtained after N pulses. For imaging applications, zero cross-talk between pixels can be achieved by choosing a measurement time equal or larger than NT_{rep} per pixel. A digital implementation enables to monitor the signal continuously by providing intermediate results during the calculation of the moving average over N periods.

### Summary of boxcar parameters and their effects

- Boxcar window: The window width T
_{box}and its position determines the captured signal and noise. Assuming white noise, the SNR increases approximately with √(T_{rep}/T_{box}). The SNR is often maximized for a window width smaller compared to the full width of the input signal pulse. - Averaging periods N: The integrated signal is averaged over N periods using a moving average filter. Assuming white noise, the SNR increases proportionally to √N.
- Spectral response: A short boxcar window T
_{box}puts more relative weight on contributions from higher harmonics. The number of averaging periods N determines the width of the sinc function peaks at the harmonics. - The measurement bandwidth f
_{3dB}scales linearly with f_{rep}/N. - Temporal response: The response of a boxcar averager is linear in time with a slope determined by the number of averaging periods N and the repetition period T
_{rep}.

## State of the Art

The first analog boxcar averagers were built following the principle of boxcar averaging described by Blume and collaborators in 1961 [2]. More recently, the development of analog-to-digital converters with high speed, resolution and linearity has enabled the realization of digital instruments where all calculations are carried out numerically by digital signal processing on a fast field-programmable gate array (FPGA). The Zurich Instruments UHF-BOX Boxcar Averager shown in Figure 4 (a) is the only digital boxcar averager on the market today. It enables dead-time-free operation up to a repetition rate of 450 MHz, and offers additional features such as a periodic waveform analyzer (PWA) and the possibility for baseline suppression. Control and readout of all instrument settings and measurement parameters are achieved thanks to the LabOne^{®} user interface shown in Figure 4 (b) or through application programming interfaces (APIs).

Feature | Analog | UHF-BOX |
---|---|---|

Insensitive to trigger jitter |
no | yes |

Rectangular boxcar window |
no | yes |

Intermediate results |
no | yes |

Measure non-periodic signals |
yes | no |

Graphical user interface |
no | yes |

Periodic waveform analyzer |
no | yes |

Flexible reference window |
no | yes |

Max. averaging periods |
10000 | 1 Mio |

Max. repetition rate for dead-time-free operation |
< 50 kHz | 450 MHz |

### Analog vs digital operation

Analog boxcar averagers are based on a trigger-controlled gate window during which the signal is acquired and integrated, therefore they are often referred to as gated integrators. Controlling the boxcar window with individual trigger pulses has the advantage that both periodic and also non-periodic input signal pulses can be processed. However, the trigger re-arm time - caused by the finite time required to erase the integrator - can be several milliseconds long and constitutes a significant limitation for fast pulse sequences. Additionally, the boxcar window of an analog boxcar averager is not perfectly rectangular due to the rising time of the gate, and the reliance on a trigger signal causes jitter. In the digital UHF-BOX Boxcar Averager, the input signal is digitized using an analog-to-digital converter; the subsequent multiplication with the boxcar function and averaging operation are performed in the digital domain. This process makes it possible to achieve an almost perfect rectangular boxcar window without dead time. In this case, the rise time only depends on the input bandwidth and sampling frequency, and it enables operation at very high repetition rates without signal loss. A simplified block diagram of the UHF-BOX Boxcar Averager is shown in Figure 5 (a). The signal is phase-locked to an internal oscillator so that the boxcar window is defined in terms of the phase. The phase-synchronous data processing of a periodic signal is insensitive to trigger jitter and drift, and is patented by Zurich Instruments [3]. The boxcar averager results can be routed internally to other tools, for example to the lock-in amplifier unit if the duty cycle of the signal is subject to an additional modulation, or to the internal PID controllers for creating feedback loops. Thanks to the digital calculation of the moving average, intermediate results of the boxcar averager output can be obtained and used to implement fast feedback loops.

Table 1 provides a summary of the comparison between analog boxcar averagers and the digital UHF-BOX Boxcar Averager.

### Hardware requirements

A boxcar averager captures information from the fundamental frequency and many harmonics. Measuring higher harmonics requires an input bandwidth of the instrument that is at least several multiples of the fundamental frequency, and an even higher sampling rate.

### Periodic waveform analyzer

Choosing the width and the position of the boxcar window can be challenging if the signal is buried in noise. The UHF-BOX Boxcar Averager facilitates this process by providing a periodic waveform analyzer (PWA) tool displaying a single period of the input signal. If the SNR is low, the input signal can be averaged over many periods. In Figure 5 (b), the boxcar window is defined with respect to the phase of the reference oscillator. If the pulse cannot be resolved when measuring the full period, the PWA makes it possible to increase the resolution by zooming in and displaying only a fraction of the full period: this is done by referencing the signal input to a higher harmonic of the reference oscillator. With the PWA users can also calculate the Fast Fourier Transform of the input signal and thereby display and analyze the weighting of the harmonics with respect to the fundamental frequency.

### Baseline suppression and arithmetic operations

In the UHF-BOX Boxcar Averager, inaccuracies due to DC components and variable offsets can be removed thanks to a reference window in the time interval between pulses. This so-called baseline suppression also enables the rejection of disturbing input signals that are phase-shifted with respect to the signal of interest at the fundamental frequency, such as electronic reflections in the cables. The position of the reference window can be chosen using the PWA, as shown in Figure 5 (b).

The concept of a reference window is ideal for experiments where the information of interest is only present in every other pulse, as is the case in pump-probe spectroscopy with pump-induced transmission change. By setting two filter windows in the time domain, individual signal components can be successfully isolated.

The UHF-BOX Boxcar Averager offers two independent boxcar units, each with baseline suppression, and a built-in Arithmetic Unit. The Arithmetic Unit can provide real-time results based on a combination of two parallel boxcar measurements with arbitrary scaling factors, for example to capture dI/I on a shot-to-shot basis by normalizing the result with a second boxcar measurement.

## Waveform Recovery

For certain applications, it is not only the integrated signal that holds an interest: the shape of the pulse is equally relevant. There exist several tools to recover the waveform of a periodic signal:

- An oscilloscope or digitizer card together with an averaging operation.
- A periodic waveform analyzer.
- A boxcar averager combined with a sweep of the position of the boxcar window with a width much smaller than the pulse width.

If the SNR of the input signal is relatively high and a reliable trigger source is available, an oscilloscope or a digitizer card is generally the tool of choice. The digitized input signal can be averaged over several periods using a trigger signal; alternatively, all raw data can be saved for post-processing. The performance of the measurement depends on the instrument's specifications including sampling rate, voltage resolution, and memory depth. For signals with a low SNR, however, averaging over many periods is necessary and can turn trigger jitter and trigger drift into limiting factors.

For a periodic input signal with a low SNR, the waveform can be reconstructed with a boxcar averager. The UHF-BOX Boxcar Averager offers a variable gain input range amplifier to ensure high sensitivity and low input noise, and it is insensitive to trigger jitter and drifts given that the signal is locked to an internal oscillator. The PWA tool of the UHF-BOX Boxcar Averager, which was introduced above, is the method of choice when speed is more important than time resolution, for instance as a way to choose the boxcar window. However, the time resolution is fixed at 1024 points per period and can become a limitation for measuring wide pulses.

Alternatively, the waveform can be measured by sweeping a short boxcar window across the pulse. For this purpose, the boxcar window width is chosen to be much smaller than the width of the pulse as shown in Figure 5 (c). With this approach, it is possible to increase the SNR of the measurement by rejecting noise components outside of the boxcar window. With the UHF-BOX Boxcar Averager, a boxcar window sweep is easily performed using the built-in Sweeper tool; the ability to measure the integral and the shape of the waveform with the same instrument guarantees a simplified setup. The disadvantage of this strategy is that it is relatively slow and sensitive to signal intensity drifts as large parts of the data from every period are discarded.

Table 2 summarizes the properties of different tools for waveform recovery with a relative qualitative assessment of their performance.

Scope or Digitizer | Boxcar Window Sweep | Periodic Waveform Analyzer | |
---|---|---|---|

Measurement SNR |
low | high | medium |

Measurement time resolution |
high | medium | medium |

Measurement amplitude resolution |
medium | high | high |

Measurement speed |
fast | slow | fast |

Insensitivity to trigger jitter/drift |
no | yes | yes |

## Boxcar Averager vs Lock-in Amplifier

Lock-in amplifiers and boxcar averagers use different methods to measure a periodic signal. A boxcar averager captures information from the fundamental frequency of the signal and many harmonics, whereas a lock-in amplifier performs a selective measurement at a single frequency. The latter is achieved by multiplying the input signal with a reference signal that is typically sinusoidal, followed by adjustable low-pass filtering. The spectral response, measurement speed and temporal response depend on the bandwidth and the order of the low-pass filter as described in the lock-in detection white paper.

When establishing which measurement approach is better suited to a given experiment, some important considerations are:

- What is the waveform of the input signal? Is it a sine wave, a square wave, a train of periodic pulses, or a more complex waveform?
- What is the duty cycle of the input signal?
- How low is the SNR of the input signal? What are the properties of the noise?
- What are the requirements in terms of acquisition speed and settling time?

For a purely sinusoidal input signal, lock-in detection is generally the method of choice because the experiment can be set up quickly and easily. A boxcar measurement with the same measurement bandwidth can give a slightly higher SNR with an optimized boxcar window and baseline suppression. Optimizing a boxcar measurement requires the control of more parameters compared to setting up a lock-in measurement, however, and boxcar averagers are typically more expensive due to the need for a larger signal input bandwidth to capture higher harmonics.

The higher effort of setting up a boxcar measurement becomes valuable for a square wave or a pulsed signal. The lower the duty cycle of the input signal, the more information is contained in the harmonics. A boxcar averager allows experimenters to capture this information by decreasing the boxcar window width, thereby putting more relative weight on higher harmonics. Capturing the information from higher harmonics also leads to additional noise contributions though. Overall, the true advantage of boxcar averaging over lock-in detection depends on the properties of the noise background.

Figure 6 (a) shows the typical noise floor of an experiment, consisting of white noise and 1/f noise. The spectral response of a 1st-order low-pass filter for a lock-in amplifier is indicated around the fundamental frequency f_{rep}. In this example, the noise at the fundamental frequency f_{rep} is dominated by 1/f noise. A lock-in amplifier thus captures a significant amount of noise, leading to a small SNR for this measurement. Figure 6 (b) presents the spectral response of a boxcar averager with a duty cycle of d = 0.05 and N = 20 averaging periods with the same noise background: by capturing the information from the harmonics where less noise is present, boxcar averaging results in a significantly higher SNR in this scenario.

Additionally, being able to define a reference window in the time domain offers a very powerful way to avoid systematic measurement errors due to noise sources phase-shifted with respect to the signal of interest, while making it possible to isolate individual signal components as is required when measuring pump-induced effects, for instance.

Finally, the filter function is a critical aspect for measurement speed. Let's consider a signal with f_{rep} = 10 MHz. Reaching 99.9% settling with a 5th-order low-pass filter and a filter bandwidth of f_{3dB} = 34 kHz takes approximately 26 us (see the lock-in detection white paper for the calculation). By contrast, a boxcar averager with a bandwidth of 34 kHz (N = 128 averaging periods) reaches 100% settling after NT_{rep} = 12.8 us. In the case of video-rate microscopy, for example, it is therefore easier to avoid cross-talk between pixels with a boxcar averager.

In summary, lock-in measurements are easy to set up and less demanding in terms of input bandwidth and sampling rate. Boxcar averaging requires faster electronics and the optimization of several parameters, but this added complexity becomes valuable for low-duty-cycle pulsed signals where it enables to push the limits in terms of SNR and measurement speed. The best way to settle on a measurement strategy is a one-to-one comparison between a lock-in amplifier and a boxcar averager. Alternatively, users can consider implementing both methods simultaneously: this is possible on the Zurich Instruments UHFLI Lock-in Amplifier with the UHF-BOX Boxcar Averager option.