Data acquisition & sampling: practice problems with step-by-step solutions

Free Data acquisition & sampling practice problems with diagrams, hints and full worked solutions. New values every time, at three levels: Nyquist, LSB and data rates, aliasing, bits and UART frames, harmonics, SQNR and system design.

Free practice problemEasy
SD0​D1​D2​D3​D4​D5​D6​D7​Tb​ = ?115200 Bd

A UART link runs at 115200 baud. Find the duration Tb of one bit, in µs.

baud = 115200 Bd
µs
Next problem →

What you practise

  1. EasyNyquist, LSB and data rates
  2. Mediumaliasing, bits and UART frames
  3. Hardharmonics, SQNR and system design

How to solve Data acquisition & sampling problems

  1. Write down what is given: sampling rate, signal frequencies, number of bits, input range, baud rate.
  2. For sampling questions, compare each frequency with fs/2; a higher frequency appears at fa = |f − k·fs| with the nearest multiple of fs.
  3. For resolution questions, find 1 LSB = VFSR/2ᴺ, or the smallest N with 2ᴺ ≥ span/resolution.
  4. For data rates and UART links, count everything that is sent: channels, samples per second, bits or whole bytes per sample, and the start, parity and stop bits of every frame.

Common mistakes

  • Thinking a frequency above fs/2 disappears: it shows up as an alias inside the band.
  • Dividing the range by N instead of by 2ᴺ.
  • Rounding the number of bits down instead of up.
  • Forgetting the start and stop bits: 8N1 sends 10 bits for every byte.

Key formulas

Nyquist criterion
fs > 2·fmax, fN = fs/2
Alias frequency
fa = |f − k·fs|, k = round(f/fs)
Step size
1 LSB = VFSR/2ᴺ
Quantisation error (rounding)
±½ LSB
Truncating ADC code
D = ⌊Vin/LSB⌋
Bits for a resolution r
2ᴺ ≥ span/r
Ideal SQNR, full-scale sine
SQNR = 6.02·N + 1.76 dB
Data rate
channels × fs × N bit/s
Multiplexed ADC
fs = 1/(n·(tc + tset))
UART
Tb = 1/baud; 8N1 = 10 bits per byte; bytes/s = baud/bits per frame
Baud rate divider
baud = fclk/(16·D)

Learn Data acquisition & sampling from scratch

Before this: Number systems

1What data acquisition is

A computer cannot read a voltage directly. A data acquisition system turns a physical quantity into numbers: a sensor makes a small voltage, an amplifier scales it, and an analogue-to-digital converter (ADC) measures it at regular moments and outputs a binary number.

TG∿01N, fs​0101

Two choices decide how good the numbers are. The sampling rate fs says how often the ADC measures, and the number of bits N says how finely it divides its voltage range. Together they also decide how much data you have to store or send.

Self-check An ADC samples at 2 kHz. How many samples does it take in 0.5 s?
  1. 1000
  2. 2000
  3. 250
  4. 4000

Answer: 1000. Samples = fs·t = 2000·0.5 = 1000. Multiplying by 2 instead of 0.5 gives 4000, and ignoring the time gives 2000.

2Sampling and aliasing

To capture a sine wave you need more than two samples per period. So the sampling rate must be more than twice the highest frequency in the signal. Half the sampling rate is the Nyquist frequency:

fs > 2·fmax fN = fs/2

A frequency above fs/2 does not vanish. Its samples look exactly like those of a lower frequency, the alias. In the figure a 7 Hz sine (solid) is sampled at 10 Hz, and the dots fit a 3 Hz sine (dashed) just as well.

tf = 7 Hzfs​ = 10 Hz
fa = |f − k·fs|, k = the whole number nearest to f/fs

After sampling nothing can separate the alias from a real signal. That is why an analogue anti-aliasing filter removes everything above fs/2 before the ADC.

Self-check A 7 kHz tone is sampled at 10 kHz without a filter. At which frequency does it appear?
  1. 17 kHz
  2. 3 kHz
  3. 5 kHz
  4. 7 kHz

Answer: 3 kHz. 7 kHz is above fs/2 = 5 kHz, so it folds back: |7 − 1·10| = 3 kHz. It cannot stay at 7 kHz, 17 kHz adds instead of subtracting, and 5 kHz is only the folding frequency.

3Resolution and quantisation

An N-bit ADC has 2ᴺ output codes, from 0 to 2ᴺ − 1. It divides its full-scale range VFSR into 2ᴺ equal steps. One step is called 1 LSB (least significant bit):

1 LSB = VFSR/2ᴺ

A truncating ADC outputs the code ⌊Vin/LSB⌋, the whole number below. A rounding ADC is never more than ½ LSB away from the true value: that is its quantisation error.

To resolve steps of size r over a span, you need the smallest N with 2ᴺ ≥ span/r. Every extra bit halves the LSB and adds about 6 dB to the ideal signal-to-quantisation-noise ratio:

