曲线拟合正弦函数的python幂
我想将信号拟合到余弦或正弦函数中:
参考信号:
sample_rate =1000
start_time = 0
end_time = 12
t = np.arange(start_time, end_time, 1/sample_rate)
amplitude = 12 #peak to peak
period = 60/15
n= 4
func =-amplitude* np.cos( np.pi * t/period)**(2*n) + amplitude
并且该信号必须拟合到模型中:
def fit(t, a, b, n):
return -a * np.cos(np.pi* t/(b))**(2*int(n)) + a
通过这样做:
params, pcov = scipy.optimize.curve_fit(fit, t, func, )
a, b, n = params
我得到:
params a = 11.9; b = 0.97 且 n=1
这根本不匹配...
I want to fit a signal into a cos or sine function:
reference signal:
sample_rate =1000
start_time = 0
end_time = 12
t = np.arange(start_time, end_time, 1/sample_rate)
amplitude = 12 #peak to peak
period = 60/15
n= 4
func =-amplitude* np.cos( np.pi * t/period)**(2*n) + amplitude
And this signal must fit into model:
def fit(t, a, b, n):
return -a * np.cos(np.pi* t/(b))**(2*int(n)) + a
By doing:
params, pcov = scipy.optimize.curve_fit(fit, t, func, )
a, b, n = params
I am getting:
params a = 11.9; b = 0.97 and n=1
This doesn't match at all...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将这些建议放在一起给出以下结果:
它将恢复您的参数。
bounds
强制执行积极性,而p0
为起点提供合理的建议,但拟合对此选择非常敏感。putting these suggestions together gives the following:
which recovers your parameters. the
bounds
enforces positivity, while thep0
gives a reasonable suggestion for a starting point, but fitting is very sensitive to this choice.