Best fit of deltas unequally spaced to reconstruct original curve

70 Views Asked by At

I have a collection of measurement deltas $m_1...m_n$ where each measurement consists of two points $(x_{n1},y_{n1})$ and $(x_{n2},y_{n2})$ the $x_{n1}$ and $x_{n2}$ represent where the measurement was taken, and in the case of my problem it's a distance that is known, and those values are measured at the same time, so I know the $\Delta y$ for the measurement, but between any two measurements $m_n$ and $m_{n+1}$ the measurement equipment is moving, so there is some $y$ offset between the measurements that is unknown which I will call $d_n$. so for a given measurement $m_n$ : $y_{n1} = d_n$ and $y_{n2} = \Delta y_n + d_n$ I am trying to find a best fit solution for all of the $d_1...d_n$, where I'm defaulting $d_1 = 0$, but every value offset after that $d_2...d_n$ will be calculated based on the surrounding measurements. The end goal is that all the points $(x_{n1},y_{n1}),(x_{n2},y_{n2})$ fall as close as possible to the original unknown function that was being measured. Each measurement $m_n$ overlaps with it's neighboring measurements, and may even overlap with the two previous and the two next such that $x_{(n-1)2} > x_{n1}$ and $x_{(n-1)2} < x_{n2}$ and $x_{(n+1)1} < x_{n2}$ and $x_{(n+1)1} > x_{n1}$. The distance between the points in a measurement $x_{n1}$ and $x_{n2}$ are approximately the same distance every time, but given how they are taken, it can vary slightly from one measurement to the next.

Below is a picture showing what is being measured. Let's say that the black line is the true shape of what is being measured, and the red lines are the measurements. The lines here are shown on top of the true shape of the line, but when the measurement is taken all we know is where it begins and ends (the $x$ values) and the $\Delta y$. What I am trying to do is take a lot of these red measurements where I know the $\Delta y$ between the $x$ values and reconstruct the original black line as best as possible.

enter image description here

These line segments overlap with each other, and I'm trying to shift the line segments up and down to find a sort of best fit for those line segments to reconstruct the original curve.

The problem I'm running into is that I can take one line segment and interpolate where $x_1$,$y_1$ of the next line should most likely fall, but every time I move a line segment up or down it affects the best fit of the lines adjacent to it, so I can't think of a way to calculate a best fit of all the line segments simultaneously because each line segment affects the positioning of the line segments ahead and behind it.

My first attempt at solving this problem was to loop through all the measurements $m_1...m_n$ and in my first forward pass I would interpolate the position of the next measurement offset $d_{n+1}$ using the measurement $m_n$ (as a side note, the starting position of $y$ doesn't really matter, so the first delta $d_1$ I'm assuming that the $y$ position starts at 0), and then I did a backward pass where I started at the end and I used the next measurement $m_{n+1}$ to interpolate the $d_n$ of the previous measurement $m_n$, and then I did a final smoothing pass where I would look at 3 measurements at a time ($m_{n-1},m_n,m_{n+1}$) and for the middle measurement $m_n$ I would look at what the offset $d_n$ should be if interpolated based on $m_{n+1}$, and what the offset $d_n$ should be if interpolated based on $m_{n-1}$ and I averaged the two and applied that offset $d_n$ to the middle measurement $m_n$ and then moved ahead with another three measurements where $m_n$ is now $m_{n-1}$

The results from this seem reasonable, but I know it's not the mathematically best fit and it's really just a good enough approximation, but I'm concerned that finding the absolute best fit would computationally take too long and get exponentially longer with the more measurements that are added.

Is doing a forward pass where the past measurements predict the future measurements and then a backward pass where the future measurements predict the past measurements and then trying to average between the two in a final pass about as good as I can get, or is there a better way to find the best fit of these measurements?