Electronics

RC filters in practice: cutoff, time constant, debounce and sensor smoothing

What the time constant and the −3 dB cutoff of an RC filter mean, why 20 dB per decade is often not enough, and how the one-resistor-one-capacitor filter is used to debounce a switch, smooth a sensor, turn PWM into a voltage, and why the source and the load are part of it.

Author
Ahmedonics Engineering
Published
Last updated
Illustration of a resistor and capacitor on a breadboard turning a noisy waveform into a smooth one, with an oscilloscope behind

Put a resistor in series with a signal and a capacitor from the far end to ground and you have built the most used filter in electronics. It smooths a thermistor reading, turns a PWM output into a slow analogue voltage, takes the chatter out of a push-button and knocks mains hum off a sensor lead. One number describes it, the time constant τ = R × C, and nearly every design decision comes down to how large τ should be and what that costs in delay. This guide is the reasoning behind the RC low-pass filter calculator.

One resistor, one capacitor, one number: τ

Apply a step of voltage to the resistor and the capacitor charges through it. The current is largest at the start, when the whole step is across the resistor, and falls as the capacitor voltage rises, so the charge follows an exponential:

v(t) = Vstep × (1 − e−t/τ) τ = R × C

Ohms times farads are seconds, and the useful mental shortcuts are kilohms times microfarads for milliseconds and kilohms times nanofarads for microseconds: 10 kΩ and 100 nF is 1 ms, 10 kΩ and 1 µF is 10 ms, 100 kΩ and 10 µF is a second. After one time constant the output has covered 63.2 % of the step; after 2.30 τ, 90 %; after 3.00 τ, 95 %; after 4.61 τ, 99 %; after 6.91 τ, 99.9 %. The rise time from 10 % to 90 %, the number on an oscilloscope, is 2.2 τ. Discharge is the mirror image. The output never quite arrives, which is why every use of an RC comes with a decision about how close is close enough: 99 % is 4.6 τ, and a system that waits for 99.9 % waits half as long again.

Cutoff frequency and what −3 dB means

Feed the same circuit a sine wave instead of a step and the capacitor, whose impedance falls with frequency, forms a frequency-dependent divider with the resistor. The output falls off as:

|H(f)| = 1 ÷ √(1 + (f ÷ fc)²) fc = 1 ÷ (2π R C) = 1 ÷ (2π τ) φ = −arctan(f ÷ fc)

At the cutoff fc the output is 1 ÷ √2 = 0.707 of the input, which is −3.0 dB, or half the power, with a phase lag of 45°. That is a convention, not a wall: at fc the signal is 70 % there, and at a tenth of fc the loss is a negligible 0.04 dB with 5.7° of lag. The time constant and the cutoff are the same fact in two units: τ = 1 ms means fc = 159 Hz, and a filter that takes 4.6 ms to settle to 1 % is the same filter that is 3 dB down at 159 Hz. Choose one and the other is fixed. That link is the whole trade-off in RC filtering: attenuation at a frequency is bought with delay in time.

Circuit Vin R = 10 kΩ Vout C = 100 nF τ = RC = 1 ms fc = 1 ÷ 2πRC = 159 Hz Magnitude response 101001k10k Hz 0 dB−20−40 −3 dB at fc −20 dB / decade at 1 kHz: −16 dB, phase −81° at 50 Hz: −0.4 dB, passes Step response 100 % 63 % τ 4.6 τ 63 % at τ = 1 ms, 99 % at 4.6 ms 10–90 % rise time 2.2 τ = 2.2 ms
The RC low-pass filter, its magnitude response on a log-log plot with the −3 dB corner at fc and the −20 dB/decade slope above it, and its step response climbing to 63 % at one time constant.

The gentle slope: −20 dB per decade and why that is often not enough

