# Does my sampling rate act as a low pass filter?

#### ThermalEngineer

Joined Mar 23, 2020
7
If I sample a thermocouple at a slow rate such as 1 Hz, do I need Low Pass Filters? I'm not aware of any noise sources that are that low in frequency, and since I'm sampling so slowly, does this by default eliminate noise contributions in the high frequency ranges?

#### crutschow

Joined Mar 14, 2008
34,078
I'm sampling so slowly, does this by default eliminate noise contributions in the high frequency ranges?
No.
When a sample is made, the voltage at that instant, including any noise, is sampled.
The sample can't differentiate between what part of that voltage is the signal and what part is noise.

You can use a low-pass filter to eliminate noise outside the passband (in this case 1/2 Hz).

#### Ian0

Joined Aug 7, 2020
9,533
It leaves nothing to remove high frequency interference.
I assume that the signal you wish to measure varies only slowly. Let's assume that there is a 10kHz interference signal superimposed on it. It's therefore pretty much random whether your sample coincides with a positive peak or a negative peak of the interference signal, and your data will have a random error added to it.
Filter to remove all frequencies above half the sampling frequency - look up Nyquist's theorem.

#### Papabravo

Joined Feb 24, 2006
21,029
If I sample a thermocouple at a slow rate such as 1 Hz, do I need Low Pass Filters? I'm not aware of any noise sources that are that low in frequency, and since I'm sampling so slowly, does this by default eliminate noise contributions in the high frequency ranges?
This situation is covered in the discussion of aliasing. Aliasing can only be eliminated by having an analog filter limit the bandwidth of the input signal to a digital sampling system.

#### ag-123

Joined Apr 28, 2017
276
take a few readings and take an average, that is a low pass filter. there are others who used an exponential smoothing filter

$s_0 = x_0 \\ s_t = \alpha x_t + ( 1 - \alpha) s_{t-1} \\ \text{where:} \alpha \in [ 0, 1]$
https://en.wikipedia.org/wiki/Exponential_smoothing
some used $\alpha = \frac{2}{ n + 1}$ where n is the number of consecutive terms to smooth
https://en.wikipedia.org/wiki/Moving_average#Relationship_between_SMA_and_EMA
The benefit with exponential smoothing is that it works like an RC low pass filter and use very little memory to do all that smoothing.

And if you use (unshielded) wires that is long enough (like in the 10-30 cm (4"-12")), you can get *this* from your "thermal sensor"

This is radio waves, it is real and it is received by a STM32 ADC. This is a "proof" that typical microcontrollers can receive radio waves/signals directly from the air. It is an (accidental) SDR.
https://www.stm32duino.com/viewtopic.php?p=8455#p8455
Try to figure what that temperature will be with all that noise, the sample rates need not be very high.
The thermal sensor voltage is DC and from that chart with all that noise, the sensor voltage is probably around 1.75v.
If you bother to look at 3d printer electronics, they put a 10 uF ! capacitor there.
https://reprap.org/wiki/File:RAMPS1.4schematic.png
this has become widespread practice to put a heavy capacitor to do all that smoothing - for 100s of 1000s of 3d printers running now all around the world. At 10 uF, the response is definitely slow.

Last edited:

#### Papabravo

Joined Feb 24, 2006
21,029
take a few readings and take an average, that is a low pass filter. there are others who used an exponential smoothing filter

$s_0 = x_0 \\ s_t = \alpha x_t + ( 1 - \alpha) s_{t-1} \\ \text{where:} \alpha \in [ 0, 1]$
https://en.wikipedia.org/wiki/Exponential_smoothing
some used $\alpha = \frac{2}{ n + 1}$ where n is the number of consecutive terms to smooth
https://en.wikipedia.org/wiki/Moving_average#Relationship_between_SMA_and_EMA
The benefit with exponential smoothing is that it works like an RC low pass filter and use very little memory to do all that smoothing.

