Skip to content
You Start with one site
Amounts in Start with one site
Control, Measurement & Energy · Course

Signal Conditioning, Noise and Sampling

Lesson 8 of 10 29 min read
Found this useful?

A pump controller shows a pressure that moves in a slow wave, a few times each second, although a gauge on the same pipe is steady. The controller follows the wave, the pump speed hunts, and somebody spends a week on the tuning of a loop that was never wrong. In the end the wave is found to be electrical noise from the drive, changed by the sampling into something that looks like pressure. A second person then averages the signal so heavily that the loop becomes slow. This lesson shows where noise enters a signal on a plant, how to stop it before the converter, and how to choose a filter, a sample rate and an average from numbers, not by trial. #SignalConditioning #Noise #Sampling

Learning Objectives

By the end of this lesson, you will be able to:

  1. Identify the routes by which noise enters a signal cable, and the wiring practice that closes each route
  2. Calculate the corner frequency, the attenuation and the lag of a first-order RC filter
  3. Predict the frequency at which an unfiltered signal appears after sampling
  4. Choose a filter corner and a sample rate from how fast the measurand can change
  5. Find the number of samples to average for a required noise level, and the delay that the average adds

Real-World System Problem: A pressure signal beside a variable speed drive



A booster pump is driven by a variable speed drive. A pressure transmitter on the discharge line, range 0 to 10 bar, sends 4 to 20 mA to the controller, where the current passes through a 150 Ω sense resistor and a 12-bit analogue to digital converter (ADC) reads the voltage. The signal cable shares a cable tray with the motor cable for several metres.

The drive builds its output from pulses that switch several thousand times each second, with very fast edges. The motor cable carries those edges, and it also carries mains current at 50 Hz. A part of both reaches the signal. An oscilloscope on the sense resistor shows the steady voltage of the pressure with two unwanted waves on it: one at 50 Hz and one near 4 kHz.

RCADC150 ΩsenseTransmitter0 to 10 bar4to20mANcablefiltersamplernoise from the motor cable:50 Hz mains and 4 kHz switching
The signal chain and where noise enters

The pressure itself cannot change quickly: the pump, the pipe and the pressure vessel respond with a time constant of about 3 s. Everything fast in the signal is therefore noise, and that makes the problem solvable, because the wanted and the unwanted parts are at different frequencies. The order of the work matters. Keep the noise out of the cable first, remove what remains with a filter before the converter, and only then sample and average.

Fundamental Theory: Noise, filtering and sampling



Where noise comes from on a plant

Noise is any part of the signal that does not come from the measurand. On a plant it enters by three routes.

  • Electric coupling. Two conductors near each other form a small capacitor. A fast change of voltage on the power conductor pushes a current through that capacitance into the signal conductor. The fast edges of a drive are the main source.
  • Magnetic coupling. A current in a power cable creates a magnetic field. The two wires of a signal circuit enclose an area, and a changing field through that area induces a voltage in the loop. Mains current at 50 Hz and its harmonics enter this way, and the effect grows with the length of the parallel run.
  • Common impedance, or ground loop. When a signal circuit is earthed at two places, the two earth points are rarely at the same voltage. The difference drives a current through the signal return or the shield, and the voltage that this current creates adds to the signal.

A long cable makes all three worse: more capacitance to its neighbours, more loop area, and more distance between earth points.

Twisted pair, shield and separation

Each route has its own remedy, and one remedy does not replace another.

one polarityuntwisted pair: one large loop, the field addstwisted pair: many small loops, each one oppositeto the next, so the induced voltages cancel+−+−+−
Why a twisted pair cancels magnetic pickup

Twisting the two wires of a pair acts against magnetic coupling. Each half twist turns the loop over, so the voltage induced in one small loop is opposite to that in the next, and the sum is close to zero.

A shield (a foil or a braid round the pair) acts against electric coupling: the noise current flows into the shield and to earth, not into the wires inside. It does little against a magnetic field at 50 Hz. For an analogue signal the shield is normally earthed at one end only, at the cabinet, so that it cannot become part of a ground loop. The motor cable of a drive follows different rules, which the drive’s maker states.

Separation acts against both kinds of coupling: signal cables in their own tray, away from motor cables, crossing them at a right angle where they must cross.

Differential measurement

A single-ended input measures the voltage of one wire against the ground of the converter. Any voltage between that ground and the far end of the cable is measured as signal. A differential input has two terminals and measures only the difference between them. Noise that appears equally on both wires (common-mode noise) is not in the difference, so it is rejected.

