问题描述
我正在使用 Apache Commons Math 软件包,得到了以下正弦波...
I'm using the Apache Commons Math package and I've got the following Sine Wave...
0.90, 0.85, 0.80, 0.83, 0.89
0.90, 0.85, 0.80, 0.83, 0.89
0.90, 0.85, 0.80, 0.83, 0.89
0.90, 0.85, 0.80, 0.83, 0.89
从以上数据中,您可以看到wave具有以下属性...
from the above data you can see that the wave has the following attributes...
- 振幅=
.05
- 阶段=
0
- 频率=
5
- Amplitude =
.05
- Phase =
0
- Frequency =
5
但是,当我像这样将正弦波添加到HarmonicFitter
时...
However, when I add my sine wave to a HarmonicFitter
like so...
HarmonicFitter fitter = new HarmonicFitter(new LevenbergMarquardtOptimizer());
fitter.addObservedPoint(0, 0.90);
fitter.addObservedPoint(1, 0.85);
fitter.addObservedPoint(2, 0.80);
fitter.addObservedPoint(3, 0.83);
fitter.addObservedPoint(4, 0.89);
fitter.addObservedPoint(5, 0.90);
fitter.addObservedPoint(6, 0.85);
fitter.addObservedPoint(7, 0.80);
fitter.addObservedPoint(8, 0.83);
fitter.addObservedPoint(9, 0.89);
fitter.addObservedPoint(10, 0.90);
fitter.addObservedPoint(11, 0.85);
fitter.addObservedPoint(12, 0.80);
fitter.addObservedPoint(13, 0.83);
fitter.addObservedPoint(14, 0.89);
fitter.addObservedPoint(15, 0.90);
fitter.addObservedPoint(16, 0.85);
fitter.addObservedPoint(17, 0.80);
fitter.addObservedPoint(18, 0.83);
fitter.addObservedPoint(19, 0.89);
double[] vals = fitter.fit();
return vals;
返回的值更像是...
The values returned are more like...
Amplitude: 5.19813329138371
Frequency: 4.69209750375546E-5
Phase: 1.405312649084833
为什么曲线拟合会导致具有4个相同频率的正弦波具有如此巨大的不同属性?
Why has the curve fitting resulted in such drastically different attributes for a sinewave with 4 identical frequencies?
推荐答案
@Marko Topolnik有问题. Fitter
期望一个简单的谐波(即单个余弦或正弦),平均值为零.因此,从所有内容中减去0.854
(均值),然后将该常数加回到生成的正弦波中.
@Marko Topolnik has the problem. The Fitter
is expecting a simple harmonic (i.e., a single cosine or sine), which has mean zero. So subtract 0.854
(the mean) from everything, and add that constant back to your resulting sine wave.
实际上,微小的频率产生平坦的正弦波,因此其他数字无关紧要.尝试绘制所有内容(包括结果函数).
As things are, the tiny frequency is giving a flat sine wave, so the other numbers are irrelevant. Try plotting everything (including the resulting function).
编辑:这是两个图.第一个具有您的观点以及三个功能:所需的y=.05*cos(2πx/5)
,相同的功能加上.0854
(看来您的相位不会为零),以及包装的最佳配合功能: 但是,除非您缩小到[-1e5,1e5]x[-8,8]
窗口,否则您无法区分包的最佳拟合功能:这也意味着包装的最佳配合功能非常不稳定.点的微小变化将导致输出的巨大变化.
Here are two plots. The first has your points along with three functions: your desired y=.05*cos(2πx/5)
, the same function plus .0854
(it appears your phase won't be zero), and the package's best fit function: But you can't distinguish the package's best fit function until you zoom way out to a window of [-1e5,1e5]x[-8,8]
:This also means that the package's best fit function is wildly unstable. A small change in your points will cause a large change in the output.
这篇关于Java中的正弦波曲线拟合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!