# How to reduce latency under mean filter for high noise?

We have a position sensor that under some conditions receives some high frequency noise. We can eliminate that very well with a simple mean filtering.

Unfortunately this causes too much lag when there is not any noise (at the beginning of the graph at s=90 to 95). Thus we have been experimenting with Savitzky-Golay filtering:

However, the results are not that great. The filtering under heavy noise is worse than mean filtering (Or the latency reduction is not that good). What else can we do?

Some more background:

• The problem is an online problem, so we cannot retrospectively analyze the data and for instance shift the mean by half a period.
• The 'regular' movement is performed by a human moving an object, the 'noise' is from a high frequency vibration.
• You mentioned "high frequency noise". Is it possible that you are affected by a well described interference? You can consider capturing a longer sequence of the background noise process (without changing position) and then doing an FFT on the result; if the frequency characteristics of the interference are consistent, then it is feasible you can design an optimized filter based on frequency domain parameters to minimize it. Commented Sep 12, 2018 at 11:15
• @Dan: This is the route we are likely to go down: Use FFT/DCT to detect the noise and switch filters based on that. The noise is not uniform enough for a general filter, I believe. Commented Sep 12, 2018 at 20:33
• Using that approach, what intelligence do you use to distinguish between noise and signal of interest? Commented Sep 12, 2018 at 20:47
• Our signal (human movement) is very low frequency, the noise (vibrations) has a high but unknown frequency. That's why mean filtering works great, but the delay in signal cannot be accepted. Commented Sep 12, 2018 at 20:50
• Yes filter delay is directly proportional to the roll-off factor of the frequency specifically; so best strategy with a fixed filter is as low as a cutoff as possible with the smallest roll-off you can get away with to suppress the higher frequency signal which would provide the minimum delay possible (and better than a simple moving average which is a very poor low pass filter) Commented Sep 12, 2018 at 20:54

Although this is an old entry and probably the author of the question has already solved the issue, I leave here my solution, just in case, it could help someone else.

As explained in the question, you need a kind of real-time "smoother" for the trajectory. You are going to have trade-offs: speed, latency, energy efficiency, etc.

I propose to use Alpha-Beta filters, Moving Average Filters or some kind of Adaptative Average filter. They should be faster, easy to implement and with less latency than Kalman filter or similar. I have made a couple of tests, trying to reproduce the type of data used in the question, and testing those filters with quick(and nasty) own implementations. The results are shown below in the next figures:

Cheers.

P.D. Probably, the vibration noise commented in the original question is not absolutely uncorrelated. The data I have generated is using random noise.

• The noise was uncorrelated in our case and yes we did use an adaptive mean filtering based on FFT to detect high frequency noise components. Commented Dec 1, 2020 at 19:49
• Thanks for sharing your solution @ChristopherOezbek. I already imagined that you found something because this was very old. :) Commented Dec 1, 2020 at 19:52

There are two possible methods that you can try.

• Polynomial approximation (Spline fitting)
• Total variation denoising

In polynomial approximation, you can try to fit polynomial approximation of the entire data vector. In total variation denoising, you can regulate the amount of sparsity seen in the first-order difference term using the regularization parameter $\lambda$. In other words, under heavy noise, the first order difference of the input data is sparse.

• @Matrox: These are both offline approaches once all the data is collected, right? Our particular problem is realtime/online in that we must calculate the next 'denoised' output directly after receiving the next input data point. Global optimizations are not available. Commented Sep 12, 2018 at 11:02
• You can use a sliding window and do batch-processing. In the first frame, wait until you get N samples, process the data, then when you get N+1 th sample, shift the window by 1. Commented Sep 12, 2018 at 14:39
• Sliding window causes a delay of commonly N / 2. We don't want that. Commented Sep 12, 2018 at 20:34
• Have you tried using fast implementations of total variation denosing (TVD). AFAIK, it takes roughly 3-4 milliseconds to run TVD on an input vector of length $N < 1000$. I generally use MATLAB. Commented Sep 12, 2018 at 20:52
• But it is an online / real-time problem: I receive a new input data point (let's say at x = 52.5 mm), I have to give an answer immediately (not after collecting 999 other data points) to the actual x = 52.9 mm that I should pass to the user/application. This is not a smoothing problem, it is a filtering one. Commented Sep 12, 2018 at 20:56

Saying that your signal is «really low frequency» while you need to have low delay/smearing in order to capture it seems like a contradiction.

If you can describe what (aspects of) the inputsignal that you need to preserve are, and what the noise is like, perhaps a better solution presents itself.

The easiest solution will be some kind of lowpass filter, and they come with a set of trade-offs.

-k

• I don't think that is really a contradiction: think about a human moving his hand up and down at a frequency of once every 4 seconds (low frequency). If I want to trace this in real-time I wouldn't want to use a filter that has such a long delay. Commented Dec 1, 2020 at 19:46
• Say that your signal really is «DC». How would delay affect it? Commented Dec 1, 2020 at 20:18
• EVen though it is batch processing, perhaps this nature article on eye movement filtering could have some useful clues? nature.com/articles/s41598-017-17983-x Commented Dec 2, 2020 at 10:23