The rejection is never complete. It is stated as the common-mode rejection ratio of the input, and it becomes worse as the frequency rises. A differential input is therefore strong against 50 Hz and weaker against the fast edges of a drive. It also has a limit on the common-mode voltage it can accept, which must be checked on the datasheet.

The first-order RC low-pass filter

A resistor in series with the signal and a capacitor from the signal to ground form the simplest filter. A slow signal passes, because the capacitor has time to follow it. A fast signal is reduced, because the capacitor cannot charge and discharge through the resistor quickly enough.

First-order RC low-pass filter

is the resistance in ohms and the capacitance in farads. is the time constant in seconds and is the corner frequency in hertz. is the gain: the amplitude of a sine wave of frequency after the filter, divided by its amplitude before it. is the phase shift, a lag.

At the corner frequency the gain is and the lag is 45 degrees. Far above the corner the gain is close to : ten times the frequency gives one tenth of the amplitude. This slope is gentle. A first-order filter separates two frequencies well only when they are far apart.

In decibels the gain is , so a gain of 0.1 is −20 dB and a gain of 0.001 is −60 dB.

Sampling and aliasing

An ADC does not see the signal continuously. It takes a sample at fixed intervals. Let be the sample rate in samples per second. A sine wave is described correctly by its samples only if its frequency is below , which is called the Nyquist frequency.

A sine wave above is not lost. Its samples fit a slower sine wave exactly, and the converter reports that slower wave. This false wave is called an alias.

Alias frequency

is the true frequency, is the sample rate, and is the whole number that brings the result into the range from 0 to . is the frequency at which the signal appears in the samples.

A worked example shows the size of the problem. A 50 Hz pickup is sampled 60 times each second. The Nyquist frequency is 30 Hz, so 50 Hz is above it. With :

The samples show a wave at 10 Hz with the full amplitude of the pickup. Between one sample and the next the pickup completes five sixths of a cycle, so each sample finds it one sixth of a cycle earlier than the last, and six samples (one tenth of a second) trace one false cycle. A wheel in a film does the same: photographed at each five sixths of a turn, it seems to turn slowly backwards.

01020304050 Hzthe aliashalf thethe trueappears atsample ratepickup10 Hz(30 Hz)at50Hz
A 50 Hz pickup sampled 60 times per second

The alias can fall anywhere, even on zero. Switching noise at 4000 Hz sampled at 200 samples per second gives Hz: a constant offset that looks like a calibration error. If the drive switches at 4003 Hz, the alias is at 3 Hz and looks like a pressure wave.

Why a digital filter cannot undo aliasing

After sampling, the alias at 10 Hz and a real pressure wave at 10 Hz give the same numbers. No calculation can tell them apart, because what separated them (the true frequency) was lost at the moment of sampling. A digital filter can remove everything at 10 Hz, wanted and unwanted together, but not only the false part.

So the filter must be analogue, before the converter: an anti-alias filter. Its task is to make every frequency above small enough, before sampling, that its alias does not matter. A digital filter after the converter has a different task: reducing noise that was sampled correctly.

Choosing the sample interval

The rule that the sample rate must be more than twice the highest frequency is a lower limit, not a design value. Two samples in each cycle prove only that a wave exists. To follow a change, plan for about ten samples within the shortest time in which the measurand can change usefully. For a process with a time constant, that is at least ten samples in each time constant, and more where a control loop uses the samples.

Start from the physics of the measurand, not from what the converter can do. The level in a large tank needs one sample each minute, a room temperature one each ten seconds or slower, and a pump pressure in a control loop ten or more each second. A faster rate than the measurand needs is still useful in one way: it moves the Nyquist frequency up, away from the wanted signal, so that a gentle analogue filter is enough, and the extra samples can be averaged afterwards.

Averaging: what it gives and what it costs

The mean of samples is less noisy than one sample, as shown for repeated readings in uncertainty budgets.

Averaging independent noise

is the standard deviation of the noise on one sample, that of the mean of samples, and is the sample interval. is the mean delay of a moving average: the average age of the samples inside it.

The gain is slow and the cost is direct. Halving the noise needs four times the samples, and the delay grows almost in proportion to . A moving average of samples needs seconds to show the whole of a sudden change.

The rule holds for independent noise only. It fails in three cases.

  • Correlated noise. If neighbouring samples carry nearly the same noise (because the noise is slow, or because an analogue filter has already smoothed it), averaging them gains much less. Sampling faster than the noise changes does not create new information.
  • Quantisation with too little noise. If the noise is much smaller than one count, every sample returns the same count. The mean of a thousand equal numbers is the same number, and the rounding error stays.
  • Bias. An offset, a wrong range or an alias at zero frequency is the same in every sample. Averaging does not touch it.

