how to find out the scaling factors to match two curves in matlab?

末鹿安然 提交于 2019-12-01 12:05:37

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)

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!