public static class HarmonicCurveFitter.ParameterGuesser extends Object
The algorithm used to guess the coefficients is as follows:
We know f(t)f(t) at some sampling points titi and want to find aa, ωω and ϕϕ such that f(t)=acos(ωt+ϕ)f(t)=acos(ωt+ϕ).
From the analytical expression, we can compute two primitives : If2(t)=∫f2dt=a2(t+S(t))/2If2(t)=∫f2dt=a2(t+S(t))/2 If′2(t)=∫f′2dt=a2ω2(t−S(t))/2 where S(t)=sin(2(ωt+ϕ))2ω
We can remove S between these expressions : If′2(t)=a2ω2t−ω2If2(t)
The preceding expression shows that If′2(t) is a linear combination of both t and If2(t): If′2(t)=At+BIf2(t)
From the primitive, we can deduce the same form for definite integrals between t1 and ti for each ti : If2(ti)−If2(t1)=A(ti−t1)+B(If2(ti)−If2(t1))
We can find the coefficients A and B that best fit the sample to this linear expression by computing the definite integrals for each sample points.
For a bilinear expression z(xi,yi)=Axi+Byi, the coefficients A and B that minimize a least-squares criterion ∑(zi−z(xi,yi))2 are given by these expressions:
A=∑yiyi∑xizi−∑xiyi∑yizi∑xixi∑yiyi−∑xiyi∑xiyi B=∑xixi∑yizi−∑xiyi∑xizi∑xixi∑yiyi−∑xiyi∑xiyiIn fact, we can assume that both a and ω are positive and compute them directly, knowing that A=a2ω2 and that B=−ω2. The complete algorithm is therefore:
For each ti from t1 to tn−1, compute: f(ti) f′(ti)=f(ti+1)−f(ti−1)ti+1−ti−1 xi=ti−t1 yi=∫tit1f2(t)dt zi=∫tit1f′2(t)dt and update the sums: ∑xixi,∑yiyi,∑xiyi,∑xizi,∑yizi Then: a=√∑yiyi∑xizi−∑xiyi∑yizi∑xiyi∑xizi−∑xixi∑yizi ω=√∑xiyi∑xizi−∑xixi∑yizi∑xixi∑yiyi−∑xiyi∑xiyiOnce we know ω we can compute: fc=ωf(t)cos(ωt)−f′(t)sin(ωt) fs=ωf(t)sin(ωt)+f′(t)cos(ωt)
It appears that fc=aωcos(ϕ) and fs=−aωsin(ϕ), so we can use these expressions to compute ϕ. The best estimate over the sample is given by averaging these expressions.
Since integrals and means are involved in the preceding estimations, these operations run in O(n) time, where n is the number of measurements.
Constructor and Description |
---|
ParameterGuesser(Collection<WeightedObservedPoint> observations)
Simple constructor.
|
public ParameterGuesser(Collection<WeightedObservedPoint> observations)
observations
- Sampled observations.MathIllegalArgumentException
- if the sample is too short.MathIllegalArgumentException
- if the abscissa range is zero.MathIllegalStateException
- when the guessing procedure cannot
produce sensible results.Copyright © 2016-2021 CS GROUP. All rights reserved.