When you are designing a system that has a sensor that must be sampled, eliminating noise from the readings should be one of your concerns. Averages and other low-pass filters do a good job at smoothing the signal which reduces the amount of white noise, but if the sample rate of your system is a harmonic of the noise’s frequency a different approach is needed.
First, we need to understand what is going on in the system that is causing us to change our sampling behavior. The picture below shows a normal sensor signal that has been injected with a single-frequency noise signal. The sampling rate occurs at a harmonic frequency to the noise and so the samples are not occurring at random locations on the noise – they are following a harmonic sine wave.
If each sample is processed individually, the system will have to filter out the sine wave which could slow the response time. If multiple samples are added together or averaged, the resulting stream of samples will look like they have a large increase in the amount of white noise. This will have to be filtered out which will decrease the sensitivity of the sensor.
The solution to this problem is to slightly jitter the sampling rate of your system. Instead of sampling every X ms, sample every X+Y ms, where Y is a random value that is much smaller than X. For example, if your system is sampling once every 10 ms, then the sampling rate may be jittered by +/- 25 µs. (TIP: To create a simple, pseudorandom number, you can take the least significant bits from the previous sample and add them to the sampling rate timer. It’s not perfectly random, but it should be random enough.)
The result of this technique will be that your system will sample with the behavior shown in the picture below. Notice how the samples are still following the sample rate, but now they are more randomly distributed throughout the injected noise signal. Now if the system processes one sample at a time, it will see a small amount of increase white noise which will be solved with a simple averaging filter. If the system takes several samples and combines them before processing them, the white noise should naturally eliminate itself and the samples will hover around the normal sensor signal.