问题
I have two data sets obtained at different days. The results I got from two different data sets have similar shape but different values (see fig1). I am trying to match the second data set (x2,y2) to the first one (x1,y1) by multiply a constant A in x and B in y of the second data (see fig2).


for example:
data1:
x1=[-0.3:0.06:2.1]';
y1=[ 0.001 0.001 0.004 0.014 0.052 0.166 0.330 0.416 0.340 0.247 0.194 0.197 0.237 0.330 0.428 0.542 0.669 0.767 0.855 0.900 0.913 0.904 0.873 0.811 0.765 0.694 0.631 0.585 0.514 0.449 0.398 0.351 0.309 0.273 0.233 0.211 0.182 0.154 0.137 0.117 0.101 ]';
data2
x2=[-0.3:0.06:2.1]';
y2=[0.000 0.000 0.000 0.000 0.025 0.230 0.447 0.425 0.269 0.194 0.225 0.326 0.477 0.636 0.791 0.931 1.036 1.104 1.117 1.123 1.062 0.980 0.897 0.780 0.675 0.571 0.471 0.390 0.309 0.258 0.209 0.161 0.129 0.099 0.079 0.063 0.047 0.038 0.027 0.023 0.015 ]';
To find out the scaling factor A & B, I am thinking about obtaining B by minimizing the delta y between data1 and x modified data2. However I do have a good way to find out the A. How should I find out the A & B to match this two curve? Any help is greatly appreciated.
回答1:
If you have the optimization toolbox (or access to any unconstrained non-linear minimization routine), you can do the following:
Define a function that computes the error between your two curves
function err = sqrError(coeffs, x1, y1, x2, y2)
% Interpolation of 'y2' with scaled 'x2' into the domain 'x1'
y2sampledInx1 = interp1(coeffs(1)*x2,y2,x1);
% Squred error calculation
err = sum((coeffs(2)*y2sampledInx1-y1).^2);
end
Use fminunc
(or whatever optimizer you have available) to compute your coeffiecients:
coeffs = fminunc(@(c) sqrError(c,x1, y1, x2, y2),[1;1]);
A = coeffs(1);
B = coeffs(2);
plot(x1, y1, A*x2, B*y2)
回答2:
To determine A you want to do a cross-correlation but instead of testing a range of time-lags, you'll want to test a range of x multipliers, i.e. A values.
Assuming you have a range of A values you want to test, do a correlation between the two curves (x1, y1) and (A*x2, B*y2) by multiplying the points in each curve that correspond to the same x values and sum these products. This will give you one number representing the correlation at the particular A value.
Repeat the above for each potential A value. The one that gives the maximum correlation result is the A value that best matches the two curves in the x dimension.
This method requires that the A values that you test give new x values that synchronize with the original x values so that both curves have values at the same x values.
来源:https://stackoverflow.com/questions/9119316/how-to-find-out-the-scaling-factors-to-match-two-curves-in-matlab