Well above fc the response approaches fc ÷ f: a tenth at 10 × fc, a hundredth at 100 × fc. That is 20 dB per decade, or 6 dB per octave, and it is all a single RC can do because it has one energy-storing element. For smoothing and debouncing it is plenty. For removing an interferer close to the signal it is not. Take 50 Hz hum on a signal that changes over a second or so: a corner at 5 Hz leaves the hum at a tenth, reduced but present, and getting it to a thousandth would need fc = 0.05 Hz, a time constant of 3.2 s and a reading that takes fifteen seconds to settle. The better answers are a second-order filter (a Sallen-Key stage with one op-amp gives 40 dB per decade and a sharper knee), a notch, or, cheapest of all in a microcontroller, averaging the ADC readings over exactly one mains cycle, 20 ms, which nulls 50 Hz and its harmonics without adding a part.

Cascading two RC sections is the obvious way to steepen the slope and it works, with a caveat: the second section loads the first. Give the second resistor at least ten times the value of the first (and the capacitor a tenth) or put a buffer between them; and note that two identical buffered sections are not 3 dB down at fc but 6 dB, their combined corner sitting at about 0.64 × fc.

Debouncing a switch

A mechanical contact does not close once; it bounces, opening and closing for a few milliseconds and on a worn or large switch for 10–20 ms, and a microcontroller reading the pin sees a burst of presses. The RC cure: a pull-up resistor R to the supply, a capacitor C from the pin to ground, and a Schmitt-trigger input. With R = 10 kΩ and C = 1 µF, τ = 10 ms.

  • Press. The switch shorts the capacitor to ground and the pin falls at once. When the contact bounces open for a millisecond the capacitor recharges through R by only 1 − e−0.1 = 9.5 % of the supply before the contact closes again and pulls it back down. The input never sees the bounce.
  • Release. The capacitor charges with τ = 10 ms and crosses half the supply after τ × ln 2 = 6.9 ms; a bounce during that ramp drags it back and the ramp restarts. The input sees a clean, slow rise.
  • The input must be a Schmitt trigger. A slow ramp through an ordinary logic input spends milliseconds in the undefined region between low and high, where noise makes it chatter and the gate draws excess current. A 74HC14 or a microcontroller pin with hysteresis (check the datasheet; not all have it) turns the ramp into one clean edge. Without hysteresis, read the pin in software after 2–3 τ.
  • Protect the contacts. Closing a switch straight across 1 µF dumps its charge as a current spike limited only by contact resistance; a resistor of about 1 kΩ between the switch and the capacitor limits it and barely changes the timing.

Software can do the same job (sample every few milliseconds, accept a change after several consistent reads), and often does; the RC still earns its place on a long cable, where it also keeps electrical noise and ESD out of the pin.

Smoothing a sensor signal

A thermistor in air, a pressure transmitter on a tank, a potentiometer on a valve stem: signals that change over seconds, read by an ADC that samples in microseconds and is happy to record every spike of noise on the lead. The RC filter goes between them, with fc well below the fastest real change but well above nothing. A thermistor with a thermal time constant of ten seconds cannot change faster than about 0.02 Hz; an RC corner at 1 Hz (160 kΩ and 1 µF, or 16 kΩ and 10 µF) leaves that untouched and attenuates 50 Hz by 34 dB, to 2 %. The price is lag: a first-order filter delays a slowly changing signal by τ, 160 ms here, and after power-up or a range change the reading takes 4.6 τ to be within 1 % of the truth. Choose τ as large as the lag you can afford and no larger, and remember that the same capacitor doubles as the charge reservoir the ADC needs, as explained in voltage dividers and loading.

Two things a low-pass does not do. It does not remove an offset, because it passes DC; a sensor with a 50 mV zero error keeps it. And it does not prevent aliasing unless the corner is far below half the sample rate: with fc at a tenth of the sample rate, a single RC is only 14 dB down at the Nyquist frequency. Sample faster than the signal needs, filter digitally, and let the RC take care of the radio-frequency pickup.

Turning PWM into a voltage

A microcontroller without a DAC makes an analogue voltage by pulsing a pin at frequency fPWM with duty D and filtering the pulses: the average is D × Vsupply, and the RC removes the rest. What is left is ripple at fPWM. When fPWM is at least ten times fc, the capacitor voltage moves almost linearly within each pulse and the peak-to-peak ripple is approximately:

