DACs and reconstruction
لم يُترجم بعد؛ يُعرض باللغة الإنجليزية
عن هذا الدرس
A DAC (digital-to-analog converter) turns stored numbers back into a voltage. Follow one period of a 1000 Hz tone stored as 8 codes at 8000 samples a second: the DAC adds up the bit weights of each code, holds the voltage until the next one and so draws a staircase. The staircase's sharp corners add copies of the tone, called images, at 8 ± 1 kHz and higher. A low-pass reconstruction filter removes them and a smooth wave comes out. You will see why, compare it with the ideal sinc-pulse reconstruction, and check the images in Python with numpy. It follows "Inside an ADC" and uses the Circuits lesson on filters.
A sound stored as numbers
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.
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"
اقرأ الدرس خطوة بخطوة
A sound stored as numbers
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.
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"Each bit has a weight
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.
bit weights 128 64 32 16 8 4 2 1 code 199 = 1 1 0 0 0 1 1 1 128 + 64 + 4 + 2 + 1 = 199 voltage = 199 × 10 mV = 1.99 V step (LSB) = 10 mV, 2⁸ = 256 codes full scale = 256 × 10 mV = 2.56 V (a binary-weighted DAC; real chips often use an R-2R resistor ladder for the weights)Hold each value: a staircase
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.
zero-order hold (ZOH): z(t) = v[n] for n·Ts ≤ t < (n+1)·Ts t (µs) code z (V) 0 .. 125 128 1.28 125 .. 250 199 1.99 250 .. 375 228 2.28 375 .. 500 199 1.99 ... flat between samples, a jump at each one motion in the figure: slowed down a lotSharp corners, a little late
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.
each stair starts at its sample and lasts Ts, so its middle is Ts/2 later: delay = 125 µs / 2 = 62.5 µs a sudden jump cannot be made from slow waves alone: it needs fast (high-frequency) ones added in dashed: the smooth wave through the samplesThe steps add images
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.
tones in the staircase (amplitude, V) 0 kHz 1.28 (the middle level) 1 kHz 0.976 the tone we want 7 kHz 0.139 = 0.976 / 7 9 kHz 0.108 = 0.976 / 9 15 kHz 0.065 17 kHz 0.057 images sit at k·fs ± f0 the hold scales tone f by sinc(f/fs): 1 kHz × 0.974 (−0.22 dB, a slight droop) zero at 8 kHz and 16 kHzA low-pass filter
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.
4th-order Butterworth low-pass cutoff fc = 3500 Hz |H(f)| = 1 / √(1 + (f/fc)⁸) 1 kHz 1.0000 7 kHz 0.0624 (1/16) 9 kHz 0.0229 fc sits between the tone (1 kHz) and the first image (7 kHz) filters in depth: see Circuits, "Filters"Out comes a smooth wave
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.
after the filter (amplitude, V) 1 kHz 0.976 × 1.0000 = 0.976 7 kHz 0.139 × 0.0624 = 0.0087 9 kHz 0.108 × 0.0229 = 0.0025 delay at 1 kHz hold 62.5 µs filter 123 µs (its group delay) the y(t) curve is computed from the staircase's tones through |H| and its phaseThe ideal: one sinc pulse per sample
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.
sinc(u) = sin(πu) / (πu): 1 at u = 0, 0 at every other whole number s(t) = Σ v[n]·sinc((t − n·Ts) / Ts) at t = n·Ts only pulse n is not zero, so s passes through every sample exact when every tone is below fs/2 (the Nyquist rate lesson) real filters only come close, which is why fc sits well below 4 kHzCheck it in Python
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.
import numpy as np n = np.arange(8) codes = np.round(128 + 100*np.sin(2*np.pi*n/8)) v = codes * 0.01 held = np.repeat(v, 16) X = np.fft.rfft(held) / 64 abs(X[[1, 7, 9]]).round(2) >>> codes.astype(int) array([128, 199, 228, 199, 128, 57, 28, 57]) >>> abs(X[[1, 7, 9]]).round(2) array([0.98, 0.14, 0.11]) 128 points span 1 ms, so bin k = k kHz (Python 3 with numpy)Numbers back to sound
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.
memory codes, one every 125 µs DAC code × 10 mV, held for Ts -> staircase + images at k·fs ± f0 filter low-pass, keeps below fc -> smooth wave speaker turns voltage into sound sampling (ADC) and reconstruction (DAC) are the two halves of digital audio
أسئلة سريعة: 5
اختر إجابة واحدة لكل سؤال. يمكنك تغيير اختياراتك قبل التحقق منها.
01An 8-bit DAC has a step of 10 mV. Which voltage does it output for the code 10100000?
The 1-bits have weights 128 and 32, so the code is 160. 160 × 10 mV = 1.60 V.
02A DAC with a zero-order hold runs at fs = 8000 samples per second. What does its output look like?
A zero-order hold keeps each voltage until the next code arrives, Ts = 1/8000 s = 125 µs later, so the output is flat between samples and jumps at each one.
03A 2 kHz tone is played by a DAC at fs = 8000 per second with a zero-order hold. Where is the first image?
Images sit at k·fs ± f0. The lowest is fs − f0 = 8 − 2 = 6 kHz; the next is 8 + 2 = 10 kHz.
04What does the reconstruction filter after a DAC do?
It is a low-pass filter. Its cutoff sits above the wanted tones and below the first image, so the images shrink and a smooth wave remains.
05In ideal reconstruction, why does the sum of sinc pulses pass exactly through every sample?
sinc(u) is 1 at u = 0 and 0 at every other whole number. At t = n·Ts only pulse n is non-zero, so the sum equals sample n there.
المسرد
- DAC (digital-to-analog converter)
- A circuit that turns a number (a code) into a voltage or current, here code × 10 mV.
- Bit weight
- The value a bit adds when it is 1: 128, 64, 32 ... 1 for an 8-bit code. The code is the sum of the weights of its 1-bits.
- LSB (step)
- The voltage one code step stands for, here 10 mV; the output for code c is c × LSB.
- Zero-order hold
- Keeping each output value flat until the next sample arrives, which turns a list of numbers into a staircase.
- Image
- A copy of a wanted tone at k·fs ± f0 (here 7, 9, 15, 17 kHz ...) created by the steps of the staircase.
- Reconstruction filter
- A low-pass filter after a DAC that keeps the wanted tones and removes the images, smoothing the output.
- Spectrum
- A picture of which tones (frequencies) a signal holds and how big each one is.
- sinc pulse
- sinc(u) = sin(πu)/(πu): 1 at u = 0 and 0 at every other whole number. Ideal reconstruction places one, scaled by the sample, at every sample time.
الملاحظات والمصادر
- 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.
- A. V. Oppenheim, A. S. Willsky, S. H. Nawab, Signals and Systems, 2nd ed., Pearson (ch. 7: sampling, zero-order hold, reconstruction by interpolation)
- A. V. Oppenheim, R. W. Schafer, J. R. Buck, Discrete-Time Signal Processing (ch. 4: the D/C converter and reconstruction; course text listed on MIT OCW 6.341 readings)
- MIT OpenCourseWare 6.003 Signals and Systems (D. Freeman, Fall 2011)
- MIT OpenCourseWare RES.6-007 Signals and Systems (A. V. Oppenheim): sampling for analog and digital systems
- Zero-order hold (Wikipedia): frequency response e^(−jπfT)·sinc(fT)
- Digital-to-analog converter (Wikipedia): staircase output, binary-weighted and R-2R DACs, reconstruction filter
- Whittaker-Shannon interpolation formula (Wikipedia): x(t) = Σ x[n]·sinc((t − nT)/T)
- Butterworth filter (Wikipedia): gain 1/√(1 + (ω/ωc)^2n)
- NumPy documentation: numpy.repeat
- NumPy documentation: numpy.fft.rfft
- NumPy documentation: numpy.sinc (sin(πx)/(πx))
اختبار يتاح بعد الخطوة الأخيرة.