如何找出matlab中匹配两条曲线的比例因子?
我有两个在不同日期获得的数据集。我从两个不同数据集得到的结果具有相似的形状但不同的值(见图 1)。我试图通过将 x 中的常数 A 和 y 中的 B 相乘来将第二个数据集 (x2,y2) 与第一个数据集 (x1,y1) 相匹配第二个数据(见图 2)。
例如:
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 ]';
要找出比例因子A & B,我正在考虑通过最小化data1和x修改的data2之间的delta y来获得B。不过我确实有一个很好的方法来找出 A。我应该如何找出 A 和 A ? B 来匹配这两条曲线?非常感谢任何帮助。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您有优化工具箱(或可以访问任何无约束非线性最小化例程),则可以执行以下操作:
定义一个计算两条曲线之间误差的函数
使用
fminunc
(或您使用的任何优化器)有可用的)来计算你的系数: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
Use
fminunc
(or whatever optimizer you have available) to compute your coeffiecients:要确定 A,您需要进行互相关,但您需要测试一系列 x 乘数,而不是测试一系列时滞,即 A价值观。
假设您要测试一系列 A 值,通过将每条曲线中对应于相同 x 值的点相乘,在两条曲线 (x1, y1) 和 (A*x2, B*y2) 之间建立相关性将这些产品相加。这将为您提供一个代表特定 A 值的相关性的数字。
对每个潜在的 A 值重复上述操作。给出最大相关结果的是在 x 维度上与两条曲线最匹配的 A 值。
此方法要求您测试的 A 值提供与原始 x 值同步的新 x 值,以便两条曲线具有相同的 x 值。
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.