Quantisation

An ADC rounds the voltage to a whole number of counts. The rounding error lies evenly between minus half a count and plus half a count, so its standard uncertainty is , where is the size of one count. For the converter of this lesson, one count is , which is 0.0034 bar.

Quantisation behaves like independent noise only when the signal moves over several counts between samples. Then averaging does improve on one count, and a small amount of real noise is useful. This is the one case where a perfectly quiet signal measures worse than a slightly noisy one.

Application 1: An RC anti-alias filter and a sample rate



150Ωloop currentR=3.3kΩADC inputsenseC=10µFresistorADC ground
The RC filter between the sense resistor and the ADC

Step 1: The size of the noise in bar and in counts

Click to reveal the noise in engineering units
  1. Scale of the signal. The span of 16 mA across 150 Ω is for 10 bar.

    ✅

  2. Mains pickup.

    ✅

  3. Switching noise.

    Both are larger than the maker’s limit of the transmitter, ±0.05 bar. Without a filter the noise, and not the transmitter, decides the quality of the reading. ✅

Step 2: The corner frequency and the parts

Click to reveal the choice of corner, resistor and capacitor
  1. Where the corner can be. It must be above 2 Hz, so that the pressure passes, and below 50 Hz, so that the pickup is reduced. A first-order filter is gentle, so the corner cannot be far from both at once. A corner near 5 Hz is ten times below 50 Hz and more than two times above 2 Hz. ✅

  2. Time constant for 5 Hz.

    ✅

  3. Resistance. With the total resistance is . The capacitor is charged through the filter resistor and the sense resistor in series, so the filter resistor should be . The nearest E12 value is 3.3 kΩ. ✅

  4. The corner as built.

    ✅

Step 3: Attenuation and lag

Click to reveal the gain at each frequency
  1. At 50 Hz.

    The pickup of 20 mV becomes 1.84 mV: 2.3 counts, or 0.0077 bar. ✅

  2. At 4 kHz.

    The switching noise of 50 mV becomes 0.058 mV: 0.07 count. It is now below the resolution of the converter, so its alias cannot be seen wherever it falls. ✅

  3. At 2 Hz, the fastest useful change of pressure.

    A pressure wave at 2 Hz loses 8 percent of its amplitude. Slower changes lose less. ✅

  4. Lag where the controller works. At 0.5 rad/s:

    The time constant of the filter is 1.2 percent of the loop’s 3 s. The control loop will not notice the filter. ✅

Step 4: The filter against the ADC input

The filter resistor is now the source resistance that the ADC sees: 3450 Ω with the sense resistor. Many microcontroller converters ask for a source resistance below about 10 kΩ, for two reasons that can be checked.

Click to reveal the two checks
  1. Charge for each sample. At each conversion the ADC connects its 15 pF sampling capacitor to the input. The 10 µF filter capacitor supplies that charge at once, and its voltage falls by the ratio of the two capacitances:

    One count is 244 parts per million of the reference. The effect is far below one count, and the large capacitor at the pin is the reason. ✅

  2. Leakage current. A steady leakage current flows through the source resistance and creates an offset.

    This is the worst case. At the typical 0.1 µA the offset is 0.4 count. ✅

  3. Judgement. The worst-case offset, 0.014 bar, is less than one third of the transmitter’s limit of 0.05 bar, and it is a bias, not noise. It is acceptable here. If it were not, the choices are a smaller resistor with a larger capacitor, or a buffer amplifier between the filter and the ADC. ✅

Step 5: The sample rate

Click to reveal the sample rate and the check
  1. What the measurand needs. The pressure changes no faster than 2 Hz, so ten results each second give at least five results in the fastest cycle and thirty in each time constant of the loop. Ten results per second is enough for the controller. ✅

  2. What the remaining noise needs. After the filter, the 50 Hz pickup is still 2.3 counts. If the converter sampled only 10 times per second, that remainder would alias, and for a mains frequency slightly away from 50 Hz it would appear as a slow drift. So sample faster than twice 50 Hz and remove the remainder digitally, which is possible because it has then been sampled correctly. ✅

  3. The choice. Sample at 200 samples per second (Nyquist frequency 100 Hz), and report the mean of each block of 20 samples.

    A mean over a whole number of cycles of a sine wave is zero, so the block mean removes the 50 Hz remainder. One result leaves each 0.1 s: 10 results per second. ✅

  4. Lag of the block mean. Its mean delay is , which is 1.36 degrees at 0.5 rad/s. With the RC filter the total is 2.35 degrees. ✅

  5. Check by simulation. The Python script builds a slowly changing pressure near 4 bar with both noise signals on it and passes it through the chain. Sampled with no filter, the error of the indication is 0.159 bar (root mean square). With the RC filter it is 0.0057 bar. With the RC filter and the block mean it is 0.0012 bar, less than one count of 0.0034 bar. ✅