SQNR = 6.02·N + 1.76 dB
Self-check A 10-bit ADC has a range of 0 to 5.12 V. What is 1 LSB?
  1. 10 mV
  2. 2.5 mV
  3. 5 mV
  4. 512 mV

Answer: 5 mV. 210 = 1024, so 1 LSB = 5.12/1024 = 0.005 V = 5 mV. Dividing by N = 10 gives 512 mV, using 2⁹ gives 10 mV, and 2.5 mV is the largest error of a rounding ADC, half an LSB.

4Data rates and serial links

Each channel delivers fs samples per second of N bits. The raw data rate is channels × fs × N. In memory a sample takes whole bytes, so a 12-bit sample uses 2 bytes.

A UART sends every byte as a frame: a start bit, 8 data bits, an optional parity bit and one or two stop bits. In the common 8N1 format that is 10 bits per byte. The baud rate counts bits per second, so one bit lasts 1/baud.

bytes per second = baud/(bits per frame)

A multiplexer lets one ADC serve several channels in turn. If one conversion (with settling) takes t, each of n channels is sampled at 1/(n·t).

5A worked example

Use this order for most questions:

  1. Check the sampling rate against the highest signal frequency.
  2. Find the step size from the range and the number of bits.
  3. Count the data: channels, samples per second, bytes per sample.
  4. Compare with what the link or the memory can take, counting start, parity and stop bits.
Worked example

A logger measures 4 temperature channels with a 12-bit ADC over 0 to 4.096 V. The signals contain frequencies up to 20 Hz, and each channel is sampled at 100 Hz. Every sample is sent as 2 bytes over a UART at 9600 baud, 8N1. Is the sampling rate high enough, what is 1 LSB, and can the link keep up?

1

Nyquist check

2·fmax = 2·20 = 40 Hz < 100 Hz

The sampling rate is high enough.

2

Step size

1 LSB = 4.096/212 = 4.096/4096 = 0.001 V = 1 mV
3

Data to send

4 channels · 100 samples/s · 2 bytes = 800 bytes/s
4

Capacity of the link

8N1 sends 10 bits per byte.

9600/10 = 960 bytes/s ≥ 800 bytes/s
5

Check the answer

On the line that is 800·10 = 8000 bit/s, below 9600 baud. The link is 83 % busy.

Answer

Yes: 100 Hz is more than twice 20 Hz, 1 LSB = 1 mV, and the link needs 800 of its 960 bytes/s.

6Common mistakes

  • Thinking a frequency above fs/2 is simply lost: it appears as an alias inside the band.
  • Dividing the range by N instead of 2ᴺ.
  • Rounding the number of bits down: 2ᴺ must be at least span/resolution.
  • Counting 8 bits per byte on a UART: 8N1 needs 10.
  • Forgetting that a 10-bit or 12-bit sample is stored in 2 whole bytes.
Self-check How many bytes per second can a 9600-baud UART send in the 8N1 format?
  1. 1067
  2. 1200
  3. 9600
  4. 960

Answer: 960. Each byte needs 10 bits (start, 8 data, stop): 9600/10 = 960. Dividing by 8 forgets the start and stop bits, and dividing by 9 forgets one of them.

7How exam questions look

  • Easy: Nyquist, LSB and data rates. You find the minimum sampling rate, the Nyquist frequency, the LSB size or quantisation error, the bit time of a UART or the raw data rate.
  • Medium: aliasing, bits and UART frames. You find an alias frequency, the number of bits for a resolution, the output code for a voltage, the memory for a recording, the byte rate of a UART format or the ideal SQNR.
  • Hard: harmonics, SQNR and system design. You find where a harmonic aliases, the bits for a required SQNR, the highest frequency a UART-streamed ADC can capture, the rate of a multiplexed ADC, the baud rate error of a divider or the temperature resolution of a sensor chain.

Learn it step by step in the appLearn it step by step in the app

Worked examples

Example 1Easy
SD0​D1​D2​D3​D4​D5​D6​D7​Tb​ = ?2400 Bd

A UART link runs at 2400 baud. Find the duration Tb of one bit, in µs.

baud = 2400 Bd

Find Tb (µs)

Show hints
  1. The baud rate is the number of bits sent per second.
  2. Tb = 1/baud.
  3. 1 s = 10⁶ µs.
Show the answer and the step-by-step solution

UART: an asynchronous serial link sends each byte as a frame: one start bit (low), the data bits, an optional parity bit and one or two stop bits (high). The baud rate is the number of bits per second, so one bit lasts Tb = 1/baud and a frame of n bits lasts n/baud. The common 8N1 format has 10 bits per byte. The baud generator divides the clock: baud = fclk/(16·D) with a whole number D, so the real baud rate differs slightly from the target; an error below about 2 % is usually acceptable.

Bit time

Tb = 1/2400 s = 416.7 µs

Answer

Tb = 416.7 µs
Example 2Medium
Vin​N = 85 V2ᴺ − 101 LSB2.125 V?

