Package xal.extension.fit
Class DampedSinusoidFit
java.lang.Object
xal.extension.fit.DampedSinusoidFit
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 Summary
ConstructorsConstructorDescriptionDampedSinusoidFit(double[] waveform) Constructor accepting the entire waveformDampedSinusoidFit(double[] waveform, int count) Primary Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidcalculateFittedWaveform(double[] positions, double[] waveform) Convenience method to calculate the fitted waveform over the specified positionsdoubleestimateInitialFrequencyVariance(double signalVariance) get an estimate of the initial frequency's variancedoubleestimateInitialGrowthRateVariance(double signalVariance) get an estimate of the initial growth rate's variancedoubleestimateInitialOffsetVariance(double signalVariance) get an estimate of the initial offset's variancedoubleGet the optimized sine-like amplitudedoubleGet the optimized cosine-like phase (equivalent phase if the fitted equation were of the form of A * damping * cos( mu + phase ) ).double[]getFittedWaveform(double[] positions) Convenience method to calculate the fitted waveform over the specified positionsdoubleget the optimized frequencydoubleget the optimized growth ratedoubleGet the sine-like amplitude calculating it if necessary.doubleGet the cosine-like phase calculating it if necessary.doubleget the fitted frequency calculating it if necessarydoubleget the variance in the initial frequency estimate using the initial estimate of the signal variancedoubleget the fitted growth rate calculating it if necessarydoubleget the variance in the initial growth rate estimate using the initial estimate of the signal variancedoubleget the fitted offset calculating it if necessarydoubleget the variance in the initial offset estimate using the initial estimate of the signal variancedoubleGet the sine-like phase estimation calculating it if necessary.doubleget the initial estimate of the signal variancedoubleGet the sine-like phase calculating it if necessary.double[]get the initial waveform error calculating it if necessarydoubleget the initial RMS errorstatic DampedSinusoidFitgetInstance(double[] waveform) Get a new instance of the damped sinusoid using the entire waveformstatic DampedSinusoidFitgetInstance(double[] waveform, int count) Get a new instance of the damped sinusoiddoubleget the optimized offsetdoublegetPhase()get the optimized phasedoubleget the optimized estimate of the signal variancedoubleGet the optimized sine-like phase.double[]get the waveform errordoubleget the initial RMS errorvoidRun the solver to find the best fitvoidsolveWithNoise(double noiseLevel) Run the solver to find the best fitvoidsolveWithNoiseMaxEvaluations(double noiseLevel, int maxEvaluations) Run the solver to find the best fitvoidsolveWithNoiseMaxEvaluationsSatisfaction(double noiseLevel, int maxEvaluations, double satisfaction) Run the solver to find the best fitvoidsolveWithNoiseMaxTime(double noiseLevel, double maxTime) Run the solver to find the best fitvoidsolveWithNoiseMaxTimeSatisfaction(double noiseLevel, double maxTime, double satisfaction) Run the solver to find the best fit
-
Constructor Details
-
DampedSinusoidFit
public DampedSinusoidFit(double[] waveform, int count) Primary Constructor- Parameters:
waveform- data to fitcount- 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
Get a new instance of the damped sinusoid- Parameters:
waveform- data to fitcount- starting from the beginning of the waveform, the number of items in the waveform to use in the fit
-
getInstance
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 noisemaxEvaluations- 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 noisemaxEvaluations- the maximum number of evaluations to performsatisfaction- 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 noisemaxTime- 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 noisemaxTime- the maximum time to wait for the solutionsatisfaction- the satisfaction target to reach before stopping
-
solve
Run the solver to find the best fit- Parameters:
noiseLevel- the noise level used to estimate the error bounds and provide a measure for satisfactionstopper- 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 waveformwaveform- big enough to hold the calculated waveform over each of the positions
-