Skip to content
Tactiverge

Textbooks/Signals and Systems/Chapter 8Lite (plain text) version

8Filters seen in frequency

Version 1 · Technically checked (automated checks only) · 3 source lessons · 8 practice items

Text
All chapters and search
  1. 1. Signals and noise
  2. 2. Sampling and the Nyquist rate
  3. 3. Aliasing: when samples lie
  4. 4. Quantisation and resolution
  5. 5. Smoothing filters
  6. 6. Sinusoids and Fourier series
  7. 7. The DFT: measuring a spectrum
  8. 8. Filters seen in frequency

Introduction

Look at a filter through the frequency lens and its behaviour becomes a single graph: how much of each sinusoid gets through. The moving average passes slow signals, attenuates fast ones and completely blocks certain frequencies, its nulls. The first-order IIR filter, a cousin of the exponential smoother and of the RC circuit, rolls off smoothly above its cut-off. Choosing a filter is choosing that curve.

The moving average is a low-pass filter0.769 at 10 Hz25500frequency (Hz)nulls at multiples of fs / N
Figure 8.1. The moving average is a low-pass filter. Gain against frequency from 0 to 50 Hz for a 4-point moving average sampled at 100 Hz. The gain is 1 at 0 Hz, 0.769 at 10 Hz, and falls to zero at 25 Hz and 50 Hz, multiples of fs / N.

Explanation

This chapter is built from 3 School lessons. Each part below is the lesson's own explanation; open the lesson for its predict-and-discover activities.

8.1 The moving average, seen in frequency

Averaging the last four readings smooths a sensor beautifully. So why does it completely erase one particular frequency?

One line of code

y[n] = (x[n] + x[n−1] + … + x[n−M+1])/M. It is a finite impulse response (FIR) filter: an impulse affects exactly M outputs, then is forgotten. Random noise of standard deviation σ comes out with σ/√M, because independent errors partly cancel.

Nulls and side lobes

Its gain is 1 at DC and falls to exactly zero at fs/M, 2fs/M, …, with bumps (side lobes) in between: the first is about 0.22 for large M. Great for removing a known interference, like 50 Hz mains when fs/M = 50 Hz, but a mediocre general low-pass because the side lobes leak.

The price: lag

The output is centred (M − 1)/2 samples in the past. With M = 9 at 100 Hz that is 40 ms: fine for a thermometer, dangerous inside a fast control loop where delay erodes stability. Doubling M halves the noise power again but doubles the lag.

Derivation: The moving-average frequency response
  1. Input x[n] = e^{jωn} with ω = 2πf/fs. Output y[n] = (1/M)·Σ_{k=0}^{M−1} e^{jω(n−k)} = e^{jωn}·H, with H = (1/M)·Σ e^{−jωk}.

  2. That is a geometric series: H = (1/M)·(1 − e^{−jωM})/(1 − e^{−jω}).

  3. Factor out half-angles: (1 − e^{−jθ}) = e^{−jθ/2}·2j·sin(θ/2).

  4. So |H| = |sin(ωM/2) / (M·sin(ω/2))| = |sin(πMf/fs)/(M·sin(πf/fs))|, with a pure delay of (M − 1)/2 samples.

  5. It is 1 at f = 0 and 0 whenever Mf/fs is a whole number (other than multiples of M): nulls at f = fs/M, 2fs/M, …

Common mix-ups

  • A longer moving average is always better.
    ✓ It smooths more but lags more; inside a control loop the lag can cause oscillation.
  • A moving average blocks all frequencies above its cut-off.
    ✓ Its side lobes let some high frequencies leak through; it is only zero at the nulls.

Open the full lesson: The moving average, seen in frequency →

8.2 A filter with memory: first-order IIR

One multiply, one add and a single remembered number can smooth a sensor as well as averaging dozens of readings. How?

Infinite memory in one number

Unlike a moving average, the IIR (infinite impulse response) filter feeds its own output back. An impulse never fully disappears; its influence decays by (1 − α) every sample. The weights on past inputs are α, α(1 − α), α(1 − α)², …: an exponentially fading average.

One knob

Large α (close to 1) follows the input almost immediately; small α smooths heavily but responds slowly (time constant about 1/α samples). It behaves like an RC low-pass with RC ≈ T/α, so the cut-off is roughly fc ≈ α·fs/(2π) for small α.

High-pass for free

