# ADC sampling frequency - Noise filtering

I have to take the reading of two analog sensors temperature & Fuel level. Both of them are analog signal & i have to remove noise from this reading. And i want to use the Digital filter for these. My MCU is running at 32 MHZ, also i am taking reading of ADC for both the sensors every 5 msec.

Now i want to reduce Noise from my sample by using external analog filter & software digital fileter (IIR & FIR).

This link says we should follow Nyquist criteria for sampling to avoid alising problem. https://en.wikipedia.org/wiki/Analog-to-digital_converter

Now to design a Digital IIR filter, this link use to state about using cutoff frequency. https://stratifylabs.co/embedded%20design%20tips/2013/10/04/Tips-An-Easy-to-Use-Digital-Filter/

Now if i am right then Nyquist criteria & aliasing & setting sampling frequency is important for analog signals recording, where we are aware that human voice is < 20,000 HZ.

But how to set these criteria of (Analog or Digital filter cutoff frequency & sampling rate & nyquist criteria) for sensor signal like temperature & Fuel where we get simply the analog signals & we are not aware what frequency is for these signals.

• If you take a measurement every 5ms, you have a sampling frequency of 200Hz. This is the frequency you should use to determine the analog filter cutoff frequency. Sep 19, 2016 at 11:23
• You are aware of the frequency for these signals - temperature and fuel level both (should) change very slowly. I take 20 Hz cutoff filters as a rule of thumb for such signals. If you wish, you can measure your signal bandwidth by acquiring with a higher cutoff analog filter and FFT-ing the samples. Sep 19, 2016 at 11:25
• @Arsenal Your frequency calculation is 1/time_5msec, but Exact time should be 5msec+ADC conversion time+Software processing delay right ? Sep 19, 2016 at 11:27
• Similarly, your digital filter cut-off depends on how many samples you chose to filter. Actually, you started at the wrong end. What is the information rate which is of interest, and how much do you need to over-sample this to achieve the SNR which you desire? Sep 19, 2016 at 11:27
• @user6363 no, if you sample at 5ms, you sample at 5ms. The conversion timing is just an offset of the exact time when the sample is taken but has no influence on the frequency. If your software is so slow and cannot process your samples in 5ms, you probably don't sample at 5ms. Sep 19, 2016 at 11:31

You have a sampling rate of 200 Hz (1/5 ms). But you have not stated the needed response time for the output from the filter. To find the answer to that you should ask yourself how slow can the response be before it gives you a problem. Ie. if this is the fuel level and temperature of a car, then one minute is plenty good response time. But if this is some internal measurement of a fuel chamber for a mini turbine engine, then even a second delay might give you trouble. It's not possible for me to determine. (Ok the turbine is a far fetched and nearly useless example, could not think of any better examples where a delay time in the region of one second could cause problems).

You should filter the analog signal with a low-pass filter with a cut-off frequency (-3 dB frequency) of less than the Nyquist frequency. Same with the cut-off frequency in the digital filter. I would keep the cut-off frequency of the analog filtering as close to the Nyquist frequency as possible. That way you are free to alter the filter characteristics as you please by only altering the digital filter.

The other design criteria fro the analog filter is the sampling depth (in bits) of the ADC. The damping of the signals above the Nyquist frequency should be more than the S/N ratio of the ADC. Ie. 8 bit ADC, roughly 7 bit S/N -> more than 42 dB damping at the Nyquist frequency to avoid aliasing.

200 Hz sampling rate -> Nyquist freq = 100 Hz. Analog low pass cut off frequency < 100 Hz. Assuming 8 bit as in my example above: Damping at 100 Hz >42 dB

Suggested analog filter: 2. order filter (40 dB/decade). Filter frequency < 8.8 Hz.

And for the digital filter, you can filter as much as you want as long as you keep the needed response time in mind.

• thanks ..Please clarify this point what do you mean here "And for the digital filter, you can filter as much as you want as long as you keep the needed response time in mind." You mean to say You can reduce the cutoff frequency in digital filter right ? What do you mean by "keeping needed response time in mind" ? please suggest. Sep 19, 2016 at 11:38
• As I wrote, there is probably a response time you need to take into consideration. If not, I would simply set the cut-off frequency for the digital filter at 1 Hz. I have no idea on what you are making and therefor I don't know if my suggestion is at all valid. If you tell us a bit more, we can most likely provide better answers. Sep 19, 2016 at 11:41
• Your analogue filter needs to be significantly lower in frequency than 3dB at the nyquist frequency if you want to avoid aliasing. Sep 19, 2016 at 11:41
• @Andyaka Yes, and to clerify that I included the exampl with a 2. order filter and 8 bit ADC. I hope the example helps in understanding the relationship between cut-off frequency, S/N ratio, Nyquist frequency and aliasing problems. Sep 19, 2016 at 11:46
• @user6363 Yes, the 1 Hz was taken out of thin air, but I think it will suit your needs. Do the sampling at 5ms intervals as you stated in the original question. And the rest of my example solution can be used. Also read up on the datasheet of the ADC to see if there are any example of anti-aliasing filters (other then my suggestion for a 2. order filter). Some ADCs have buildt in filters by design (Ie. Sigma-Delta converters). They might not need much filtering of the analog signal to avoid aliasing. Makes the analog design simpler. Sep 20, 2016 at 7:00

You can sample them 2 to 20 times per second and then calculate a moving average over a second. your response time will be about a second and there should be no noise if your electronics are even remotely reasonable.

Unless you have some interesting micro-turbine and want to measure accurate fuel consumption you are not likely to need very fast response from your filters or ADC if your sensors only respond at 1 to 10 Hz.

EDIT:
If you have or think you will have non random electrical noise much greater than 5 times the resolution that you actually need (not what can be calculated) you may gain benefit by adding analogue filtering. The cut-off frequency should be around half of your sampling frequency.

However any low pass filtering above your desired response frequency would be a benefit though the digital averaging filter is a low pass filter already that can eliminate a lot of random noise sources. if you have noise near some multiple of the sampling frequency then the aliased noise may cause a beat signal in the output that is not actually there, an analogue front end filter would minimise this risk.

• If i take 20 samples per second then this means, i am taking sample every 50 msec. So means save 20 samples in an circular array of 20 integers & then average them every 50 msec to get accurate value, right ? Sep 19, 2016 at 11:04
• But this averaging is same about using the FIR FIlter. Suppose if i have to take reading of 40 analog values (say from sensor or output of op-amp or potential divider) & if i use 20 samples of each sensor then it will consume 40*20*sizeof(int) memory to perform this operation, memory wastage. I want to use IIR filter for avoiding memory wastage. Now how to set the value of cut off frequency parameter ALPHA as per this link stratifylabs.co/embedded%20design%20tips/2013/10/04/… ???? Sep 19, 2016 at 11:17
• Again i have same question what should be cutoff frequency parameter set of these analog signals (coming from sensor or output of op-amp or potential divider) so that IIR filter work accurately ? please suggest Sep 19, 2016 at 11:18