Check it with the drive running. With the pump at a steady duty, log 30 s of the ten results per second and compare them with a gauge on the same pipe. The slow wave must be gone, and the results should scatter by no more than about one count, 0.003 bar, beyond the real movement of the pressure. Then stop the drive for a moment. If the spread falls a lot, noise from the drive is still getting through: look at the cable route and the shield first, then at the filter parts.

Application 2: How many samples to average, and the delay



Step 1: The number of samples

Click to reveal the number of samples
  1. Required reduction. The noise must fall from 0.03 bar to 0.01 bar: a factor of 3. ✅

  2. Number of samples.

    A factor of 3 in noise costs a factor of 9 in samples. ✅

Step 2: The delay

Click to reveal the delay and the lag
  1. Length of the window. Nine values at 0.1 s each cover . After a sudden change of pressure the display needs 0.9 s to show all of it. ✅

  2. Mean delay.

    For slow changes the averaged value is the pressure of 0.4 s ago. ✅

  3. Lag at 0.5 rad/s.

    This is five times the lag of the whole of Application 1. ✅

Step 3: Check, and where the rule fails

Click to reveal the check and the three failures
  1. Check by simulation. The script draws 900 000 independent values with a standard deviation of 0.03 bar and averages them in groups of nine. The standard deviation of the means is 0.0100 bar. ✅

  2. Correlated noise. The script repeats the test with noise in which each value has a correlation of 0.8 with the one before it. The mean of nine values then has a standard deviation of 0.0227 bar, not 0.0100 bar. The average gains a factor of 1.3 where the rule promised 3. This is also why the block of 20 samples in Application 1 does not reduce random noise by : those samples are 5 ms apart, behind a filter with a time constant of 34.5 ms, so neighbours are almost equal. ✅

  3. Quantisation with too little noise. The script holds the input at 1.5604 V, which is 1936.79 counts, with a noise of only 0.02 count. Every one of 900 000 samples reads 1937. The mean is wrong by 0.21 count, and no number of samples changes that. ✅

  4. Bias. The transmitter’s own error, and the leakage offset of Application 1, are the same in every sample. Nine samples or nine thousand leave them unchanged. ✅

Verify It in Python



The script repeats both applications: the corner of the filter, the gain at 2 Hz, 50 Hz and 4 kHz, the lag, and the two checks against the ADC input. It calculates the alias frequencies of the worked examples, confirms one from the spectrum of sampled data, and simulates the whole chain at 200 samples per second, with and without the filter. Last, it tests the averaging rule on independent noise, on correlated noise and on a signal with too little noise. It saves two plots: the gain of the filter against frequency, and the indicated pressure for the three versions of the chain.

