Codes to voltages
Memory holds a 1 kHz tone as numbers: 8 samples per wave, one every 125 µs (fs = 8000 per second). A DAC, a digital-to-analog converter, turns numbers like these back into a voltage.
The DAC gives every bit a weight: 128, 64, 32 down to 1. It adds the weights of the 1-bits and multiplies by one step, 10 mV. Code 199 = 11000111 = 128 + 64 + 4 + 2 + 1, so 1.99 V.
The DAC holds each voltage until the next code arrives, 125 µs later. This is called a zero-order hold. Code after code, the output becomes a staircase z(t) that follows the wave.
Why the steps matter
Compare the staircase with the smooth wave through the samples. The stairs have sharp corners, and on average they run half a step, 62.5 µs, late. Sharp corners mean extra, higher tones are mixed in.
A spectrum shows which tones a signal holds. The staircase holds the 1 kHz tone plus copies called images, at 8 ± 1 kHz, 16 ± 1 kHz and on: 7, 9, 15, 17 kHz. The 7 kHz image is 1/7 as big.
Smoothing it out
A reconstruction filter is a low-pass filter: it passes tones below its cutoff, 3.5 kHz here, and blocks tones above. The 1 kHz tone gets through; the 7 kHz image shrinks 16 times.
After the filter the 7 kHz image is 0.0087 V, 0.89% of the tone. The staircase has become a smooth 1 kHz wave, and the speaker plays it. It comes out slightly late: the filter takes time too.
A perfect low-pass filter, passing all below fs/2 = 4 kHz and nothing above, would rebuild the wave exactly. Each sample becomes a sinc pulse; the pulses add up to a smooth wave through every sample.
Check and recap
numpy can find the images. np.repeat holds each voltage for 16 points: a zero-order hold. np.fft.rfft measures the tones: 0.98 V at 1 kHz, 0.14 V at 7 kHz and 0.11 V at 9 kHz.
The whole path: codes leave memory, the DAC turns each into a voltage and holds it, and the low-pass filter removes the images. Numbers become a smooth wave again, ready for a speaker.
The working
# step 1/10 · codes fs = 8000 samples per second Ts = 1 / fs = 125 µs one period of a 1000 Hz tone = 8 samples code[n] = round(128 + 100·sin(2π·n/8)) n 0 1 2 3 4 5 6 7 code 128 199 228 199 128 57 28 57 8-bit codes: 0 .. 255, middle = 128 how the codes were made: see "Inside an ADC"
The DAC is an example: 8 bits, steps of 10 mV, fed with 8 codes per period of a 1000 Hz tone at fs = 8000 per second. The filter is an example 4th-order Butterworth low-pass with cutoff 3500 Hz. Every value and curve in the figure is computed from this model. The motion is slowed down a great deal: the real DAC takes a new code every 125 µs. The filter output y(t) is the steady state (the tone has been playing for a while); it is the sum of the staircase's tones, each scaled and delayed by the filter.