TactivergeLite

Lite / Intelligent Robotic Systems / Week 22

Choosing a sample rate for a real robot

Sampling at 10 kHz is safe but drains the battery. Sampling at 20 Hz is cheap but might lie. How do you pick?

About 40 min · 3 goals · Checked by automated tests · Full interactive version

Why should I care?

In a real robot, every sensor competes for processor time, bus bandwidth and battery. Good engineers sample each signal just fast enough, with the right filter in front, and can explain the choice to the rest of the team.

Predict

A balance controller must react to tilts that change at up to 5 Hz, but the IMU also picks up motor vibration at 180 Hz. Which plan is safest?

  1. Sample at 20 Hz: that's above 2 × 5 Hz
  2. Low-pass filter below 180 Hz, then sample at a few hundred hertz
  3. Sample at 10 Hz exactly
Guess first, then reveal

20 Hz is fast enough for the tilt but the 180 Hz vibration would alias to |180 − 180| = 0 Hz: a fake steady tilt. Filter out the vibration first, then sample with a margin.

Discover

In the Code Lab, generate one second of a 3 Hz 'tilt' plus a 47 Hz 'vibration'. Sample it at 50 Hz and at 500 Hz and print the dominant frequency you see in each. Then apply a 9-sample moving average to the 500 Hz data before keeping every 10th sample. What happened to the vibration?

What the interactive shows (text version)

Code Lab task, described: a 3 Hz tilt plus a 47 Hz vibration sampled at 50 Hz shows a false 3 Hz component from the vibration (|47 − 50| = 3 Hz) on top of the real tilt, so the two are confused. At 500 Hz both frequencies are seen correctly. Averaging 9 samples at 500 Hz before keeping every 10th sample strongly reduces the 47 Hz vibration, leaving the 3 Hz tilt.

You can also open the interactive on the full site when you have a faster connection.

Understand

Start from the frequencies

List what the signal contains: the frequencies you want (the tilt, the heartbeat, the wall getting closer) and the ones you don't (motor vibration, mains hum at 50 or 60 Hz, switching noise). The sample rate must exceed twice the highest frequency that reaches the sampler, wanted or not.

Filter, then sample

An analogue low-pass filter in front of the converter cuts unwanted high frequencies so they can't alias. A common digital pattern is oversample, filter, decimate: sample fast, low-pass filter digitally, then keep every Mth sample. The filter must run on the fast samples, before you throw any away.

Count the cost

Data rate = channels × sample rate × bytes per sample. Six 16-bit channels at 1 kHz is 12 kB/s, about 43 MB an hour. Processing cost scales the same way. Control loops also need the delay between sample and action to be small compared with the system's response time.

Explain it another way

Intuitive

Before photographing a race with a slow camera, close the curtains on the flashing lights behind it: remove what you can't sample properly, then sample what's left.

Technical

Choose fₛ > 2·f_c, where f_c is the frequency above which the anti-alias filter has attenuated signals below the noise floor. Decimation by M requires first low-pass filtering to below fₛ/(2M).

Mathematical

A k-point moving average has zeros in its frequency response at multiples of fₛ/k, so it strongly attenuates those frequencies. With fₛ = 500 Hz and k = 10 its first zero is at 50 Hz.

Applied

Many flight controllers sample gyros at several kilohertz and filter digitally before running the control loop more slowly, precisely so propeller vibration cannot alias into the attitude estimate.

Worked example 1

Mains hum at 50 Hz leaks into a sensor sampled at 52 Hz. What appears?

|50 − 52| = 2 Hz: a slow, convincing 2 Hz wobble. Either filter the hum out before sampling, sample far faster (e.g. 1 kHz) and filter digitally, or choose fₛ so the hum is easy to spot and remove.

Common mix-ups

Practice

Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.

Practice 1. A heart-rate sensor's useful content is below 8 Hz, and an anti-alias filter removes everything above 15 Hz. Which sample rate is the sensible minimum?

Hz

B/s

Hz

Practice 5. You sample at 1 kHz and want to keep only every 10th sample. When must you low-pass filter?

Apply it

Write a one-paragraph sampling plan for a line-following robot with a light sensor array (line edges pass at up to 40 Hz at full speed) and a motor current sensor (PWM ripple at 20 kHz). Give each a sample rate, a filter, and the data rate.

Reflect

Which costs more if you get it wrong: sampling too slowly or too fast? Give an example of each.

Write your answer on paper or in your own notes. Lite never stores what you write.

← Aliasing: when samples tell liesThe moving average and the noise–lag trade-off →