TExcelTAD
Home › Signals, Systems & Digital Filters for Engineers › Reconstruction and DACs: Zero-Order Hold and Sinc Droop

Reconstruction and DACs: Zero-Order Hold and Sinc Droop

A waveform generator built on a microcontroller plays a 1 kHz1\ \text{kHz} sine from a table at 8 kSa/s8\ \text{kSa/s}. On the scope it looks like a staircase, the FFT shows extra tones at 77 and 9 kHz9\ \text{kHz} only about 1717 to 19 dB19\ \text{dB} below the wanted one, and a 3 kHz3\ \text{kHz} tone comes out quieter than the 1 kHz1\ \text{kHz} one although both tables have the same amplitude. None of this is a bug: it is what a real digital-to-analog converter does. The ideal reconstruction of Reconstruction uses sinc interpolation, which no circuit can build. Real converters hold each sample for one period (a zero-order hold) and rely on an analog reconstruction filter afterwards. This lesson quantifies both effects and shows how to correct them.

The zero-order hold

0 1 2 1 -1 t/T0 dashed: input sine, amber: DAC staircase (10 samples/period), green: sine delayed by Ts/2

A DAC that holds each value x[n]x[n] for TsT_s produces xZOH(t)=∑nx[n] rect⁡ ⁣(t−nTs−Ts/2Ts)x_\text{ZOH}(t) = \sum_n x[n]\,\operatorname{rect}\!\left(\frac{t - nT_s - T_s/2}{T_s}\right): the ideal impulse train convolved with a pulse of width TsT_s. The pulse's transform is the frequency response of the hold:

HZOH(f)=e−jπf/fs sin⁡(πf/fs)πf/fs=e−jπf/fssinc⁡(f/fs)H_\text{ZOH}(f) = e^{-j\pi f/f_s}\,\frac{\sin(\pi f/f_s)}{\pi f/f_s} = e^{-j\pi f/f_s}\operatorname{sinc}(f/f_s)

Three consequences:

  1. Sinc droop. Inside the band the output amplitude falls as sinc⁡(f/fs)\operatorname{sinc}(f/f_s): −0.14 dB-0.14\ \text{dB} at 0.1fs0.1 f_s, −0.91 dB-0.91\ \text{dB} at 0.25fs0.25 f_s, −3.92 dB-3.92\ \text{dB} at the Nyquist frequency fs/2f_s/2.
  2. Images. The sampled spectrum has copies at kfs±fk f_s \pm f. The hold weights them by sinc⁡\operatorname{sinc}, so they shrink but do not vanish; the nulls fall exactly at multiples of fsf_s.
  3. Delay. The linear phase −πf/fs-\pi f/f_s is a pure delay of Ts/2T_s/2, the average lag of the staircase (the green curve). In a control loop it costs phase margin (Real-Time DSP).

The reconstruction filter after the DAC is the anti-alias filter's mirror image: pass 0…fp0 \ldots f_p, attenuate the first image at fs−fpf_s - f_p. The same order calculations apply (Anti-Alias Filters).

Worked example: an audio DAC at 48 kSa/s

Given: a DAC at fs=48 kSa/sf_s = 48\ \text{kSa/s} with zero-order hold, playing a full-scale tone at f=20 kHzf = 20\ \text{kHz}.

Find: the droop at 20 kHz20\ \text{kHz}, and the level of the first image relative to the tone.

Solve: f/fs=0.4167f/f_s = 0.4167, sinc⁡(0.4167)=sin⁡(1.309)/1.309=0.9659/1.309=0.738\operatorname{sinc}(0.4167) = \sin(1.309)/1.309 = 0.9659/1.309 = 0.738, i.e. −2.64 dB-2.64\ \text{dB}. The first image is at fs−f=28 kHzf_s - f = 28\ \text{kHz} with weight sinc⁡(28/48)=0.9659/1.833=0.527\operatorname{sinc}(28/48) = 0.9659/1.833 = 0.527, which is 0.527/0.738=0.7140.527/0.738 = 0.714 of the tone: only −2.9 dBc-2.9\ \text{dBc}. The image is almost as loud as the tone; a sharp reconstruction filter between 2020 and 28 kHz28\ \text{kHz} (or digital oversampling before the DAC) is mandatory.

Check: the image and tone have the same numerator ∣sin⁡(πf/fs)∣\lvert \sin(\pi f/f_s) \rvert, so the ratio is simply f/(fs−f)=20/28=0.714f/(f_s - f) = 20/28 = 0.714.

python · try it yourself
import numpy as np
from scipy import signal