filter_sampling.py
"""Anti-alias filter, sample rate and averaging for a 4 to 20 mA pressure
signal read across 150 ohm beside a variable speed drive."""
import numpy as np
from scipy import signal
import matplotlib.pyplot as plt
R_SENSE = 150.0 # ohm
R_FILT = 3300.0 # ohm
C_FILT = 10e-6 # F
VREF, COUNTS = 3.3, 4096
V_PER_BAR = 16e-3 * R_SENSE / 10.0 # 0.24 V per bar
COUNT_V = VREF / COUNTS
COUNT_BAR = COUNT_V / V_PER_BAR
# ---------- Part 1: the RC filter ----------
r_source = R_SENSE + R_FILT
tau = r_source * C_FILT
fc = 1.0 / (2.0 * np.pi * tau)
def gain(f, fc=fc):
"""Amplitude ratio of a first-order low-pass filter."""
return 1.0 / np.sqrt(1.0 + (f / fc) ** 2)
print("RC filter: 3.3 kohm and 10 uF after the 150 ohm sense resistor")
print(f" source resistance {r_source:.0f} ohm, time constant {1000 * tau:.1f} ms, "
f"corner {fc:.2f} Hz")
print(f" one count: {1000 * COUNT_V:.3f} mV = {COUNT_BAR:.5f} bar")
for name, f, mv in (("pressure, 2 Hz", 2.0, None), ("mains, 50 Hz", 50.0, 20.0),
("drive, 4 kHz", 4000.0, 50.0)):
g = gain(f)
line = f" {name:<15} gain {g:.5f} ({20 * np.log10(g):6.1f} dB)"
if mv is not None:
out = mv * g
line += (f", {mv:.0f} mV becomes {out:.3f} mV = "
f"{out / 1000 / COUNT_V:.2f} count = {out / 1000 / V_PER_BAR:.4f} bar")
print(line)
w_loop = 0.5
print(f" lag at {w_loop} rad/s: {np.degrees(np.arctan(w_loop * tau)):.2f} degrees, "
f"time constant is {100 * tau / 3.0:.1f} % of the loop's 3 s")
for tol in (-0.2, 0.2):
print(f" capacitor {100 * tol:+.0f} %: corner {fc / (1 + tol):.2f} Hz, "
f"gain at 50 Hz {gain(50.0, fc / (1 + tol)):.4f}")
# Loading of the filter by the ADC input
C_SAMPLE, I_LEAK, FS = 15e-12, 1e-6, 200.0
print("ADC input against the filter")
print(f" charge taken per sample: {1e6 * C_SAMPLE / C_FILT:.1f} parts per million "
f"of the voltage (one count is {1e6 / COUNTS:.0f})")
print(f" mean sampling current at 3 V: {1e9 * C_SAMPLE * 3.0 * FS:.0f} nA, "
f"drop {1e6 * C_SAMPLE * 3.0 * FS * r_source:.0f} uV")
v_leak = I_LEAK * r_source
print(f" leakage 1 uA: {1000 * v_leak:.2f} mV = {v_leak / COUNT_V:.1f} counts = "
f"{v_leak / V_PER_BAR:.4f} bar")
print(f" leakage 0.1 uA: {v_leak / 10 / COUNT_V:.2f} count")
# ---------- Part 2: aliasing ----------
def alias(f, fs):
"""Apparent frequency of a sine of frequency f sampled at fs."""
return abs(f - fs * np.round(f / fs))
print("Aliasing")
for f, fs in ((50.0, 60.0), (50.0, 200.0), (4000.0, 200.0), (4003.0, 200.0),
(150.0, 200.0)):
print(f" {f:6.0f} Hz sampled at {fs:.0f} per second appears at "
f"{alias(f, fs):.0f} Hz")
n = np.arange(600) # 10 s at 60 samples per second
x = np.sin(2 * np.pi * 50.0 * n / 60.0)
spec = np.abs(np.fft.rfft(x))
print(f" spectrum of the 50 Hz sine sampled at 60 per second peaks at "
f"{np.fft.rfftfreq(n.size, 1 / 60.0)[spec.argmax()]:.1f} Hz")
# ---------- Part 3: the whole chain in simulation ----------
F_SIM = 40_000.0
t = np.arange(0.0, 20.0, 1.0 / F_SIM)
p_true = 4.0 + 0.10 * np.sin(2 * np.pi * 0.08 * t) # bar, slow change
v = (0.6 + V_PER_BAR * p_true
+ 0.020 * np.sin(2 * np.pi * 50.0 * t + 0.7)
+ 0.050 * np.sin(2 * np.pi * 4003.0 * t))
b, a = signal.bilinear([1.0], [tau, 1.0], fs=F_SIM)
step = int(F_SIM / FS)
def to_bar(volts):
counts = np.round(volts / COUNT_V)
return (counts * COUNT_V - 0.6) / V_PER_BAR
N_BLOCK = 20
T_BLOCK = N_BLOCK / FS
g50 = abs(np.sin(np.pi * 50.0 * T_BLOCK) / (N_BLOCK * np.sin(np.pi * 50.0 / FS)))
d_block = (N_BLOCK - 1) / 2 / FS
lag_total = np.degrees(np.arctan(w_loop * tau) + w_loop * d_block)
print("Block mean of 20 samples at 200 per second")
print(f" block {T_BLOCK:.1f} s = {50.0 * T_BLOCK:.0f} mains cycles, "
f"gain at 50 Hz {g50:.4f}, {1 / T_BLOCK:.0f} results per second")
print(f" mean delay {1000 * d_block:.1f} ms, lag at 0.5 rad/s "
f"{np.degrees(w_loop * d_block):.2f} degrees, with the RC filter "
f"{lag_total:.2f} degrees")
raw = to_bar(v[::step]) # no filter
filt = to_bar(signal.lfilter(b, a, v)[::step]) # RC filter first
ref = p_true[::step]
skip = int(2 * FS) # let the filter settle
blocks = filt[skip:].reshape(-1, N_BLOCK).mean(axis=1) # 20 samples = 0.1 s
ref_blocks = ref[skip:].reshape(-1, N_BLOCK).mean(axis=1)
print("Simulated chain, 200 samples per second")
print(f" no filter: error {np.std(raw[skip:] - ref[skip:]):.4f} bar rms")
print(f" RC filter: error {np.std(filt[skip:] - ref[skip:]):.4f} bar rms")
print(f" RC and 20-sample block mean: error "
f"{np.std(blocks - ref_blocks):.4f} bar rms")
# ---------- Part 4: averaging ----------
SIGMA, TARGET, T_S = 0.03, 0.01, 0.1
n_avg = int(np.ceil((SIGMA / TARGET) ** 2))
print("Averaging")
print(f" samples needed: ({SIGMA}/{TARGET})^2 = {n_avg}")
print(f" window {n_avg * T_S:.1f} s, mean delay {(n_avg - 1) / 2 * T_S:.1f} s, "
f"lag at 0.5 rad/s {np.degrees(0.5 * (n_avg - 1) / 2 * T_S):.1f} degrees")
rng = np.random.default_rng(3)
M = 900_000
white = rng.normal(0.0, SIGMA, M)
print(f" independent noise: {white.reshape(-1, n_avg).mean(axis=1).std():.4f} bar")
RHO = 0.8 # correlation of neighbouring samples
corr = signal.lfilter([np.sqrt(1 - RHO**2)], [1.0, -RHO], rng.normal(0.0, SIGMA, M))
k = np.arange(1, n_avg)
factor = np.sqrt((1 + 2 * np.sum((1 - k / n_avg) * RHO**k)) / n_avg)
print(f" correlated noise (0.8 between neighbours): "
f"{corr[1000:1000 + 99_000 * n_avg].reshape(-1, n_avg).mean(axis=1).std():.4f} bar, "
f"formula {SIGMA * factor:.4f} bar")
small = np.round((1.5604 + rng.normal(0.0, 0.02 * COUNT_V, M)) / COUNT_V) * COUNT_V
print(f" noise of 0.02 count: every sample reads "
f"{np.unique(small / COUNT_V).astype(int)} counts, "
f"mean wrong by {abs(small.mean() - 1.5604) / COUNT_V:.2f} count")
print(f" quantisation alone: {COUNT_BAR / np.sqrt(12):.5f} bar")
# ---------- Plot ----------
fig, ax = plt.subplots(2, 1, figsize=(8, 7))
f = np.logspace(-1, 4, 400)
ax[0].semilogx(f, 20 * np.log10(gain(f)))
for fx in (2.0, 50.0, 4000.0):
ax[0].axvline(fx, color="gray", linewidth=0.8)
ax[0].set_xlabel("frequency (Hz)")
ax[0].set_ylabel("gain (dB)")
ax[0].set_title("RC filter: lines at 2 Hz, 50 Hz and 4 kHz")
tt = np.arange(raw.size) / FS
ax[1].plot(tt, raw, linewidth=0.5, label="no filter")
ax[1].plot(tt, filt, linewidth=0.8, label="RC filter")
ax[1].plot(tt[skip::N_BLOCK][:blocks.size] + 0.05, blocks, "k", label="RC and block mean")
ax[1].set_xlim(2, 8)
ax[1].set_xlabel("time (s)")
ax[1].set_ylabel("indicated pressure (bar)")
ax[1].legend()
fig.tight_layout()
fig.savefig("filter_sampling.png", dpi=120)
print("Saved filter_sampling.png")