And if you use (unshielded) wires that is long enough (like in the 10-30 cm (4"-12")), you can get *this* from your "thermal sensor"
View attachment 271017
This is radio waves, it is real and it is received by a STM32 ADC. This is a "proof" that typical microcontrollers can receive radio waves/signals directly from the air. It is an (accidental) SDR.
https://www.stm32duino.com/viewtopic.php?p=8455#p8455
Try to figure what that temperature will be with all that noise, the sample rates need not be very high.
The thermal sensor voltage is DC and from that chart with all that noise, the sensor voltage is probably around 1.75v.
If you bother to look at 3d printer electronics, they put a 10 uF ! capacitor there.
https://reprap.org/wiki/File:RAMPS1.4schematic.png
this has become widespread practice to put a heavy capacitor to do all that smoothing - for 100s of 1000s of 3d printers running now all around the world. At 10 uF, the response is definitely slow.
Doing a digital lowpass filter will be of no help without the analog anti-aliasing filter, It will be subject to the same problems as the original system. There is no real argument about this.

#### ag-123

Joined Apr 28, 2017
276
Thanks @Papabravo
I think you are right about it, but that if the noise is just as extreme as my previous figure, I'd guess it'd help somehow. In a sense, the errors are now averaged, and the sample mean would be closer to the true mean assuming that the true mean is after all DC.

But normally, using an RC filter before the ADC is easy, cheap and effective, I'd guess most would just do that. And it solves the problem itself.

#### Ian0

Joined Aug 7, 2020
9,533
Unfortunately not, the effect of aliasing is to transform the frequencies that are outside your bandwidth INTO your bandwidth, and when they are within your bandwidth, they look like real signals.

You can make an even better job of removing interference by increasing the sample rate, and then filter digitally as well.

#### BobTPH

Joined Jun 5, 2013
8,688
I beg to differ with my esteemed colleagues. For random noise, averaging will improve the readings. Aliasing should only be a problem if there is a repetitive signal above half the sampling rate. It all depends on what noise he is picking up.

#### Papabravo

Joined Feb 24, 2006
21,029
I beg to differ with my esteemed colleagues. For random noise, averaging will improve the readings. Aliasing should only be a problem if there is a repetitive signal above half the sampling rate. It all depends on what noise he is picking up.
That is the key insight with regard to anti-aliasing filters. Limit the bandwidth of BOTH the signal and the noise.

#### drjohsmith

Joined Dec 13, 2021
850
If I sample a thermocouple at a slow rate such as 1 Hz, do I need Low Pass Filters? I'm not aware of any noise sources that are that low in frequency, and since I'm sampling so slowly, does this by default eliminate noise contributions in the high frequency ranges?
What are you using to sample the thermo couple
How much noise is there on the measurement ?
If its an off the shelf thermo coupler system, then you dont need to add extra filtering,

Regarding aliasing filter,
that implies you have great insight to sampling theroy, well done,

Yes in general,
if your sampling at F hz, and you want to look at base band signals , then you need a filter that ges rid of all signlas above F/2 Hz to better than your sampling systems sensitivity.

That assumes a few things
an instantaneous sample for one,

ADC's at this low a rate, tend to average over a fair period, thus "integrating out" any high frequency noise
Also the thermocouple is a fairly low noise system,
and not that many bits of an adc is needed,
so the effect of "random" noise at higher frequencies is nominally negligible.
The biggest source of noise, is normally the 50 / 60 Hz mains pick up
thus its "normal" to have a filter of some kind to attenuate those frequencies,

As mentioned above,
a cheap ADC , can easily sample at many hundreds of KHz,
thus a system with a relatively easy say 2 KHz filter, can be used,
sampling at say 10 KHz
and then digitally filter out the 50 / 60 Hz noise,
good luck

#### MrChips

Joined Oct 2, 2009
30,520
Digital average does not remove the high frequency noise.
Any signal above the Nyquist limit gets folded down below fs/2.
You must use antialiasing filter if you cannot guarantee that the signal is already band-limited.

#### crutschow

Joined Mar 14, 2008
34,078
For random noise, averaging will improve the readings.
True.
But to do that averaging for a given bandwidth signal, you need to sample at above the Nyquist frequency, which means the noise aliasing is occurring at a higher frequency.
So it really depends upon how high above the Nyquist frequency you can sample.

#### ag-123

