Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7053743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:32:32+00:00 2026-05-28T03:32:32+00:00

I have an app that accepts integers at a variable rate every .25 to

  • 0

I have an app that accepts integers at a variable rate every .25 to 2 seconds.

I’d like to output the data in a smoothed format for 3, 5 or 7 seconds depending on user input.

If the data always came in at the same rate, let’s say every .25 seconds, then this would be easy. The variable rate is what confuses me.

Data might come in like this:
Time – Data
0.25 – 100
0.50 – 102
1.00 – 110
1.25 – 108
2.25 – 107
2.50 – 102
ect…

I’d like to display a 3 second rolling average every .25 seconds on my display.

The simplest form of doing this is to put each item into an array with a time stamp.

array.push([0.25, 100])  
array.push([0.50, 102])  
array.push([1.00, 110])  
array.push([1.25, 108])  

ect…

Then every .25 seconds I would read through the array, back to front, until I got to a time that was less than now() - rollingAverageTime. I would sum that and display it. I would then .Shift() the beginning of the array.

That seems not very efficient though. I was wondering if someone had a better way to do this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:32:33+00:00Added an answer on May 28, 2026 at 3:32 am

    Why don’t you save the timestamp of the starting value and then accumulate the values and the number of samples until you get a timestamp that is >= startingTime + rollingAverageTime and then divide the accumulator by the number of samples taken?

    EDIT:
    If you want to preserve the number of samples, you can do this way:

    Take the accumulator, and for each input value sum it and store the value and the timestamp in a shift register; at every cycle, you have to compare the latest sample’s timestamp with the oldest timestamp in the shift register plus the smoothing time; if it’s equal or more, subtract the oldest saved value from the accumulator, delete that entry from the shift register and output the accumulator, divided by the smoothing time. If you iterate you obtain a rolling average with (i think) the least amount of computation for each cycle:

    • a sum (to increment the accumulator)
    • a sum and a subtraction (to compare the timestamp)
    • a subtraction (from the accumulator)
    • a division (to calculate the average, done in a smart way can be a shift right)

    For a total of about 4 algebric sums and a division (or shift)

    EDIT:

    For taking into account the time from the last sample as a weighting factor, you can divide the value for the ratio between this time and the averaging time, and you obtain an already weighted average, without having to divide the accumulator.

    I added this part because it doesn’t add computational load, so you can implement quite easy if you want to.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UITextField in my app that accepts decimal amounts for prices (i.e.,
I have a WCF app that accepts requests to start a job. Each job
I have created a servlet that accepts an image from my android app.I am
I have a windows console app (that accepts parameters) and runs a process. I
I have a Ruby-on-Rails app that accepts a binary file upload, stores it as
I have a web app, that accepts parameters that then go on to create
I have an ASP.NET app that accepts users comments and them in a SQL
I have a Python-based app that can accept a few commands in a simple
have an app that finds your GPS location successfully, but I need to be
Have an app that has listings - think classified ads - and each listing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.