sincdb = lambda r: 20 * np.log10(np.sinc(r))      # np.sinc(x) = sin(pi x)/(pi x)
for r in (0.1, 0.25, 20 / 48, 0.5):
    print(f"f/fs = {r:.4f}: ZOH gain {sincdb(r):6.2f} dB")
fs, f = 48e3, 20e3
print(f"image at {(fs - f) / 1e3:.0f} kHz relative to the tone: {sincdb((fs - f) / fs) - sincdb(f / fs):.2f} dBc")

# Inverse-sinc pre-compensation: a short linear-phase FIR that boosts the top of the band
numtaps = 15
freq = np.linspace(0, 1, 51)                     # fraction of Nyquist
gain = 1 / np.sinc(freq / 2)                     # 1/sinc(f/fs) over the whole band (freq/2 = f/fs)
h = signal.firwin2(numtaps, freq, gain)
w, H = signal.freqz(h, worN=2048, fs=1.0)
band = w <= 0.40
total = 20 * np.log10(np.abs(H[band]) * np.sinc(w[band]))
print(f"{numtaps}-tap compensator: overall response 0..0.40 fs within {total.min():+.2f} .. {total.max():+.2f} dB "
      f"(ZOH alone: {sincdb(0.40):+.2f} dB at 0.40 fs)")
f/fs = 0.1000: ZOH gain  -0.14 dB
f/fs = 0.2500: ZOH gain  -0.91 dB
f/fs = 0.4167: ZOH gain  -2.64 dB
f/fs = 0.5000: ZOH gain  -3.92 dB
image at 28 kHz relative to the tone: -2.92 dBc
15-tap compensator: overall response 0..0.40 fs within +0.03 .. +0.07 dB (ZOH alone: -2.42 dB at 0.40 fs)

The 15-tap filter holds the overall response within a tenth of a decibel where the hold alone loses 2.42 dB2.42\ \text{dB}. The compensator is applied to the samples before the DAC. The firwin2 design here is quick and approximate; the remez design of Equiripple FIR does the same job with controlled ripple. Many audio and RF DAC chips have such a filter built in.

Seeing the images

To look at the analog output in simulation, model it on a grid 32 times finer than the DAC clock: repeat each sample 32 times (the hold), then take an FFT.

python · try it yourself
import numpy as np
import matplotlib.pyplot as plt

fs, f0, up = 8000, 1000, 32                      # DAC rate, tone, fine-grid factor
n = np.arange(800)                               # 0.1 s at 8 kSa/s
x = np.sin(2 * np.pi * f0 * n / fs)
y = np.repeat(x, up)                             # zero-order hold on the fine grid (256 kSa/s)
Y = np.abs(np.fft.rfft(y)) / len(y) * 2
fr = np.fft.rfftfreq(len(y), 1 / (fs * up))
ref = Y[np.argmin(abs(fr - f0))]
for fk in (1000, 7000, 9000, 15000, 17000):
    k = np.argmin(abs(fr - fk))
    pred = 20 * np.log10(abs(np.sinc(fk / fs) / np.sinc(f0 / fs)))
    print(f"{fk / 1e3:4.0f} kHz: {20 * np.log10(Y[k] / ref):6.2f} dBc (sinc prediction {pred:6.2f} dBc)")

plt.figure(figsize=(7, 2.6))
plt.plot(fr / 1e3, 20 * np.log10(Y / ref + 1e-12))
plt.xlim(0, 40); plt.ylim(-60, 5)
plt.xlabel("f (kHz)"); plt.ylabel("dBc"); plt.title("ZOH output of a 1 kHz tone at 8 kSa/s")
plt.tight_layout(); plt.show()
   1 kHz:   0.00 dBc (sinc prediction   0.00 dBc)
   7 kHz: -16.89 dBc (sinc prediction -16.90 dBc)
   9 kHz: -19.07 dBc (sinc prediction -19.08 dBc)
  15 kHz: -23.47 dBc (sinc prediction -23.52 dBc)
  17 kHz: -24.55 dBc (sinc prediction -24.61 dBc)

Practical DACs

  • Architectures. Resistor-string and R-2R ladders (monotonic or fast), current-steering (high speed, RF), PWM plus a filter (cheap microcontrollers) and sigma-delta (audio, high resolution with heavy oversampling and a simple analog filter). Details belong to the embedded and chip design track; here the hold and filter model is what matters.
  • Oversampling DACs. Interpolating by 4 or 8 before the converter (Multirate) moves the first image from fs−ff_s - f to Lfs−fL f_s - f and makes the droop in the band tiny, so the analog filter becomes simple.
  • Non-idealities. Glitches at major code transitions (worst at mid-scale in R-2R designs), finite settling time, output impedance, and clock jitter, which modulates the time each step occurs and adds noise proportional to the signal's slope.
  • PWM as a DAC. The average of a PWM signal is the DAC value; the filter must suppress the PWM frequency itself, so the PWM rate is chosen far above the signal band.

