I do it with my eye on excel by plotting y =f(x) I control the duration. scale and shift using a,c,d,g,h constants

y = a*( sin(x*pi/c+d)*g+h


is there a systemic way to curve fit data
I actually I need to code for my program. I just need the math or the steps for it