Fitting an *almost* sinusoidal curve

127 Views Asked by At

I am trying to fit a curve I obtained from numerical integration, let's call it $f_{num}(x)$, with an analytic equation, call it $f_{fit}(x)$. Since the solution of the numerical integration is periodic, with period $P$, and it appears to have a sinusoidal behavior, I let $f_{fit}$ be such that

$f_{fit}(x)= A\cos(Bx)+C$

where

$A = -\frac{1}{2}[\textrm{max}(f_{num})-\textrm{min}(f_{num})]$

$B = \frac{2\pi}{P}$

$C = \textrm{min}(f_{num})-A$

However, as you can see from the image below, the approximated function could still be improved. Any suggestions on how this could be done without resorting to Fourier Series or other techniques that involve more that 3 or 4 parameters? In other words, could I use a better function other $A\cos(Bx)+C$ to better represent $f_{num}(x)$? Thank you for your help!

enter image description here

2

There are 2 best solutions below

0
On BEST ANSWER

The difference between your blue curve and red curve is plotted on the graph below.

It is not surprising that the scatter of the dots is large because, without your data, it was necessary to scan your image. The resulting data from the position of the pixels on the computer screen is not accurate enough.

Nevertheless, it is clear that the difference between your numerical and fitted curves is roughly a periodic function, but not a pure sinusoid.

This means that you could improve the fitting in adding a sinusoidal term, such as : $$f_{fit}(x)= A'\cos(Bx)+C'+ D'\cos(2Bx)$$ Of course, the new parameters $A', C'$ will be slightly different from the previous ones $A,C$. And there is a new parameter $D'$. So, they are four parameters $A',B,C',D'$ as required at the most.

The fitting will be slightly improved, but not much because the periodic deviation is not a pure sinusoidal term.

Since the deviation is mainly periodic and since your requirements excludes the Fourier series, the most likely it is not possible to improve again the fitting.

enter image description here

Of course, the result of fitting depends on the chosen criteria ( The minimum of what ? ). For example, for minimum mean squares, and not regarding the max. and min. of $f(x)$ , the result is shown on the figure below.

enter image description here

0
On

If the target function is really periodic, then you can just fit one "cycle", and then repeat to represent other cycles.

The easiest approach to approximation is to fit with polynomials. It's fairly easy to write polynomial fitting functions yourself. Or, if you want a deluxe solution developed by approximation experts, try chebfun