Exorbitant - 1 year ago 61

Python Question

Hello dear Python experts:)

From a simulation I got data (course of energy over the time) which I have to fit. When I plot the energy it has a non-periodic oscillating course. There are a bunch of helping function like curve_fit from scipy etc. But you always have to specify a function with which the fit should take place. But I don't know a proper function a priori.

I need something like a Fourier fit to get a function representing the data (like it is possible in MatLab) to later use this function to determine its maxima. Has anyone an idea how to deal with such a problem?

Here is an example course: 2

If you like, you can have a look at the data in a .csv-file: https://1drv.ms/u/s!AuQAmr8-QRJSdzNTzyvWPhUaEnw

I would be very delighted to get some help:-)

Many thanks:-)

Answer Source

Using the Fourier fit in MATLAB you also specify a model (how many sin/cos you want).

For instance "Fourier 2" is:

```
f(x) = a0 + a1*cos(x*w) + b1*sin(x*w) +
a2*cos(2*x*w) + b2*sin(2*x*w)
```

Check http://exnumerus.blogspot.nl/2010/04/how-to-fit-sine-wave-example-in-python.html to see how to fit for "Fourier1".

If you really want no model you need to use something like "eureqa", which is free for academic use (http://www.nutonian.com/download/eureqa-desktop-download/).