How to implement low pass filter using java

chai picture chai · Oct 26, 2010 · Viewed 49.5k times · Source

I am trying to implement a low pass filter in Java. My requirement is very simple,I have to eliminate signals beyond a particular frequency (Single dimension). Looks like Butterworth filter would suit my need.

Now the important thing is that CPU time should be as low as possible. There would be close to a million sample the filter would have to process and our users don't like waiting too long. Are there any readymade implementation of Butterworth filters which has optimal algorithms for filtering.

Answer

Phrogz picture Phrogz · Sep 23, 2011

I have a page describing a very simple, very low-CPU low-pass filter that is also able to be framerate-independent. I use it for smoothing out user input and also for graphing frame rates often.

http://phrogz.net/js/framerate-independent-low-pass-filter.html

In short, in your update loop:

// If you have a fixed frame rate
smoothedValue += (newValue - smoothedValue) / smoothing

// If you have a varying frame rate
smoothedValue += timeSinceLastUpdate * (newValue - smoothedValue) / smoothing

A smoothing value of 1 causes no smoothing to occur, while higher values increasingly smooth out the result.

The page has a couple of functions written in JavaScript, but the formula is language agnostic.