# Should I always put a low-pass filter on an ADC input?

I'm a recent hobbyist EE and new to micro controllers.

I've built a test circuit to make measurements with a type K thermocouple, a PT1000 as well as an oxygen sensor. The weak signals go through a low-pass filter to remove high frequency noise and are amplified by OPs before they go to the ADC inputs of an Atmega328p (not Arduino).

In my code I am doing noise cancelling with CPU sleep/ADC interrupt, 16x oversampling and creating a moving average.

The measurements are stable if the circuit is powered via the USB of a laptop and particularly stable if the laptop itself is connected to AC. But when the device is powered with a wall-wart, the readings are very unstable unless I ground the circuit. The readings are also stable with no sensors connected, i.e. the PT1000 with its 4m cable replaced by a resistor.

Putting a low-pass filter with a cutoff frequency of 1.59 Hz in front of the ADC input helps a lot and stabilizes the measurements, so I guess my circuit suffers from 50/60 Hz noise.

So my question: For such slow signals, is it a good idea to always put such a low-pass filter in front of the ADC input or would I just connect the device to ground? Which would be strange when powering the device with batteries or a non-grounded power supply.

## 2 Answers

It's usually a good idea to put an anti-alias filter in front of the ADC's input and if this also removes unwanted noise from the signal that is also useful. However, I don't think the filter is the full answer to why your circuit suffers "variations" when disconnected from the AC supply. You should try using a resistor potential divider to halve the dc rail to your ADC and feed this into the input to see if it is (somehow) and ADC problem or an external problem. It could be a problem with wires on the input and there ability to pick-up AC magnetically or it could be something else.

It's also worth saying that allowing a little high frequency noise thru with your signal can lead to high resolution results - it's called dithering.

• I've tried what you suggested. If the device runs ungrounded (laptop battery) with no sensors connected and a voltage between both rails, the readings are stable. If I connect the sensors (3-4 meters of cable each), still pretty stable. When I connect the wall-plug power supply, the readings get very unstable. Mar 3, 2015 at 19:12
• So it has to be pickup from the cables. And the common factor appears to be the wall-wart itself supplying power. In your question I presumed it was quiet when the wall wart was plugged in the wall but not switched on. Is this correct? Mar 3, 2015 at 22:27
• No, I think my question is confusing there. With sensors connected and powered by the wall-wart it is unstable but gets quiet as soon as I ground it. It is also pretty quiet when powered via USB from the laptop running on battery, and again very stable when the laptop runs on AC, which also provides some sort of grounding I suppose. Mar 4, 2015 at 7:53
• OK I think I understand. Wall warts are electrical isolating at AC power frequencies but, in terms of the switching noise they produce, both DC output wires are dancing around (with respect to local earth) quite a lot. I'm talking several volts peak-to-peak on some. This is high frequency jitter that wouldn't affect a balanced input circuit but I suspect what you have is probably unbalanced and so this supposedly common-mode noise turns into a differential noise due to the imbalanced input impedances of both sensor wires. Mar 4, 2015 at 8:19
• I just learned about balanced vs. unbalanced and yes, all three sensor inputs are unbalanced. And BTW, two of them have one wire connected to GND and the other to input of simple non-inverting OPs. The third sensor is connected to an instrumentation amplifier, so none of the two wires is connected to GND. I suppose there is nothing wrong with that? Mar 4, 2015 at 8:48

You want to put a low-pass filter on any ADC input (except the very high-speed types which are being used to acquire very high-speed signals). 60 Hz pickup is not the only source of noise you have to worry about. Line noise from nearby motors is another, not to mention radio stations and such. The reason you have to worry about such high-frequency sources is that any transistor junctions can act as rectifiers, and even radio signals can occasionally show up on low-frequency ADCs due to this effect. The less often you sample the signal the more important this is.

Input filters can be thought of as dealing with two different sources of "noise". The first is aspects of the original signal which are simply beyond the Nyquist limit, and in this role is referred to as an antialiasing filter. The second is injected noise which is beyond the abilities of the circuit handling it. In this aspect, it's particularly important to provide filters at the point where the external signal, such as the inputs from a temperature sensor, enter the electronics. This applies to signal conditioning amplifiers especially.

So there are really two filters to think about - system input and ADC input. The system input filters should be capable of rejecting very high frequencies - think ceramic capacitors with fairly low values. The ADC filters don't necessarily need to be separate from the signal-conditioning opamps - you can incorporate them into the gain stage, usually with just a single capacitor added across the gain-setting feedback resistor.

Of course, you don't want to over-filter the signal and lose information, so you need to pay a little attention to exactly what frequencies are important to you. Another possibility is to sample your signal at a higher rate than you first think you need, and then perform a lowpass filter in software. This is not necessarily a big deal, since a simple running average will make the equivalent of a single RC section. I notice you've done exactly this. What you don't realize is that in order to get a lower filter frequency you have to perform the running average over a longer string of data. You might try playing around with this. Note that this can be computationally efficient, but at the cost of increased intermediate storage. That is, if you allocate a section of memory to your raw data, you can keep a variable as the running total with the new data being added on a sample-by-sample basis at the same time that the oldest data is subtracted from the total. After the cycling through enough samples the total will have flushed out all the invalid sample data, and you're good after that.

• Thanks for the nice explanations. I am currently building the moving average like average = (average * weight + value) / weight + 1. It is not really a moving average, because old values are not removed but their weight just goes towards 0 as they get "older" if I understand correctly, but I can get a higher smoothing effect by increasing the value of weight. Mar 3, 2015 at 19:32