Class DampedSinusoidFit

java.lang.Object
xal.extension.fit.DampedSinusoidFit

public final class DampedSinusoidFit extends Object
DampedSinusoid provides an exact closed form solution for fitting a waveform to a damped sinusoid of the form q = Aeγtsin(μt + φ) + C which is adapted for efficient fitting in the presence of noise. The fits for frequency, offset and growth rate are good in the presence of relatively small noise. However, the estimation of phase and amplitude are relatively poor in the presence of noise. Also, the estimation breaks down when the frequency is near an integer or half integer.
  • Constructor Details

    • DampedSinusoidFit

      public DampedSinusoidFit(double[] waveform, int count)
      Primary Constructor
      Parameters:
      waveform - data to fit
      count - starting from the beginning of the waveform, the number of items in the waveform to use in the fit
    • DampedSinusoidFit

      public DampedSinusoidFit(double[] waveform)
      Constructor accepting the entire waveform
      Parameters:
      waveform - data to fit
  • Method Details

    • getInstance

      public static DampedSinusoidFit getInstance(double[] waveform, int count)
      Get a new instance of the damped sinusoid
      Parameters:
      waveform - data to fit
      count - starting from the beginning of the waveform, the number of items in the waveform to use in the fit
    • getInstance

      public static DampedSinusoidFit getInstance(double[] waveform)
      Get a new instance of the damped sinusoid using the entire waveform
      Parameters:
      waveform - data to fit
    • solveWithNoise

      public void solveWithNoise(double noiseLevel)
      Run the solver to find the best fit
      Parameters:
      noiseLevel - estimate of the expected noise
    • solveWithNoiseMaxEvaluations

      public void solveWithNoiseMaxEvaluations(double noiseLevel, int maxEvaluations)
      Run the solver to find the best fit
      Parameters:
      noiseLevel - estimate of the expected noise
      maxEvaluations - the maximum number of evaluations to perform
    • solveWithNoiseMaxEvaluationsSatisfaction

      public void solveWithNoiseMaxEvaluationsSatisfaction(double noiseLevel, int maxEvaluations, double satisfaction)
      Run the solver to find the best fit
      Parameters:
      noiseLevel - estimate of the expected noise
      maxEvaluations - the maximum number of evaluations to perform
      satisfaction - the satisfaction target to reach before stopping
    • solveWithNoiseMaxTime

      public void solveWithNoiseMaxTime(double noiseLevel, double maxTime)
      Run the solver to find the best fit
      Parameters:
      noiseLevel - estimate of the expected noise
      maxTime - the maximum time to wait for the solution
    • solveWithNoiseMaxTimeSatisfaction

      public void solveWithNoiseMaxTimeSatisfaction(double noiseLevel, double maxTime, double satisfaction)
      Run the solver to find the best fit
      Parameters:
      noiseLevel - estimate of the expected noise
      maxTime - the maximum time to wait for the solution
      satisfaction - the satisfaction target to reach before stopping
    • solve

      public void solve(double noiseLevel, Stopper stopper)
      Run the solver to find the best fit
      Parameters:
      noiseLevel - the noise level used to estimate the error bounds and provide a measure for satisfaction
      stopper - the stopper which determines when to stop the solver
    • getInitialOffset

      public double getInitialOffset()
      get the fitted offset calculating it if necessary
    • getInitialOffsetVariance

      public double getInitialOffsetVariance()
      get the variance in the initial offset estimate using the initial estimate of the signal variance
    • getInitialSignalVariance

      public double getInitialSignalVariance()
      get the initial estimate of the signal variance
    • estimateInitialOffsetVariance

      public double estimateInitialOffsetVariance(double signalVariance)
      get an estimate of the initial offset's variance
    • getOffset

      public double getOffset()
      get the optimized offset
    • getSignalVariance

      public double getSignalVariance()
      get the optimized estimate of the signal variance
    • getInitialGrowthRate

      public double getInitialGrowthRate()
      get the fitted growth rate calculating it if necessary
    • getInitialGrowthRateVariance

      public double getInitialGrowthRateVariance()
      get the variance in the initial growth rate estimate using the initial estimate of the signal variance
    • estimateInitialGrowthRateVariance

      public double estimateInitialGrowthRateVariance(double signalVariance)
      get an estimate of the initial growth rate's variance
    • getInitialWaveformError

      public double[] getInitialWaveformError()
      get the initial waveform error calculating it if necessary
    • getInitialWaveformRMSError

      public double getInitialWaveformRMSError()
      get the initial RMS error
    • getGrowthRate

      public double getGrowthRate()
      get the optimized growth rate
    • getInitialFrequency

      public double getInitialFrequency()
      get the fitted frequency calculating it if necessary
    • getInitialFrequencyVariance

      public double getInitialFrequencyVariance()
      get the variance in the initial frequency estimate using the initial estimate of the signal variance
    • estimateInitialFrequencyVariance

      public double estimateInitialFrequencyVariance(double signalVariance)
      get an estimate of the initial frequency's variance
    • getFrequency

      public double getFrequency()
      get the optimized frequency
    • getInitialPhase

      public double getInitialPhase()
      Get the sine-like phase estimation calculating it if necessary. Note that this estimation is relatively poor.
    • getPhase

      public double getPhase()
      get the optimized phase
    • getSineLikePhase

      public double getSineLikePhase()
      Get the optimized sine-like phase.
    • getCosineLikePhase

      public double getCosineLikePhase()
      Get the optimized cosine-like phase (equivalent phase if the fitted equation were of the form of A * damping * cos( mu + phase ) ).
    • getWaveformError

      public double[] getWaveformError()
      get the waveform error
    • getWaveformRMSError

      public double getWaveformRMSError()
      get the initial RMS error
    • getInitialSineLikePhase

      public double getInitialSineLikePhase()
      Get the sine-like phase calculating it if necessary. Note that this estimation is relatively poor.
    • getInitialCosineLikePhase

      public double getInitialCosineLikePhase()
      Get the cosine-like phase calculating it if necessary. Note that this estimation is relatively poor.
    • getInitialAmplitude

      public double getInitialAmplitude()
      Get the sine-like amplitude calculating it if necessary. Note that this estimation is relatively poor.
    • getAmplitude

      public double getAmplitude()
      Get the optimized sine-like amplitude
    • getFittedWaveform

      public double[] getFittedWaveform(double[] positions)
      Convenience method to calculate the fitted waveform over the specified positions
      Parameters:
      positions - array of positions over which to calculate the waveform
      Returns:
      array holding the calculated waveform over each of the positions
    • calculateFittedWaveform

      public void calculateFittedWaveform(double[] positions, double[] waveform)
      Convenience method to calculate the fitted waveform over the specified positions
      Parameters:
      positions - array of positions over which to calculate the waveform
      waveform - big enough to hold the calculated waveform over each of the positions