x[n] − y[n] keeps what the low-pass removed: fast changes pass and any steady offset decays to zero. Use it to remove a slow drift, such as a gyroscope's bias, while keeping quick motions. Combining a high-passed gyro with a low-passed accelerometer is the complementary filter used on drones.

Derivation: Steady state and time constant of the first-order IIR
  1. Filter: y[n] = αx[n] + (1 − α)y[n−1], with 0 < α ≤ 1.

  2. Steady state for constant input X: set y[n] = y[n−1] = y. Then y = αX + (1 − α)y, so αy = αX and *y = X**. DC gain is 1.

  3. Step response from y[−1] = 0: the gap X − y shrinks by (1 − α) each sample, so y[n] = X·(1 − (1 − α)^{n+1}).

  4. Time constant: the gap falls to 1/e (37 %) after n with (1 − α)^n = e^{−1}, so n = −1/ln(1 − α) ≈ 1/α for small α. α = 0.1 gives about 9.5 samples.

  5. Frequency response: H = α/(1 − (1 − α)e^{−jω}). At ω = 0 this is 1; at Nyquist (ω = π) it is α/(2 − α), the strongest attenuation.

Common mix-ups

  • The IIR filter makes a constant reading smaller.
    ✓ Its DC gain is 1; constants pass unchanged once it has settled.
  • α is a cut-off frequency.
    ✓ α is a mixing fraction; the cut-off is roughly α·fs/(2π) for small α.

Open the full lesson: A filter with memory: first-order IIR →

8.3 The RC time constant, from measurements

A capacitor charging through a resistor never quite finishes. So how can engineers say exactly how long it 'takes'?

Why it slows down

At switch-on the capacitor is empty, so the whole supply voltage sits across the resistor and a big current I = V/R flows. As charge builds up, the capacitor's voltage rises, the resistor's share falls, and the current shrinks. Less current means slower charging. The voltage approaches the supply ever more slowly: it never quite arrives, but it gets close very quickly.

The curve and its landmarks

The charging voltage is v(t) = V(1 − e^(−t/τ)) with τ = R·C. Ohms times farads gives seconds (and kΩ × µF gives milliseconds). After 1τ the capacitor is at 63.2 % of V, after 2τ 86.5 %, after 3τ 95 %, after 5τ 99.3 %. Engineers usually call it 'charged' after about 5τ. Discharging follows v = V·e^(−t/τ): 36.8 % left after one τ.

Measuring τ from data

On a measured curve, the quickest estimate is the time at which the voltage reaches 63 % of its final value. A better one uses every point: rearrange to τ = −t / ln(1 − v/V), compute it at several times and average. If ln(1 − v/V) plotted against t is a straight line, the circuit really is first-order, and the slope is −1/τ. Knowing R, the capacitance follows as C = τ/R.

Hitting a threshold

Many circuits care about when the capacitor crosses a voltage, such as a chip's reset threshold. Solve v = V(1 − e^(−t/τ)) for t: t = −τ·ln(1 − v/V). Crossing half the supply takes τ·ln 2 ≈ 0.69τ; crossing 90 % takes τ·ln 10 ≈ 2.3τ. Thresholds near the supply voltage take much longer and are sensitive to component tolerances.

Derivation: Solving the charging equation
  1. Around the loop: V = i·R + v. The capacitor's current is i = C·dv/dt, so R·C·dv/dt = V − v.

  2. Separate variables: dv/(V − v) = dt/(RC).

  3. Integrate from v = 0 at t = 0: −ln(V − v) + ln V = t/(RC), so ln((V − v)/V) = −t/(RC).

  4. Exponentiate: (V − v)/V = e^(−t/RC), so v(t) = V(1 − e^(−t/τ)) with τ = RC.

  5. At t = τ: v = V(1 − e^(−1)) ≈ 0.632·V. Taking logs of the same line gives the measurement formula τ = −t/ln(1 − v/V).

Common mix-ups

  • The time constant is how long the capacitor takes to charge fully.
    ✓ τ is the time to reach about 63 %. 'Fully' (99 %) takes about 5τ, and mathematically it never quite finishes.
  • A bigger supply voltage makes the capacitor charge faster.
    ✓ τ = RC does not depend on V. A bigger supply reaches any fixed voltage sooner, but the shape and the 63 % time stay the same.
  • The capacitor value printed on the can is exact.
    ✓ Electrolytic capacitors often have ±20 % tolerance. Measuring τ and dividing by R gives the real value in your circuit.