Joined Apr 28, 2017
276
imho, strictly speaking even if we'd place an RC filter before the ADC, it'd basically *improve* things
https://en.wikipedia.org/wiki/RC_circuit#Gain_and_phase
the gain fall off after the -3db cutoff is normally by decades i.e. 100hz, 1khz, 10khz, 100khz, 1mhz?
I'd guess in the case of measuring temperatures which is pretty much DC, the purpose is that the "noise" that is *much higher* frequencies than DC (e.g. RFI radio frequency interference, they can be pretty low like in the khz region, I'd guess this is due to beats when signals mix) would be filtered off by a typical RC filter (those are many decades higher than DC and hence with an RC filter, the gain at those frequencies is pretty much zero).

In this case, actually I'd think a different way to do so digitally is to use a moving median filter. i.e. anything too far off a median is discarded. I'd think this works, but that it is so computation and memory intensive (MCUs typically has kbytes or even just bytes). If there are other processes, this would be too slow and too cpu / memory intensive to be implemented.
Averaging would help 'a little', as it'd basically recover that DC signal which is the temperature sensor signal.
There would still be errors, but that assuming that the noise is gaussian centred around the temperature sensor voltage, then it'd just reduce that mean error vs some arbitrary reading I'd guess.

But I'd guess the more appropriate way is just to have that RC filter, low cost, easy, effective, especially for RF noise vs DC.
100s of 1000s of 3d printers is printing in our world polluted with RF noise with that RC filter setup with a 10 uF ! capacitor.
https://reprap.org/mediawiki/images/f/f6/RAMPS1.4schematic.png
It works well as it would otherwise likely need costly shielding etc. the thermistor cord is long and normally unshielded, making it a perfect RF antenna.
The trouble with using such large 10 uF filters is the response is typically slow, and you can see temperatures oscillate in a wavy pattern as the hotend is slightly overheated and cooled down.

Last edited:

#### crutschow

Joined Mar 14, 2008
34,078
Since it's usually easy to place a simple, 1-pole, RC low-pass (aniti-alias) filter in front of the A/D input, there's generally no reason not to.

#### MrChips

Joined Oct 2, 2009
30,520
Here is a numerical example.

Suppose your signal is varying at 0.2Hz.
Suppose your sampling frequency is 1Hz.
Suppose your noise frequency is 1000.1Hz.

The noise will reappear at 0.1Hz and will still appear within your signal bandwidth.

#### BobTPH

Joined Jun 5, 2013
8,688
I specifically stated RANDOM noise. Random noise does not have frequency, every frequency is included. When you alias that, the noise is still random.

Here is an article about noise reduction by averaging, right on the very site.

I looked at several different articles on this and not one mentions any need for an anti-aliasing filter.

If the noise is not random, then you are right, as the article says, averaging will not reduce a 60Hz line frequency noise.

#### Papabravo

Joined Feb 24, 2006
21,029
I specifically stated RANDOM noise. Random noise does not have frequency, every frequency is included. When you alias that, the noise is still random.

Here is an article about noise reduction by averaging, right on the very site.

I looked at several different articles on this and not one mentions any need for an anti-aliasing filter.

If the noise is not random, then you are right, as the article says, averaging will not reduce a 60Hz line frequency noise.
Strictly speaking white noise, which includes every frequency, is an idealization which does not exist in practice. As a matter of practical reality, we use noise with a sufficiently high bandwidth as an approximation to actual white noise. Noise with a bandwidth higher than half the sampling frequency will be detected and processed by the digital sampling as if it were in band noise. That is what the analog filter can and will eliminate.

That they don't mention anti-aliasing it is hardly a surprise considering how many are ignorant of the phenomenon and blissfully ignore the effects. There is very little any of us can do to counteract that behavior.

#### crutschow

Joined Mar 14, 2008
34,078
I looked at several different articles on this and not one mentions any need for an anti-aliasing filter.
It's not mentioned likely because it assumes there is one already in place, as most sampled-data systems have.

Random noise has all frequency components, as you noted, so any components above Nyquist are aliased into the passband.
So the aliased noise is still random but it's not benign.
It adds to the passband noise (by the square-root of the sum of their squares).
You want an anti-alias filter do minimize that high frequency aliased noise.

You can average after that, if you like, to further reduce the in-band noise.

Last edited: