Change smoothing by moving your mouse

Low Pass Filter

A low-pass filter passes signals with a frequency lower than a certain cutoff frequency and attenuates signals with frequencies higher than the cutoff frequency. In this case only the y coordinate is passed through the LPF to be adjusted.


function lpf( points, smoothing )
{
    var result = [];

    var p;

    for( var i = 0; i < points.length; ++i )
    {
        p = points[ i ];

        result.push( { x: p.x, y: p.y } );
    }

    p = result[ 0 ];

    for( var j = 1; j < result.length; ++j )
    {
        var current = result[ j ];

        //smoothed value += ( new value - smoothed value) / smoothing;

        p.y += (current.y - p.y) * smoothing;

        current.y = Math.round( p.y );
    }

    return result;
}