Expected output

RC filter: 3.3 kohm and 10 uF after the 150 ohm sense resistor
source resistance 3450 ohm, time constant 34.5 ms, corner 4.61 Hz
one count: 0.806 mV = 0.00336 bar
pressure, 2 Hz gain 0.91749 ( -0.7 dB)
mains, 50 Hz gain 0.09187 ( -20.7 dB), 20 mV becomes 1.837 mV = 2.28 count = 0.0077 bar
drive, 4 kHz gain 0.00115 ( -58.8 dB), 50 mV becomes 0.058 mV = 0.07 count = 0.0002 bar
lag at 0.5 rad/s: 0.99 degrees, time constant is 1.2 % of the loop's 3 s
capacitor -20 %: corner 5.77 Hz, gain at 50 Hz 0.1146
capacitor +20 %: corner 3.84 Hz, gain at 50 Hz 0.0767
ADC input against the filter
charge taken per sample: 1.5 parts per million of the voltage (one count is 244)
mean sampling current at 3 V: 9 nA, drop 31 uV
leakage 1 uA: 3.45 mV = 4.3 counts = 0.0144 bar
leakage 0.1 uA: 0.43 count
Aliasing
50 Hz sampled at 60 per second appears at 10 Hz
50 Hz sampled at 200 per second appears at 50 Hz
4000 Hz sampled at 200 per second appears at 0 Hz
4003 Hz sampled at 200 per second appears at 3 Hz
150 Hz sampled at 200 per second appears at 50 Hz
spectrum of the 50 Hz sine sampled at 60 per second peaks at 10.0 Hz
Block mean of 20 samples at 200 per second
block 0.1 s = 5 mains cycles, gain at 50 Hz 0.0000, 10 results per second
mean delay 47.5 ms, lag at 0.5 rad/s 1.36 degrees, with the RC filter 2.35 degrees
Simulated chain, 200 samples per second
no filter: error 0.1586 bar rms
RC filter: error 0.0057 bar rms
RC and 20-sample block mean: error 0.0012 bar rms
Averaging
samples needed: (0.03/0.01)^2 = 9
window 0.9 s, mean delay 0.4 s, lag at 0.5 rad/s 11.5 degrees
independent noise: 0.0100 bar
correlated noise (0.8 between neighbours): 0.0227 bar, formula 0.0227 bar
noise of 0.02 count: every sample reads [1937] counts, mean wrong by 0.21 count
quantisation alone: 0.00097 bar
Saved filter_sampling.png

