3
votes

What is the best way of finding the shift along the x-axis for the blue line in this image unshifted such that it matches the red line? The result has to look like this image shifted ). In MATLAB there are complex function like fminunc but I have to deal with some time constraints, so I'm wondering if there are more efficient ways.

Edit: The data is coming from range measurements of an laser scan in a simulated environment. On the x-axis you see the bearing of each scan in radians versus the range measured in meters on the y-axis. For the red points (the reference scan) the bearings are indeed evenly spaced out. This is always the case for the reference scan, but not for the current scan (the blue points).

Edit: data for the red points

-1.5708    6.8542
-1.3963    6.9530
-1.2217    7.2137
-1.0472    7.6592
-0.8727    8.3326
-0.6981    9.2984
-0.5236   10.6477
-0.3491   12.5060
-0.1745   15.0092
     0   18.2745
0.1745   22.3368
0.3491   27.1113
0.5236   32.4112
0.6981   38.0010

And for the blue points

-1.3963    7.0092
-1.2217    7.3112
-1.0472    7.8065
-0.8727    8.5420
-0.6981    9.5872
-0.5236   11.0407
-0.3491   13.0360
-0.1745   15.7225
     0   19.1849
0.1745   23.4301
0.3491   28.3466
0.5236   32.4114
2
Do you know what was the model of your data, for example, a*exp(bx), or a+bx+cx^2 ?Andrey Rubshtein
The x coordinates seem to be evenly spaced out. Is this guaranteed for all your datasets?mars
Do you want solutions that involve non-linear optimization as well?Andrey Rubshtein
Not a complete solution, but a thought: An offset in x introduces a factor exp(+- ikoffset) in fourier space, which makes the offset accessible with polyfit.mars

2 Answers

1
votes

OK, it's not the "best" way, but it's a way if you don't know the proper model that describes the curve:

% your first plot
figure(1), clf, hold on
plot(red(:,1), red(:,2), 'ro-')
plot(blue(:,1), blue(:,2), 'bo-')

% approximate reference with splines, so it can be evaluated anywhere
ppred = spline(red(:,1),red(:,2));

% minimize the distance between the curves
f = @(x) norm( ppval(ppred, blue(:,1)+x)-blue(:,2) );    
x0 = fminsearch(f, 0);    
blue(:,1) = blue(:,1)+x0;

% pretty close to your second plot
plot(blue(:,1), blue(:,2), 'ko-')
0
votes

Why not just do a grid search? Make a grid of offset possibilities, like delta_x = [0.0001:0.2:0.0001] and then just evaluate your objective function (least squares?) at every place in the offset grid, and choose the one with minimum error. If you are too short on time to use fminfunc then grid search might be an acceptable approximation.