- Home /
Low pass filter on iphone accelerometer.
Hello guys, I have to filter out my iPhone,s noisy values which i get from the accelerometer. so i got a sample code from unity,s website.
var AccelerometerUpdateInterval : float = 1.0 / 60.0;
var LowPassKernelWidthInSeconds : float = 1.0;
private var LowPassFilterFactor : float = AccelerometerUpdateInterval / LowPassKernelWidthInSeconds; // tweakable
private var lowPassValue : Vector3 = Vector3.zero;
function Start () {
lowPassValue = Input.acceleration;
}
function LowPassFilterAccelerometer() : Vector3 {
lowPassValue = Mathf.Lerp(lowPassValue, Input.acceleration, LowPassFilterFactor);
return lowPassValue;
}
here i get an error on Mathf.Lerp function. it says Mathf.Lerp takes the parameters (float, float, float). so what else should i use instead of this ?
any help will be appreciative.
Answer by CHPedersen · Jun 20, 2011 at 06:38 AM
The variables lowPassValue and Input.acceleration are both of type Vector3. You're passing Vector3, Vector3, float to a function that takes float, float, float. That's why it's failing.
If my hunch is correct, it looks like you're using the code that's also available in this forum thread:
http://forum.unity3d.com/threads/15029-Iphone-Shaking
Notice that the lerp function used is Vector3.Lerp, used to linearly interpolate between two vectors. You're using Mathf.Lerp, which interpolates between floating point numbers.
I haven't followed the specifics of the math involved in the creation of a lowpass filter, so my reply is concerned with the syntactic correctness of your code, not the semantic. This means that if you're following the example I think you are then yes, you need to use Vector3.Lerp. I guarantee that doing so will fix your compile-time error, but I don't guarantee it will make your solution mathematically correct. ;-)
Answer by codejoy · Jan 23, 2014 at 07:57 AM
I just posted a topic on this, it seems like the docs have a typo in it?
Your answer