Deprecated
As of 3.1 (to be removed in 4.0).
f (t) = a cos (ω t + φ). They are
searched by a least square estimator initialized with a rough guess
based on integrals.
| Modifier and Type | Class and Description |
|---|---|
| public static class | HarmonicFitter.
This class guesses harmonic coefficients from a sample. |
| Access | Constructor and Description |
|---|---|
| public | HarmonicFitter(final DifferentiableMultivariateVectorOptimizer
Optimizer to use for the fitting. optimizer)
Deprecated
as a consequence of
DifferentiableMultivariateVectorOptimizer being deprecated.
Simple constructor. |
| Modifier and Type | Method and Description |
|---|---|
| public double[] | Returns: the parameters of the harmonic function that best fits the observed points (in the same order as above).First guess values in the following order:
initialGuess)
Fit an harmonic function to the observed points. |
| public double[] |
| HarmonicFitter | back to summary |
|---|---|
| public HarmonicFitter(final DifferentiableMultivariateVectorOptimizer optimizer)
Deprecated as a consequence of Simple constructor.
| |
| fit | back to summary |
|---|---|
| public double[] fit(double[] initialGuess) Fit an harmonic function to the observed points.
| |
| fit | back to summary |
|---|---|
| public double[] fit() Fit an harmonic function to the observed points. An initial guess will be automatically computed.
| |
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) = a cos (ω t + φ).
From the analytical expression, we can compute two primitives :
If2 (t) = ∫ f2 = a2 × [t + S (t)] / 2
If'2 (t) = ∫ f'2 = a2 ω2 × [t - S (t)] / 2
where S (t) = sin (2 (ω t + φ)) / (2 ω)
We can remove S between these expressions :
If'2 (t) = a2 ω2 t - ω2 If2 (t)
The preceding expression shows that If'2 (t) is a linear combination of both t and If2 (t): If'2 (t) = A × t + B × If2 (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) = A × xi + B × yi, the coefficients A and B that minimize a least square criterion ∑ (zi - z (xi, yi))2 are given by these expressions:
∑yiyi ∑xizi - ∑xiyi ∑yizi
A = ------------------------
∑xixi ∑yiyi - ∑xiyi ∑xiyi
∑xixi ∑yizi - ∑xiyi ∑xizi
B = ------------------------
∑xixi ∑yiyi - ∑xiyi ∑xiyi
In fact, we can assume 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 = ∫ f2 from t1 to ti
zi = ∫ f'2 from t1 to ti
update the sums ∑xixi, ∑yiyi, ∑xiyi, ∑xizi and ∑yizi
end for
|--------------------------
\ | ∑yiyi ∑xizi - ∑xiyi ∑yizi
a = \ | ------------------------
\| ∑xiyi ∑xizi - ∑xixi ∑yizi
|--------------------------
\ | ∑xiyi ∑xizi - ∑xixi ∑yizi
ω = \ | ------------------------
\| ∑xixi ∑yiyi - ∑xiyi ∑xiyi
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.
| Modifier and Type | Field and Description |
|---|---|
| private final double | a
Amplitude. |
| private final double | omega
Angular frequency. |
| private final double | phi
Phase. |
| Access | Constructor and Description |
|---|---|
| public | ParameterGuesser(WeightedObservedPoint[]
Sampled observations. observations)
Deprecated
as a consequence of
WeightedObservedPoint being deprecated.
Simple constructor. |
| Modifier and Type | Method and Description |
|---|---|
| public double[] | Returns: the guessed parameters, in the following order:
Gets an estimation of the parameters. |
| private double[] | Returns: the guessed amplitude (at index 0) and circular frequency (at index 1).Observations, sorted w.r.t. abscissa. observations)
Deprecated
as a consequence of
WeightedObservedPoint being deprecated.
Estimate a first guess of the amplitude and angular frequency. |
| private double | Returns: the guessed phase.Observations, sorted w.r.t. abscissa. observations)
Deprecated
as a consequence of
WeightedObservedPoint being deprecated.
Estimate a first guess of the phase. |
| private WeightedObservedPoint[] | Returns: the input observations, sorted.Input observations. unsorted)
Deprecated
as a consequence of
WeightedObservedPoint being deprecated.
Sort the observations with respect to the abscissa. |
| a | back to summary |
|---|---|
| private final double a Amplitude. | |
| omega | back to summary |
|---|---|
| private final double omega Angular frequency. | |
| phi | back to summary |
|---|---|
| private final double phi Phase. | |
| ParameterGuesser | back to summary |
|---|---|
| public ParameterGuesser(WeightedObservedPoint[] observations)
Deprecated as a consequence of Simple constructor.
| |
| guess | back to summary |
|---|---|
| public double[] guess() Gets an estimation of the parameters.
| |
| guessAOmega | back to summary |
|---|---|
| private double[] guessAOmega(WeightedObservedPoint[] observations)
Deprecated as a consequence of Estimate a first guess of the amplitude and angular frequency.
This method assumes that the
| |
| guessPhi | back to summary |
|---|---|
| private double guessPhi(WeightedObservedPoint[] observations)
Deprecated as a consequence of Estimate a first guess of the phase.
| |
| sortObservations | back to summary |
|---|---|
| private WeightedObservedPoint[] sortObservations(WeightedObservedPoint[] unsorted)
Deprecated as a consequence of Sort the observations with respect to the abscissa.
| |