In the lower plot the trace with no filter is a wide band: the 50 Hz pickup, with the switching noise aliased to a wave at 3 Hz on it. The filtered trace is a thin line with a small ripple at 50 Hz, and the block mean follows the true pressure.

Common Mistakes



  • Filtering in software only. A digital filter works on samples, and an alias is already inside the samples. The anti-alias filter is an analogue part before the converter.
  • Sampling at exactly twice the highest frequency. Twice is the limit below which the method fails, not a design value. Plan for about ten samples in the shortest useful change, and more where a filter must be gentle.
  • Placing the corner of a first-order filter at the frequency to be removed. At the corner the gain is still 0.707. Unwanted frequencies must be far above the corner.
  • Expecting ten times less noise from ten times more samples. Independent noise falls with the square root of the number, and correlated noise falls less.
  • Averaging to make a reading “more accurate”. An average reduces the spread. It leaves the bias, the range error and the maker’s limit unchanged.
  • Earthing a signal shield at both ends without a reason. Two earth points at different voltages drive a current through the shield and create the noise that the shield was fitted to stop.

Summary



  • Noise enters a signal by electric coupling, magnetic coupling and ground loops. A shield, a twisted pair, separation and a single earth point each close one route.
  • A first-order RC filter has a corner at and a gentle slope, so the wanted and the unwanted frequencies must be far apart. Here 3.3 kΩ and 10 µF give 4.61 Hz, a gain of 0.092 at 50 Hz and 0.0012 at 4 kHz, and a lag of 1 degree at 0.5 rad/s.
  • A frequency above half the sample rate appears as an alias at a lower frequency: 50 Hz sampled at 60 samples per second appears at 10 Hz. No digital filter can separate an alias from a real signal, so the filter comes before the converter.
  • The sample interval comes from how fast the measurand can change. Sampling faster than that, then averaging, makes the analogue filter easier.
  • Averaging independent samples divides the noise by and adds a mean delay of . Nine samples bring 0.03 bar to 0.01 bar and add 0.4 s at 10 samples per second.
  • The rule fails for correlated noise, for noise much smaller than one count, and for any bias.

Exercises



1. A pickup at 60 Hz is sampled 50 times each second. At what frequency does it appear? Repeat for a signal at 120 Hz at the same sample rate.

Answer

The Nyquist frequency is 25 Hz. For 60 Hz, : Hz. For 120 Hz, : Hz.

2. An RC filter has and , and its source has a negligible resistance. Find the corner frequency and the gain at 50 Hz.

Answer

, so Hz. The gain at 50 Hz is , or −10.4 dB.

3. A temperature is sampled once each second. The noise on one sample has a standard deviation of 0.5 °C and the samples are independent. How many samples must be averaged for 0.1 °C? Find the length of the window and the mean delay.

Answer

samples. The window is 25 s and the mean delay is s.

