I have to find period of a pendulum. I have a data set and my idea was to use curve_fit to find the frequency. However, curve_fit returns completely wrong values.
Here's how the code looks like:
time1, red1, blue1 = reading(name_csv) #function that fetches data from csv files, there were 2 pendulums so that's why the function returns 3 arrays
p0 = 0.18, 2, 1.33, 0.02
popt, pcov = curve_fit(lambda t, A, omega, fi, B: A*np.cos(omega*t + fi) + B, time1, red1, p0)
time = np.linspace(8, 30, 250)
A, omega, fi, B = popt
fig, ax = plt.subplots(figsize=[8,7])
plt.scatter(time1, red1, color="silver")
plt.plot(time, A*np.cos(omega*time + fi) + B, color="blue")
As you can see the the amplitude and frequency are incorrect. Not sure what's wrong. Are the starting values not precise enough? Tried filtering the data, but that didn't help.