An 8-bit ADC with an input range of 0 to 5 V truncates: its output code is ⌊Vin/LSB⌋ with 1 LSB = VFSR/2ᴺ. Find the decimal output code D for an input of 2.125 V.

N = 8VFSR = 5 VVin = 2.125 V

Find D

Show hints
  1. First find the size of one LSB.
  2. 1 LSB = 5/256 = 19.53 mV.
  3. Divide the input by the LSB and keep the whole part.
Show the answer and the step-by-step solution

ADC resolution: an N-bit converter divides its full-scale range VFSR into 2ᴺ codes, from 0 to 2ᴺ − 1. One step is 1 LSB = VFSR/2ᴺ: the smallest change the converter can show. A truncating ADC gives the code ⌊Vin/LSB⌋; a rounding ADC is never more than ½ LSB away from the true value, its quantisation error. Every extra bit halves the LSB and adds about 6 dB to the ideal signal-to-quantisation-noise ratio SQNR = 6.02·N + 1.76 dB for a full-scale sine. To reach a resolution r over a span, choose the smallest N with 2ᴺ ≥ span/r.

Step size

1 LSB = 5/28 = 19.53 mV

Code

Vin/LSB = 2125/19.53 = 108.8
code = ⌊108.8⌋ = 108

Answer

D = 108

In binary that is 01101100.

Example 3Hard
f0fs​/2fs​1.92 kHz7f₁?

A 1.92 kHz square wave is sampled at 8 kHz with no anti-aliasing filter. A square wave contains the odd harmonics 3f₁, 5f₁, 7f₁, … At which frequency fa does its harmonic 7f₁ appear in the sampled data? Give it in Hz.

f₁ = 1.92 kHzfs = 8 kHzharmonic: 7f₁

Find fa (Hz)

Show hints
  1. The harmonic is at 7·1.92 kHz = 13.44 kHz, above fs/2 = 4 kHz.
  2. It appears at fa = |f − k·fs| with the nearest multiple of fs.
  3. 13440/8000 = 1.68.
Show the answer and the step-by-step solution

Sampling: an ADC measures the signal fs times per second. By the Nyquist–Shannon theorem a frequency f is captured correctly only while f < fs/2, the Nyquist (folding) frequency, so the sampling rate must exceed twice the highest signal frequency. A higher frequency is not lost: it shows up as an alias at fa = |f − k·fs|, with the whole number k that brings the result between 0 and fs/2. The samples cannot tell the two apart, so an analogue anti-aliasing filter must remove everything above fs/2 before the ADC.

Harmonic frequency

7f₁ = 7·1.92 kHz = 13.44 kHz

Nearest multiple of the sampling rate

m = round(1.68) = 2

Alias frequency

fa = |13440 − 2·8000| = 2560 Hz

Answer

fa = 2560 Hz

The alias lands inside the signal band, where no digital filter can remove it. Only an analogue filter before the ADC helps.

Questions and answers

What is Data acquisition & sampling?

A computer cannot read a voltage directly. A data acquisition system turns a physical quantity into numbers: a sensor makes a small voltage, an amplifier scales it, and an analogue-to-digital converter (ADC) measures it at regular moments and outputs a binary number.

Two choices decide how good the numbers are. The sampling rate fs says how often the ADC measures, and the number of bits N says how finely it divides its voltage range. Together they also decide how much data you have to store or send.

How do I solve Data acquisition & sampling problems step by step?
  1. Write down what is given: sampling rate, signal frequencies, number of bits, input range, baud rate.
  2. For sampling questions, compare each frequency with fs/2; a higher frequency appears at fa = |f − k·fs| with the nearest multiple of fs.
  3. For resolution questions, find 1 LSB = VFSR/2ᴺ, or the smallest N with 2ᴺ ≥ span/resolution.
  4. For data rates and UART links, count everything that is sent: channels, samples per second, bits or whole bytes per sample, and the start, parity and stop bits of every frame.
What are common mistakes in Data acquisition & sampling?
  • Thinking a frequency above fs/2 disappears: it shows up as an alias inside the band.
  • Dividing the range by N instead of by 2ᴺ.
  • Rounding the number of bits down instead of up.
  • Forgetting the start and stop bits: 8N1 sends 10 bits for every byte.
What do the Data acquisition & sampling exercises cover?
  • Easy: Nyquist, LSB and data rates
  • Medium: aliasing, bits and UART frames
  • Hard: harmonics, SQNR and system design

Every problem has new values, so you learn the method instead of an answer. Stuck? Open a small hint first, and the full explanation only when you need it.

How practising works

  • Every problem has new values, so you learn the method instead of an answer.
  • Stuck? Open a small hint first, and the full explanation only when you need it.
  • Your progress, mistakes and saved problems are kept, so you can review before the exam.

Topics before and after this one

Learn first

Courses with this topic

More topics in Electrical

Printable worksheet