4. A first-order filter must reduce a 50 Hz pickup to 5 percent of its amplitude. Find the corner frequency. With a 10 µF capacitor and a source of negligible resistance, find the exact resistance, then choose 6.8 kΩ and find the corner and the gain at 50 Hz that result.

Answer

gives , so Hz. The exact resistance is . With 6.8 kΩ the corner is 2.34 Hz and the gain at 50 Hz is 0.047.

5. A 10-bit ADC with a 5 V reference reads a signal of 0 to 5 V that represents 0 to 100 °C. Find the size of one count in °C and the standard uncertainty from quantisation. The noise on the signal is 0.002 °C. Will the mean of 100 samples have a finer resolution than one sample?

Answer

One count is °C, and °C. The noise is about one fiftieth of a count, so nearly every sample returns the same count and the mean is no better than one sample. Averaging needs noise of about half a count or more to improve on the count.

6. A moving average of 16 samples is applied to a signal sampled 20 times each second, inside a loop that works near 0.5 rad/s. Find the mean delay and the lag it adds. If the loop has a phase margin of 45 degrees, what share of the margin is used?

Answer

s. The lag is rad, which is 10.7 degrees: 24 percent of the margin.

References



  • J. P. Bentley, Principles of Measurement Systems, 4th edition, Pearson Education, 2005.
  • R. S. Figliola and D. E. Beasley, Theory and Design for Mechanical Measurements, 6th edition, Wiley, 2015.
  • H. W. Ott, Electromagnetic Compatibility Engineering, Wiley, 2009.
  • P. Horowitz and W. Hill, The Art of Electronics, 3rd edition, Cambridge University Press, 2015.


© 2021-2026 SiliconWit®. All rights reserved.
Untwisted pair: one large loop, the field adds one polarity Twisted pair: many small loops, each one opposite to the next, so the induced voltages cancel + − + − + −
0 10 20 30 40 50 Hz the alias appears at 10 Hz half the sample rate (30 Hz) the true pickup at 50 Hz
loop current ADC input ADC ground 150 Ω sense resistor R = 3.3 kΩ C = 10 µF
Watch it build: noise on a slow signal
PT 150 Ω ADC N pressure: slow, about 3 s 50 Hz: 25 counts4 kHz: 62 counts RC 50 Hz: 2.3 counts4 kHz: 0.07 then sample, and average one value per 0.1 s
  1. The pressure reaches the ADC as a voltage across 150 Ω, and it changes slowly.
  2. The drive adds 50 Hz and 4 kHz: 20 mV and 50 mV, which are 25 and 62 counts.
  3. An RC filter at 4.61 Hz leaves 1.84 mV of the 50 Hz and 0.06 mV of the 4 kHz.
  4. Only then sample and average: the mean of each 0.1 s removes the 50 Hz left over.
Predict first

A pressure signal carries a 50 Hz pickup from the mains. The converter takes 60 samples each second. What does the pickup look like in the samples?

See it: what the filter keeps and what it stops

Pressure at 2 Hz kept
Mains left, of 20 mV
Switching left, of 50 mV

The noise of Application 1 at the sense resistor: 20 mV of mains at 50 Hz and 50 mV of switching near 4 kHz. One count of the converter is 0.806 mV. Move the corner down and the mains pickup shrinks, but the pressure starts to lose amplitude and the loop gains lag. Move it up and the mains pickup gets through. A first-order filter separates two frequencies well only when they are far apart.

real: 5/6 turn forwardphotos: 1/6 turn back 50 Hz sampled 60 times a second looks like 10 Hz.
See it: the wave the samples describe

Half the sample rate
Seen in the samples
Samples in one true cycle

The grey line is the true signal and the dots are what the converter takes. The gold line is the slowest wave that passes through every dot, and that is what the converter reports. Below half the sample rate it is the true wave. Above it, the gold line is a false, slower wave, and nothing in the numbers can show that it is false.

Check yourself

Three questions. Each wrong choice is a mistake people really make, so read the note after you answer.

1. A drive switches at 4010 Hz. Its noise reaches a signal that is sampled 200 times each second, with no filter before the converter. At what frequency does the noise appear in the samples?

2. To remove a 50 Hz pickup, a technician builds a first-order RC filter with its corner frequency at exactly 50 Hz. How much of the pickup reaches the converter?

3. A pressure arrives 10 times each second with independent noise of 0.04 bar (one standard deviation). The display must show 0.01 bar. How many values must a moving average hold, and what is its mean delay?

Found this useful?

Discussion

    Comments show your name. Be kind, stay on the topic.