How do I fit two data sets to each other?
8 views (last 30 days)
Show older comments
Hey everyone
I have a problem regarding an experiment data.
I have two data sets, one is reference and the other one is a measurement.
The data set from the measurement has a shift in x, every measurement a different shift.
To say it clearly I want to fit a measurement data set f(x+c) to a reference data set denoted f(x) and at each measurement to discover the variable 'c'. note: the data set is not a function but a pair {Y(i),X(i)} for both the reference and the measurement.
more small details:
The reference will be a high resolution measurement (small spacing, lots of points) and the measurement will have a higher spacing between points and a smaller amount of points.
The range of the x axis of the measurement and the reference might be different a bit.
Thanks for your help
1 Comment
dpb
on 22 May 2023
Clear as mud... :)
I think for anybody to have any chance at all of doing anything specific to the problem would take having the data to look at to see what it is are looking at. Attach a mat file containing at least a representative sample of both...with some more context of what it is that x represents and from whence is it to be obtained? Your posting only mentions having the y, but not the x.
Answers (2)
John D'Errico
on 23 May 2023
Edited: John D'Errico
on 23 May 2023
This is a classic problem of calibration. You have two curves, one of which must be shifted (translated) to the other. In some cases, there is also a scale factor in x. And of course, sometimes there is a y shift or scale too.
It sounds like all you have indicated is a translation in x.
In any case, the problem is nonlinear. You will need to choose a simple model for the reference curve. My suggestion is a spline. Make sure the fit is a monotonic one. If necessary, you may need to smooth the reference curve, forcing it to be monotonic. For this purpose the best tool may be something like my SLM toolbox, (found on the file exchange for free download. I'll post a link.)
You may also want to insure the reference curve covers a wide domain. You may need to extrapolate it. And again, monotonicity will probably be important. Since you don't show any data, I'll make something up.
xref = linspace(-20,20,100);
F = @(x) atan(x)/pi + 1/2;
yref = F(xref)
plot(xref,yref,'b.')
It is a nice smooth and strictly monotonic curve. That is good here, so I will just use an interpolating spline.
refspl = spline(xref,yref);
Now, suppose I have a second curve, shifted from the first along the x axis.
xs = sort(rand(20,1)*20 - 10);
shift = randn(1)*5;
ys = F(xs + shift);
I have no idea what the shift is here in advance. Can I recover it, and shift the new curve onto the target? Assume I don't know the functional form itself of F, only the points on the reference curve. Even worse, the new curve is not even equally spaced.
hold on
plot(xs,ys,'ro')
hold off
grid on
Since the curve is monotonic, I'll use a tool from my SLM toolbox, slmsolve.
xest = zeros(size(xs));
for i = 1:numel(ys);
xest(i) = slmsolve(refspl,ys(i)); % slmsolve is not vectorized, oh well
end
Here is my estimate of the shift, along with the true shift
shiftest = median(xest - xs);
[shiftest, shift]
plot(xref,yref,'b.',xs,ys,'ro',xs + shiftest,ys,'ms')
legend('Reference curve','New curve','After translation')
Of course, there is no noise in this system, so the estimate should be almost perfect.
If the problem is more complicated, where there is also a scale change, or a linear shift or scale in y, with some effort, that too could be solved.
And if there is noise in the problem, where the reference curve needs to be smoothed, the SLM toolbox can help with that too.
See Also
Categories
Find more on Descriptive Statistics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!