Class HarmonicCurveFitter.ParameterGuesser

java.lang.Object
org.hipparchus.fitting.HarmonicCurveFitter.ParameterGuesser
Enclosing class:
HarmonicCurveFitter

public static class HarmonicCurveFitter.ParameterGuesser extends Object
This class guesses harmonic coefficients from a sample.

The algorithm used to guess the coefficients is as follows:

We know f(t) at some sampling points ti and want to find a, ω and ϕ such that f(t)=acos(ωt+ϕ).

From the analytical expression, we can compute two primitives : If2(t)=f2dt=a2(t+S(t))/2 If2(t)=f2dt=a2ω2(tS(t))/2 where S(t)=sin(2(ωt+ϕ))2ω

We can remove S between these expressions : If2(t)=a2ω2tω2If2(t)

The preceding expression shows that If2(t) is a linear combination of both t and If2(t): If2(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(tit1)+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 (ziz(xi,yi))2 are given by these expressions:

A=yiyixizixiyiyizixixiyiyixiyixiyi B=xixiyizixiyixizixixiyiyixiyixiyi

In 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 tn1, compute: f(ti) f(ti)=f(ti+1)f(ti1)ti+1ti1 xi=tit1 yi=t1tif2(t)dt zi=t1tif2(t)dt and update the sums: xixi,yiyi,xiyi,xizi,yizi Then: a=yiyixizixiyiyizixiyixizixixiyizi ω=xiyixizixixiyizixixiyiyixiyixiyi

Once 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 Details

  • Method Details

    • guess

      public double[] guess()
      Gets an estimation of the parameters.
      Returns:
      the guessed parameters, in the following order:
      • Amplitude
      • Angular frequency
      • Phase