Use the sinfit function to perform a sinusoidal regression. This is particularly appropriate if your data oscillates with a regular period.
1. Define a data set.
2. Define a vector of guesses.
In some cases, you must adjust the guesses to get the best possible fit. The first value should be approximately equal to the amplitude of your data, the second should be equal to the phase shift, and the third should be equal to the offset.
3. Call the sinfit function to find the parameters of the sinusoidal fit.
The parameters are those found in the following sinusoidal equation:
4. Plot the data and the sinusoidal fit.
The fit is almost perfect, as confirmed by the correlation coefficient: