2

I'm trying to fit a sinusoidal curve in CSV data to find the maximum of the curve. The data is of the like of

      Time    Voltage Current
0   -0.02500    -1.4    0.38
1   -0.02498    -1.6    0.32
2   -0.02496    -1.8    0.40
3   -0.02494    -1.4    0.44
4   -0.02492    -1.6    0.30
5   -0.02490    -2.0    0.40
6   -0.02488    -1.8    0.44
7   -0.02486    -1.4    0.32
8   -0.02484    -1.4    0.42
9   -0.02482    -1.6    0.46
10  -0.02480    -1.8    0.36

this is the code:

from numpy import sin
from scipy.optimize import curve_fit
from matplotlib import pyplot


# input and output variables
x, y = dfi["Time"], dfi["Voltage"] 


# defining the function
def func(x, a, b, c, d):
   return a * sin(b(x-c)) + d

# curve fit
popt, _ = curve_fit(func, x, y)

It gives me this error:

<ipython-input-20-f95822761dd9> in objective(x, a, b, c, d)
      9 # defining the function
     10 def objective(x, a, b, c, d):
---> 11         return a * sin(b(x-c)) + d
     12 
     13 # curve fit

TypeError: 'numpy.float64' object is not callable

It's my first attempt at curve fitting and I don't understand the mistake.

Stha_shrea
  • 21
  • 2

0 Answers0