Open the full lesson: The RC time constant, from measurements →

Worked examples

The moving average, seen in frequency: example 1

A 5-point moving average filters x = [2, 4, 6, 8, 10, 12]. Find y[4] and y[5].

Solution

y[4] = (2 + 4 + 6 + 8 + 10)/5 = 6. y[5] = (4 + 6 + 8 + 10 + 12)/5 = 8. A ramp comes out as the same ramp delayed by (5 − 1)/2 = 2 samples.

A filter with memory: first-order IIR: example 1

α = 0.2, step input x = 1 from n = 0, y[−1] = 0. Find y[0], y[1], y[2].

Solution

y[0] = 0.2. y[1] = 0.2 + 0.8 × 0.2 = 0.36. y[2] = 0.2 + 0.8 × 0.36 = 0.488. Check: 1 − 0.8³ = 0.488.

The RC time constant, from measurements: example 1

With 9 V, 1 kΩ and 1,000 µF, find τ, the voltage at 0.5 s and 2 s, and the time to reach 5 V.

Solution

τ = 1,000 Ω × 0.001 F = 1 s. v(0.5) = 9(1 − e^(−0.5)) ≈ 3.54 V; v(2) = 9(1 − e^(−2)) ≈ 7.78 V. Time to 5 V: t = −1 × ln(1 − 5/9) = −ln(0.444) ≈ 0.811 s.

The RC time constant, from measurements: example 2

A capacitor of unknown value charges from 9 V through 1 kΩ. You measure 6.0 V at 1.1 s. Estimate C.

Solution

τ = −1.1/ln(1 − 6/9) = −1.1/ln(0.333) = 1.1/1.0986 ≈ 1.00 s. C = τ/R = 1.00/1,000 ≈ 1,000 µF. Repeating at several times and averaging makes the estimate less sensitive to one bad reading.

Interactive figures

Figure 8.2 from The moving average, seen in frequencyChoose 'Moving average', low-pass. Set M = 4 and slide the test frequency to find the null. Change M to 8 and 2: where do the nulls go? Watch the step response: how many samples does it take to reach the top?
Can't use the interactive? Read a description instead

In the explorer, the 4-point moving average has gain 1 at 0, falls to about 0.77 at f/fs = 0.1, and reaches 0 at f/fs = 0.25 (a null), with a small bump after it. With M = 8 the first null moves to 0.125. The step response climbs in M equal steps to 1.

Interactive figure (online). Description: In the explorer, the 4-point moving average has gain 1 at 0, falls to about 0.77 at f/fs = 0.1, and reaches 0 at f/fs = 0.25 (a null), with a small bump after it. With M = 8 the first null moves to 0.125. The step response climbs in M equal steps to 1.

Laboratory

Everything runs in your browser. No kit, nothing mains-powered. Simulations are simplified educational models.

  • Simulation OS experiment

    Simulation OS: RC charging and discharging

    Measure the RC time constant and compute the cut-off frequency 1 / (2πRC) of the same circuit used as a filter.

    Open Simulation OS: RC charging and discharging →
  • Studio

    Code Lab

    Pass sines of 5, 10, 25 and 40 Hz through a 4-point moving average at 100 Hz and measure each output amplitude.

    Open Code Lab →

Guided practice

Answers are checked on the server; wrong answers get a hint and another try. Signed in, solved items also count towards the source lesson.

Practice 1

A moving average with M = 10 runs at fs = 500 Hz. What is the lowest frequency it removes completely, in Hz?

Hz

Practice 2

How many samples of delay does a 9-point moving average add?

samples

Practice 3

Noise on a sensor is random with standard deviation 4 mV. Roughly what is it after a 16-point moving average?

Practice 4

y[n] = 0.5x[n] + 0.5y[n−1], y[−1] = 0, and x[n] = 4 for n ≥ 0. What is y[1]?

Practice 5

For a constant input X, the first-order IIR low-pass settles at…

Practice 6

Using n ≈ −1/ln(1 − α), about how many samples is the time constant for α = 0.1 (1 decimal place)?

samples

Practice 7

A gyroscope reading has a slow, steady bias of 0.3 °/s. Which output removes it?

Practice 8

