hiperwalk.ContinuousTime.fit_sin_squared#
- static ContinuousTime.fit_sin_squared(x, y)#
Fit data to the squared sine function.
- Parameters:
- x
numpy.ndarray
The domain values. It is assumed that the entries are evenly spaced. That is,
x[i + 1] - x[i] == x[j + 1] - x[j]
for any validi
andj
.- y
numpy.ndarray
The image values evaluated at each
x[i]
. It is required thaty[i]
corresponds to the evaluation atx[i]
.
- x
- Returns:
- ddict
It contains information about the best fit found. The dictionary keys are
- fit function
A pointer to the obtained sine squared function. Issuing
d["fit function"](theta)
evaluates the function at pointtheta
.- amplitude:
Amplitude of the obtained fit function.
- angular frequency
Angular frequency of the obtained fit function.
- phase shift
Phase shift of the obtained fit function.
- vertical offset
Vertical offset of the obtained fit function.
- frequency
Frequency of the obtained fit function.
- period
Period of the obtained fit function.
Notes
The returned
d["fit function"]
is a pointer todef fit_func(theta): return d["amplitude"]*np.sin( d["angular frequency"]*theta + d["phase shift"] )**2 + d["vertical offset"]
The code was adapted from https://stackoverflow.com/questions/16716302/how-do-i-fit-a-sine-curve-to-my-data-with-pylab-and-numpy