Sampling: taking snapshots
لم يُترجم بعد؛ يُعرض باللغة الإنجليزية
عن هذا الدرس
A computer cannot store a smooth wave, because it has a value at every instant. So it takes snapshots. Follow a 1000 Hz tone as a clock ticks 10,000 times a second, a sample-and-hold freezes the voltage at each tick, and a converter writes the number to memory: x[n] = x(n·Ts). Then see what changes when the clock runs faster or too slowly, and take the same snapshots in Python with numpy. The lesson "What a signal is" introduces x(t) and x[n]; this one shows how the snapshots are taken.
A smooth wave never stops
A signal source puts a smooth 1000 Hz wave on a wire: x(t) = sin(2π·1000·t) volts. It has a value at every instant, so even one millisecond holds infinitely many values. No computer can store them all.
x(t) = A·sin(2π·f0·t)
A = 1 V
f0 = 1000 Hz (1000 cycles a second)
one cycle = 1/1000 s = 1 ms
between t = 0 and t = 1 ms there are
infinitely many instants, each with a value
plot: x(t) in volts against t in ms
motion in the figure: slowed down a lotاقرأ الدرس خطوة بخطوة
A smooth wave never stops
A signal source puts a smooth 1000 Hz wave on a wire: x(t) = sin(2π·1000·t) volts. It has a value at every instant, so even one millisecond holds infinitely many values. No computer can store them all.
x(t) = A·sin(2π·f0·t) A = 1 V f0 = 1000 Hz (1000 cycles a second) one cycle = 1/1000 s = 1 ms between t = 0 and t = 1 ms there are infinitely many instants, each with a value plot: x(t) in volts against t in ms motion in the figure: slowed down a lotA clock ticks every 0.1 ms
So we only look now and then. A clock ticks fs = 10,000 times a second: the sampling rate. The time between ticks is the sampling period, Ts = 1/fs = 0.1 ms. Each tick closes a switch for a moment.
sampling rate fs = 10000 per second = 10 kHz sampling period Ts = 1 / fs = 1 / 10000 s = 0.1 ms = 100 µs ticks at t = 0, 0.1, 0.2, 0.3 ... ms (evenly spaced: periodic sampling)Sample and hold: the snapshot
At each tick the switch joins the wire to a small capacitor, which charges to the voltage at that instant. Then the switch opens and the capacitor holds that voltage steady. This is a sample and hold: a snapshot.
tick switch closes: capacitor follows x(t) after switch opens: capacitor keeps the value held value stays flat until the next tick (the steps in the plot) t = 0.0 ms holds 0.000 V t = 0.1 ms holds 0.588 V t = 0.2 ms holds 0.951 V why hold? the converter needs a steady voltage while it measuresThe converter writes a number
While the value is held, the converter (ADC) measures it and writes the number to memory. Snapshot n is taken at t = n·Ts, so x[n] = x(n·Ts). For example x[2] = x(0.2 ms) = 0.951 V.
x[n] = x(n·Ts), Ts = 0.1 ms x[0] = x(0.0 ms) = 0.000 V x[1] = x(0.1 ms) = 0.588 V x[2] = x(0.2 ms) = 0.951 V x[3] = x(0.3 ms) = 0.951 V x[4] = x(0.4 ms) = 0.588 V (the numbers are shown to 3 decimals; rounding them to a fixed set of levels is the lesson on quantization)Now the wave is a list
The smooth wave has become a list of numbers: 0, 0.588, 0.951, 0.951, 0.588 ... volts. The whole number n counts the ticks. This list x[n] is the discrete-time signal, and it is what the computer keeps.
continuous time x(t) a value at every t discrete time x[n] a value per tick n = 0, 1, 2, ... 20 (whole numbers only) in 2 ms: 21 snapshots (t = 0 to 2.0 ms) written with square brackets: x[n] see also: "What a signal is"Snapshots per cycle
How many snapshots are enough? The wave repeats 1000 times a second and the clock ticks 10,000 times, so each cycle gets fs/f0 = 10 snapshots. Phone calls are sampled 8000 times a second; CDs, 44,100.
snapshots per cycle = fs / f0 = 10000 / 1000 = 10 real sampling rates telephone (G.711) 8 000 per second audio CD 44 100 per second the rate is chosen for the fastest wiggle the signal may containNothing between the ticks
Between two ticks the sampler does not look. Halfway between x[0] and x[1] the wave is at x(0.05 ms) = 0.309 V, but that value is not in the list. Sampling keeps only the instants t = n·Ts.
x(0.05 ms) = sin(2π × 1000 × 0.00005) = sin(18°) = 0.309 V the list has x[0] = 0 and x[1] = 0.588 and nothing in between can the in-between values be rebuilt? only if the clock is fast enough: that is the Nyquist rate lessonFaster: closer, but more data
Tick four times faster, fs = 40,000 a second, and each cycle gets 40 snapshots. The dots follow the wave closely, but there are four times as many numbers to store and send. More detail costs more data.
fs = 40000 per second Ts = 1 / fs = 0.025 ms = 25 µs per cycle: 40000 / 1000 = 40 in 2 ms: 81 snapshots (was 21) numbers per second = fs faster clock -> more memory, more bandwidthToo slow: a different wave
Tick too slowly, fs = 1500 a second, and each cycle gets only 1.5 snapshots. The dots now sit exactly on a slower 500 Hz wave. From the list alone, you cannot tell which wave made them.
fs = 1500 per second, Ts = 0.667 ms per cycle: 1500 / 1000 = 1.5 snapshots: 0, −0.866, 0.866, 0 V sin(2π·1000·n/1500) = −sin(2π·500·n/1500) for every whole n: the 1000 Hz wave and an upside-down 500 Hz wave give the same list this is aliasing; how fast is fast enough is the next lesson, The Nyquist rateSnapshots in Python
In Python with numpy, np.arange(21) numbers the ticks 0 to 20, n/fs turns each into a time in seconds, and np.sin takes every snapshot in one line. The first five match the memory.
import numpy as np fs = 10000 n = np.arange(21) x = np.sin(2*np.pi*1000*n/fs) >>> x.round(3)[:5] array([0. , 0.588, 0.951, 0.951, 0.588]) >>> len(x) 21 n/fs is the tick time in seconds np.sin takes radians (Python 3 with numpy)
أسئلة سريعة: 5
اختر إجابة واحدة لكل سؤال. يمكنك تغيير اختياراتك قبل التحقق منها.
01A clock samples a signal 20,000 times a second. What is the sampling period Ts?
Ts = 1/fs = 1 / 20 000 s = 0.00005 s = 0.05 ms (50 µs).
02With fs = 10,000 per second, which instant does the sample x[7] come from?
x[n] = x(n·Ts) with Ts = 0.1 ms, so x[7] is the value at 7 × 0.1 ms = 0.7 ms.
03Why does a sample and hold sit in front of the converter (ADC)?
The converter takes a little time to measure. The switch and capacitor freeze the voltage at the tick, so the input does not change during the measurement.
04A 2 kHz tone is sampled 16,000 times a second. How many snapshots does each cycle get?
Snapshots per cycle = fs / f0 = 16 000 / 2000 = 8.
05A 1000 Hz wave is sampled only 1500 times a second. What goes wrong?
With 1.5 snapshots per cycle, sin(2π·1000·n/1500) equals −sin(2π·500·n/1500) for every whole n. This is aliasing; the Nyquist rate lesson says how fast is fast enough.
المسرد
- Sampling
- Measuring a continuous-time signal at separate instants, usually evenly spaced, to get a list of numbers.
- Sample (snapshot)
- One measured value, x[n] = x(n·Ts). Here x[2] = 0.951 V.
- Sampling period Ts
- The time between two samples.
- Sampling rate fs
- Samples per second, fs = 1/Ts, in hertz (Hz).
- Sample and hold
- A switch and a capacitor that catch the voltage at a tick and keep it steady while a converter measures it.
- ADC (analog-to-digital converter)
- A circuit that measures a voltage and outputs it as a number.
- Discrete-time signal x[n]
- A signal defined only at whole-number indexes n, such as the list of samples.
- Aliasing
- When samples taken too slowly fit a different, slower wave just as well as the real one.
الملاحظات والمصادر
- The 1000 Hz tone at 1 V and the 10,000 per second clock are chosen examples; 8000 per second is the telephone rate (ITU-T G.711) and 44,100 per second the audio CD rate. Every number and curve in the figure is computed from this model.
- The motion is slowed down a great deal: the real clock ticks every 0.1 ms, and the real switch closes for a far shorter time than drawn.
- A real sample and hold also has a buffer amplifier, and the held voltage slowly leaks away; how the converter turns the held voltage into bits is the lesson Inside an ADC.
- A. V. Oppenheim, A. S. Willsky, S. H. Nawab, Signals and Systems, 2nd ed., Pearson (ch. 7: Sampling)
- A. V. Oppenheim, R. W. Schafer, J. R. Buck, Discrete-Time Signal Processing, 2nd ed. (course text listed on MIT OCW 6.341 readings)
- B. P. Lathi, R. A. Green, Linear Systems and Signals, Oxford University Press, 2018 (Internet Archive record)
- MIT OpenCourseWare 6.003 Signals and Systems (D. Freeman, Fall 2011): includes sampling
- MIT OpenCourseWare 6.341 Discrete-Time Signal Processing (A. V. Oppenheim, Fall 2005)
- Sampling (signal processing) (Wikipedia): sampling period T, fs = 1/T; 8000 Hz telephony, 44,100 Hz audio CD
- Sample and hold (Wikipedia): a switch and a capacitor keep the input steady while an ADC converts
- G.711 (Wikipedia): telephone audio sampled 8000 times a second
- Compact Disc Digital Audio (Wikipedia): 44,100 samples a second, 16 bits
- NumPy documentation: numpy.arange
- NumPy documentation: numpy.sin (angles in radians)
اختبار يتاح بعد الخطوة الأخيرة.