After exactly one time constant, how far has a charging capacitor got towards the supply voltage?

  1. A moving average with M = 10 runs at fs = 500 Hz. What is the lowest frequency it removes completely, in Hz? (Hz)
  2. How many samples of delay does a 9-point moving average add? (samples)
  3. Noise on a sensor is random with standard deviation 4 mV. Roughly what is it after a 16-point moving average?
    • 4 mV
    • 1 mV
    • 0.25 mV
    • 2 mV
  4. y[n] = 0.5x[n] + 0.5y[n−1], y[−1] = 0, and x[n] = 4 for n ≥ 0. What is y[1]?
  5. For a constant input X, the first-order IIR low-pass settles at…
    • αX
    • (1 − α)X
    • X
    • 0
  6. Using n ≈ −1/ln(1 − α), about how many samples is the time constant for α = 0.1 (1 decimal place)? (samples)
  7. A gyroscope reading has a slow, steady bias of 0.3 °/s. Which output removes it?
    • The IIR low-pass y
    • x − y (the high-pass)
    • x itself
    • 2y
  8. After exactly one time constant, how far has a charging capacitor got towards the supply voltage?
    • 50 %
    • About 63 %
    • About 90 %
    • 100 %

Engineering applications

  • Killing mains hum

    Averaging over exactly one mains cycle puts a null at the mains frequency and all its harmonics. Precision meters use this to ignore 50 Hz pickup almost completely.

  • Removing drift

    A high-pass filter, built by subtracting a low-pass output from the input, removes slow drift such as a gyroscope's bias, keeping only the fast changes that matter for motion.

Watch

Optional verified videos. Nothing loads from YouTube until you press play.

An overview of the two families of digital filters and how they differ.

12 min 27 s · captions on YouTube · source

Nothing loads from YouTube until you press play.

One idea, many uses: moving averages, image blurs and probability all turn out to be the same sliding multiply-and-add.

Length: see YouTube · captions on YouTube · source

Nothing loads from YouTube until you press play.

  • Overview of FIR and IIR Filters (Barry Van Veen)
  • But what is a convolution? (3Blue1Brown)

Chapter summary

  • A filter's frequency response shows the gain applied to each sinusoid.
  • An N-point moving average has nulls at multiples of fs / N.
  • A first-order IIR filter y = y + α(x − y) behaves like an RC low-pass with time constant τ.
  • Input minus low-pass output gives a high-pass filter.

Glossary

Low-pass filter (moving average and EMA)
A low-pass filter lets slow changes through and attenuates fast ones. In firmware the simplest are the moving average and the exponential moving average.
RC time constant
When a capacitor charges or discharges through a resistor, the voltage changes exponentially with time constant τ = R × C.
First-order system and time constant
A first-order system responds to a step by approaching its new value exponentially; its time constant τ is the time to cover 63.2 % of the change.
Exponential growth and decay
A quantity decays exponentially when its rate of decrease is proportional to how much is left, giving y = y0 × e^(−t/τ).

Definitions from the Field Guide.

Project: A filter to a written spec

A sensor sampled at 200 Hz carries a useful signal below 5 Hz and interference at 50 Hz. Design a moving average and a first-order IIR filter, compute each one's gain at 5 Hz and 50 Hz, and recommend one. Test your recommendation on synthetic data.

Deliverables

  • Both designs with their parameters
  • Gains at 5 Hz and 50 Hz, calculated and measured
  • A recommendation with its lag stated

Keep your work in your Engineering Journal; it stays private unless you choose to share it.

References

  • Alan V. Oppenheim et al. (1997). Signals and Systems, 2nd edition. Prentice Hall.
  • Alan V. Oppenheim and Ronald W. Schafer (2010). Discrete-Time Signal Processing, 3rd edition. Pearson.
  • Steven W. Smith (1997). The Scientist and Engineer's Guide to Digital Signal Processing. California Technical Publishing.

Publication record

Version
1
Status
Technically checked (automated checks only)
Technical review
Automated checks only, last run 2026-11-29. No human, educator or mentor review is claimed.src/content/textbooks/textbooks.test.ts: schema, every lesson, diagram, practice item, video, Field Guide entry, lab and reference resolves; figure numbers recomputed; no practice answers in client payloads.
Written by
Compiled and written by the Tactiverge team with AI assistance, from Tactiverge School lessons that were themselves written with AI assistance.
Licence
All rights reserved by the founders unless a licence is approved.
Corrections
None recorded yet.Spotted a mistake? Use “Report a problem” on any chapter, or see the corrections page.