Javascript Low-pass filter

720 Views Asked by At

How to properly apply a low pass filter in javascript? I'm not sure if my doing is correct or not. And I can't find a good example in javascript language

I tried using this but it returns NaN

 // Use a basic low-pass filter to keep only the gravity component of each axis.
 var grav_accelX = (acceleration.x * kFilteringFactor) + ( grav_accelX * (1.0 - kFilteringFactor));
 var grav_accelY = (acceleration.y * kFilteringFactor) + ( grav_accelY * (1.0 - kFilteringFactor));
 var grav_accelZ = (acceleration.z * kFilteringFactor) + ( grav_accelZ * (1.0 - kFilteringFactor));

So what I did is like this. It gives value but I'm not sure if this is the proper way.

const kFilteringFactor = 0.9
var accelX = x * kFilteringFactor
var accelY = y * kFilteringFactor
var accelZ = z * kFilteringFactor

accelX = accelX * (1.0 - kFilteringFactor)
accelY = accelY * (1.0 - kFilteringFactor)
accelZ = accelZ * (1.0 - kFilteringFactor)

The inline grav_accelX variable seems like not working here's the example

0

There are 0 best solutions below