Vripple ≈ Vsupply × D × (1 − D) ÷ (fPWM × τ) ≈ 1.6 × Vsupply × fc ÷ fPWM at 50 % duty

It is an approximation, worst at 50 % duty and optimistic near 0 % and 100 %, but close enough to design with. A 5 V output pulsed at about 1 kHz, the default of many hobby boards, through 10 kΩ and 100 nF (τ = 1 ms) leaves 1.25 V of ripple: useless. With 10 kΩ and 10 µF (τ = 100 ms, fc = 1.6 Hz) the ripple is 12.5 mV, a quarter of a per cent, but the output now takes 0.46 s to follow a change in duty. The better move is to raise fPWM: at 31 kHz, τ = 10 ms gives about 4 mV of ripple and settles in 46 ms. Two more limits: the resolution is the PWM's, 19.6 mV per step for 8 bits at 5 V; and the accuracy is that of the logic supply, since a PWM "DAC" has no reference. The output impedance is R itself, 10 kΩ, so anything that draws current needs a buffer after the filter.

Loading: the source and the load are part of the filter

The formula assumes the resistor is driven by a perfect voltage source and the capacitor feeds nothing. Neither is true, and both errors go the same way.

  • Source resistance adds to R. A sensor with 1 kΩ of output resistance feeding 10 kΩ and 100 nF makes an 11 kΩ filter with a corner at 145 Hz instead of 159 Hz. A potentiometer wiper, whose source resistance changes with position (up to a quarter of the track), gives a corner that moves as the knob turns.
  • A load forms a divider with R. A 100 kΩ input on the example takes the DC gain to 100 ÷ 110 = 0.909 and, because the capacitor now discharges through R ∥ RL, raises the corner to 175 Hz. A load of 10 kΩ would halve the signal.
  • Cascaded stages load each other, as above: step the impedance up tenfold per stage or buffer.

The rule is the same as for any divider: drive the filter from an impedance much lower than R and into one much higher, or put an op-amp follower on whichever side breaks the rule. A follower before an ADC also solves the sampling-capacitor problem, so in an instrument it is often the cheapest part on the board.

The example in numbers

R = 10 kΩ, C = 100 nF, and 1 kHz to be judged:

  1. τ = 10 kΩ × 100 nF = 1.00 ms; fc = 1 ÷ (2π × 1 ms) = 159.2 Hz.
  2. At 1 kHz, f ÷ fc = 6.28: |H| = 1 ÷ √(1 + 39.5) = 0.157, or −16.1 dB, with a phase lag of 81.0°.
  3. Step response: 63.2 % at 1.00 ms, 90 % at 2.30 ms, 99 % at 4.61 ms, 99.9 % at 6.91 ms; rise time 2.20 ms.
  4. Solving instead for R at a 1 kHz corner with the same 100 nF: 1.59 kΩ, nearest E24 1.6 kΩ, giving 994.7 Hz and τ = 160 µs.

The calculator flags 1 kHz as sitting between fc and 10 × fc, where a single RC leaves 15.7 % of it. Whether that is a problem depends on whether the kilohertz is signal or noise, and the decision is the designer's: lower the corner and accept more lag, add a second stage, or move the corner up and keep the kilohertz. Filters like this sit at the front of most of the measurement and control boards Ahmedonics designs for automation systems, where getting τ right is the difference between a controller that responds and one that hunts.

References

  • P. Horowitz and W. Hill, The Art of Electronics, 3rd ed., Cambridge University Press, 2015 — §1.4 RC circuits and the time constant; §1.7 RC filters
  • J. Ganssle, A Guide to Debouncing, 2004 (rev. 2008) — measured bounce times of real switches; hardware and software debounce circuits
  • IEC 60063:2015, Preferred number series for resistors and capacitors — E12, E24 and E96 values
  • STMicroelectronics, AN2834: How to get the best ADC accuracy in STM32 microcontrollers — source impedance, sampling time and the input capacitor