• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by Kiloblargh · Jun 09, 2012 at 04:40 PM · mathsmoothaccelerationinterpolationjagged

Help me out with a simple smoothing function for accelerometer data?

I am saving the last 30 data from Input.accelerationEvents in a List to catch tilt gestures.

One problem I'm getting is that the raw data often has "stairsteps". two or three samples that are the same or almost the same, followed by a jump to two or three higher or lower values that are almost the same, in the middle of an otherwise smooth slope. for example:

 ... 1.35, 1.40,  1.51,  1.51, 1.67, 1.67, 1.73, 1.81, 1.89, ...

In this case, I'd want to bump the second 1.51 upward a bit and the 1.67 down a bit to give me a sequence more like

 ... 1.35, 1.40, 1.51, 1.56, 1.61, 1.67, 1.73, 1.81, 1.89, ...

which would be a lot more useful if I'm looking for directional trends - after smoothing that's an upward trend of 9, instead of three upward trends of 3, 2, and 3.

So I asked Wikipedia and I am now baffled and overwhelmed by the amount and complexity of all the different kinds of smoothing functions there are.

Maybe 'smoothing' isn't even really what I want to do, because something like this coming from the accelerometer:

 ... 0.23, 0.25, 0.87,  0.48, 0,41, ...

is significant- I don't want to flatten any spikes, just cut the corners off all the stairsteps.

Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by whydoidoit · Jun 09, 2012 at 04:57 PM

Not sure what language you are using but you could use Distinct from Linq to get only the unique values without the stairsteps:

    using System.Linq;

   ....

    public List<float> myInputs = new List<float>();

   ...

   var inputsToUser = myInputs.Distinct(); //Returns a list of the unique values
Comment

People who like this

0 Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kiloblargh · Jun 09, 2012 at 05:48 PM 0
Share

Removing all the duplicates was my first thought- but it doesn't really work for two reasons- first, the jaggies are usually not exactly the same value; just very close. Second, discarding values would shorten the list for one axis more than the others in an unpredictable way which would mess up slopes and relative timings and not let me loop through all 3 at once without getting ArrayIndexOutOfBounds exceptions.

avatar image whydoidoit · Jun 09, 2012 at 06:05 PM 0
Share

Sure I see your point - but also most smoothing functions are going to bias towards the values that are repeated I guess. You could effectively draw a spline between the points and/or normalize the points as if they were a curve and interpolate through them therefore removing the problem of there being an unequal number.

Not sure how you are consuming this data? Have you tried a simple smooth using 2/3 the value 1/6 the value before and 1/6 the value after for instance? A lot of this will depend on how it actually feels rather than some correct formula. I guess the period of smoothing will depend on the data you are seeing - so perhaps you should smooth over a longer period?

You could also take the values and clamp to the interquartile range or maybe the 5th to the 95th percentiles for more accuracy (sort the data, take the 5% and 95% of sample values). I guess I can't really work out if you need to remove outliers or just smooth the curve.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How can I stretch an array of points, interpolating the values. 1 Answer

Accelerating an object for a brief time then back to normal speed 1 Answer

How to correctly get jaggy free pixel textures in 3D game? 3 Answers

Smooth transition for GetAxis, when pressing opposite direction 1 Answer

Linearization of Android Acceleration Input 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges