Skip to main content
3 of 8
added 179 characters in body
Izzo
  • 912
  • 8
  • 26

What is the method for calculating a "running" linear fit?

I'm currently working on a project in which I need to find the tilt of a surface. Let's assume I'm only concerned with a single dimension tilt (i.e. slope) to begin.

I currently have the ability to calculate a least-squared slope when processing batch data. However, this requires me to batch all the data prior to performing the calculation.

Is there a method to perform a "running linear fit" such that I'm not required to batch the data prior to performing the calculation?

I use the term running in the sense of a "running" average in which the the total average is calculated by de-weighting the current value against the previously calculated total average. This allows you to calculate the total average without buffering each value. Does a similar technique exist for calculating the slope?

I will outline my theory on how to do this but an unsure if it is valid:

Since I already know the method for calculating a running average, I would essentially transform this new problem into a simple running average problem. For each data point collected, I would calculate a slope referenced against the initial point collected. I would then use this calculated slope value and input it into a running average equation. Essentially I'm performing a running average equation on slope values (instead of raw sensor values).

I'm curious if anyone could comment on whether or not this would yield the same slope as what is calculated using the batched version problem? I'm thinking that it will offer a good slope estimate, however, I'm essentially basing every calculation off the initial sensor value which does not seem optimal. What if the initial sensor value was bad?

Edit: I performed my method on the same data set as featured in the web link and obtained a value of -1.541 which is different than the least squares slope of -1.1 ... Hmmm...

Izzo
  • 912
  • 8
  • 26