org.apache.commons.math3.fitting

## Class HarmonicFitter

- java.lang.Object
- - org.apache.commons.math3.fitting.CurveFitter<HarmonicOscillator.Parametric>
  - - org.apache.commons.math3.fitting.HarmonicFitter

    public class HarmonicFitter
    extends CurveFitter<HarmonicOscillator.Parametric>

Class that implements a curve fitting specialized for sinusoids. Harmonic fitting is a very simple case of curve fitting. The estimated coefficients are the amplitude a, the pulsation ω and the phase φ: `f (t) = a cos (ω t + φ)`. They are searched by a least square estimator initialized with a rough guess based on integrals.

Since:
  2.0
Version:
  $Id: HarmonicFitter.java 1416643 2012-12-03 19:37:14Z tn $

### Nested Class Summary

Nested Classes
`static class` `HarmonicFitter.ParameterGuesser` This class guesses harmonic coefficients from a sample.

### Constructor Summary

Constructors
Constructor and Description
`HarmonicFitter(MultivariateVectorOptimizer optimizer)` Simple constructor.

### Method Summary

Methods
`double[]` `fit()` Fit an harmonic function to the observed points.
`double[]` `fit(double[] initialGuess)` Fit an harmonic function to the observed points.

### Methods inherited from class org.apache.commons.math3.fitting.CurveFitter

`addObservedPoint, addObservedPoint, addObservedPoint, clearObservations, fit, fit, getObservations`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### HarmonicFitter

    public HarmonicFitter(MultivariateVectorOptimizer optimizer)

Simple constructor.

Parameters:
  `optimizer` - Optimizer to use for the fitting.

### Method Detail

#### fit

    public double[] fit(double[] initialGuess)

Fit an harmonic function to the observed points.

Parameters:
  `initialGuess` - First guess values in the following order:
  - Amplitude
  - Angular frequency
  - Phase
Returns:
  the parameters of the harmonic function that best fits the observed points (in the same order as above).

#### fit

    public double[] fit()

Fit an harmonic function to the observed points. An initial guess will be automatically computed.

Returns:
  the parameters of the harmonic function that best fits the observed points (see the other `fit` method.
Throws:
  `NumberIsTooSmallException` - if the sample is too short for the the first guess to be computed.
  `ZeroException` - if the first guess cannot be computed because the abscissa range is zero.