Guided lab: a microcontroller DAC

Hand calculation. A 1 kHz1\ \text{kHz} table played at 8 kSa/s8\ \text{kSa/s} gives images at 7 kHz7\ \text{kHz} (sinc⁡(7/8)/sinc⁡(1/8)=0.143\operatorname{sinc}(7/8)/\operatorname{sinc}(1/8) = 0.143, −16.9 dBc-16.9\ \text{dBc}) and 9 kHz9\ \text{kHz} (−19.1 dBc-19.1\ \text{dBc}). The droop at 1 kHz1\ \text{kHz} is −0.22 dB-0.22\ \text{dB}; at 3 kHz3\ \text{kHz} it is −2.11 dB-2.11\ \text{dB} (since sinc⁡(3/8)=0.784\operatorname{sinc}(3/8) = 0.784).

Simulation. The second program prints the image levels; change f0 to 30003000 and see the droop and the images at 55 and 11 kHz11\ \text{kHz}.

What you would measure. On a scope's FFT (Hann window, a few hundred hertz of resolution, Scope triggering and FFT): images within about ±1 dB\pm 1\ \text{dB} of the predictions if the DAC settles quickly; extra harmonics from DAC non-linearity typically 4040 to 60 dB60\ \text{dB} down. Add an RC low-pass (1.6 kΩ1.6\ \text{k}\Omega, 47 nF47\ \text{nF}, fc≈2.1 kHzf_c \approx 2.1\ \text{kHz}) and the 7 kHz7\ \text{kHz} image drops by about another 10.8 dB10.8\ \text{dB} (1/1+(7/2.12)21/\sqrt{1 + (7/2.12)^2}) while the 1 kHz1\ \text{kHz} tone loses 0.9 dB0.9\ \text{dB}, so the image improves by about 9.9 dB9.9\ \text{dB} relative to the tone.

Hazards and safe setup. USB-powered board, the DAC output into a scope probe (10 MΩ10\ \text{M}\Omega) or a high-impedance load only; do not drive a loudspeaker directly from a DAC pin.

Pitfalls

  • Forgetting the sinc droop when a flat response to 0.45fs0.45 f_s is required.
  • Assuming images are "small": near fs/2f_s/2 they are almost as large as the tone.
  • Forgetting the Ts/2T_s/2 delay of the hold in a feedback loop.
  • Blaming the DAC for harmonics that are really images (they move when fsf_s changes; harmonics don't).

Practice

  1. What is the ZOH droop at f=0.3fsf = 0.3 f_s?
  2. A 5 kHz5\ \text{kHz} tone is played at 44.1 kSa/s44.1\ \text{kSa/s}. Where is the first image, and what is its level in dBc?
  3. Why does 4 times oversampling before the DAC relax the reconstruction filter?
Answer
  1. sinc⁡(0.3)=sin⁡(0.942)/0.942=0.858\operatorname{sinc}(0.3) = \sin(0.942)/0.942 = 0.858: −1.33 dB-1.33\ \text{dB}.
  2. At 44.1−5=39.1 kHz44.1 - 5 = 39.1\ \text{kHz}; ratio 5/39.1=0.1285/39.1 = 0.128: −17.9 dBc-17.9\ \text{dBc}.
  3. The first image moves from fs−ff_s - f to 4fs−f4f_s - f, far above the band, so a low-order analog filter attenuates it enough, and the in-band droop is only sinc⁡(f/4fs)\operatorname{sinc}(f/4f_s).

Test yourself

The zero-order hold's gain at the Nyquist frequency is

  1. 0 dB
  2. -0.91 dB
  3. -3.92 dB
  4. −∞-\infty dB

The images of a ZOH DAC have nulls at

  1. multiples of fs/2f_s/2
  2. multiples of fsf_s
  3. the tone frequency
  4. there are no nulls

The average delay of a zero-order hold is

  1. 0
  2. Ts/2T_s/2
  3. TsT_s
  4. 2Ts2T_s

An inverse-sinc compensator is placed

  1. before the DAC, on the samples
  2. after the reconstruction filter
  3. in the anti-alias filter of the ADC
  4. nowhere; it cannot be built