[SciPy-User] fitting cosine with curve_fit - problem with frequency
Wed Oct 12 19:23:58 CDT 2011
So I am trying to fit some data that is a mixture of oscillations, so I figured I'd try to do a "toy" problem...and that problem is stumping me (full code at the bottom). I generate data like:
and fit a model like:
with scipy.optimize.curve_fit. It seems as if the method used in curve_fit doesn't like oscillatory data, especially when estimating the frequency. Unless my initial guess for the frequency is *very* close to the right answer (i.e. I need the right answer already to get the answer), it doesn't even get close.
Is there a better way to fit this sort of a function? Should I do an fft, pick off frequencies, and use those as the initial estimates? Am I doing something wrong?
any ideas, or references to places I can read about it, would be great!
from scipy import optimize
from numpy import *
popt, pcov = optimize.curve_fit(func, x, y,
p0=p0, # initial guess
More information about the SciPy-User