0
$\begingroup$

I have a file containing data. From the plotting I can deduce that the model is a periodic and trigonometric function.

My goal is to find the model and possible the frequencies.

I used NonlinearModelFit and FindFormula to find out the model without any success.

The data in the file:

{{-0.1, -0.0622821}, {-0.099, 1.87434}, {-0.098, 2.13679}, {-0.097, 
1.34418}, {-0.096, 1.04328}, {-0.095, 1.8515}, {-0.094, 
2.52654}, {-0.093, 2.06614}, {-0.092, 0.789174}, {-0.091, 
0.0474938}, {-0.09, 0.23035}, {-0.089, 
0.260663}, {-0.088, -0.741624}, {-0.087, -2.59957}, {-0.086, \
-3.23313}, {-0.085, -2.25539}, {-0.084, -0.841191}, {-0.083, \
-0.890904}, {-0.082, -1.38617}, {-0.081, -1.56477}, {-0.08, \
-0.400696}, {-0.079, 1.27557}, {-0.078, 1.56815}, {-0.077, 
1.08095}, {-0.076, 1.3197}, {-0.075, 2.38857}, {-0.074, 
3.23696}, {-0.073, 2.28299}, {-0.072, 
0.31218}, {-0.071, -0.805857}, {-0.07, -0.0573411}, {-0.069, 
0.416767}, {-0.068, -0.41286}, {-0.067, -1.86552}, {-0.066, \
-2.69618}, {-0.065, -2.31118}, {-0.064, -1.425}, {-0.063, -1.42586}, \
{-0.062, -1.95482}, {-0.061, -1.525}, {-0.06, 0.18301}, {-0.059, 
1.79601}, {-0.058, 2.10051}, {-0.057, 1.10133}, {-0.056, 
0.667925}, {-0.055, 1.88153}, {-0.054, 2.82576}, {-0.053, 
2.54252}, {-0.052, 0.998126}, {-0.051, -0.049864}, {-0.05, 
0.108199}, {-0.049, 
0.116833}, {-0.048, -1.10017}, {-0.047, -2.38839}, {-0.046, \
-2.98824}, {-0.045, -1.89365}, {-0.044, -0.700723}, {-0.043, \
-0.630803}, {-0.042, -2.03987}, {-0.041, -1.83158}, {-0.04, \
-0.350693}, {-0.039, 1.45547}, {-0.038, 1.89983}, {-0.037, 
1.57732}, {-0.036, 1.43025}, {-0.035, 2.19391}, {-0.034, 
2.76342}, {-0.033, 1.87159}, {-0.032, 
0.401489}, {-0.031, -0.219963}, {-0.03, 0.118037}, {-0.029, 
0.544355}, {-0.028, -0.337913}, {-0.027, -2.38913}, {-0.026, \
-3.15683}, {-0.025, -2.40203}, {-0.024, -1.1465}, {-0.023, -1.19873}, \
{-0.022, -1.71968}, {-0.021, -1.16559}, {-0.02, 0.0766209}, {-0.019, 
1.66594}, {-0.018, 1.63393}, {-0.017, 0.70867}, {-0.016, 
1.07513}, {-0.015, 2.16549}, {-0.014, 3.30807}, {-0.013, 
2.6966}, {-0.012, 
0.728343}, {-0.011, -0.277433}, {-0.01, -0.273288}, {-0.009, \
-0.206787}, {-0.008, -0.680366}, {-0.007, -2.03802}, {-0.006, \
-2.67713}, {-0.005, -1.96914}, {-0.004, -1.05758}, {-0.003, \
-1.30517}, {-0.002, -2.31628}, {-0.001, -1.85295}, {0., 
0.173436}, {0.001, 1.76388}, {0.002, 2.22286}, {0.003, 
1.38202}, {0.004, 1.12941}, {0.005, 1.94544}, {0.006, 
2.61935}, {0.007, 2.18036}, {0.008, 
0.649334}, {0.009, -0.0867474}, {0.01, 0.254235}, {0.011, 
0.348242}, {0.012, -0.629415}, {0.013, -2.51307}, {0.014, -3.2367}, \
{0.015, -2.45705}, {0.016, -0.831338}, {0.017, -0.810549}, {0.018, \
-1.51079}, {0.019, -1.49582}, {0.02, -0.152844}, {0.021, 
1.22463}, {0.022, 1.46817}, {0.023, 1.10753}, {0.024, 
1.27707}, {0.025, 2.36378}, {0.026, 3.22339}, {0.027, 
2.1831}, {0.028, 
0.49384}, {0.029, -0.600537}, {0.03, -0.243927}, {0.031, 
0.289749}, {0.032, -0.415532}, {0.033, -2.02509}, {0.034, \
-2.62382}, {0.035, -2.40972}, {0.036, -1.26999}, {0.037, -1.17311}, \
{0.038, -1.95739}, {0.039, -1.50133}, {0.04, 0.231449}, {0.041, 
1.85946}, {0.042, 1.95253}, {0.043, 0.967388}, {0.044, 
0.671136}, {0.045, 1.82168}, {0.046, 2.94848}, {0.047, 
2.4914}, {0.048, 0.933417}, {0.049, 
0.0160948}, {0.05, -0.0412908}, {0.051, 
0.0481004}, {0.052, -0.822245}, {0.053, -2.49393}, {0.054, \
-3.09013}, {0.055, -1.96377}, {0.056, -0.806867}, {0.057, -1.0216}, \
{0.058, -2.14312}, {0.059, -1.91439}, {0.06, -0.307443}, {0.061, 
1.49778}, {0.062, 1.96111}, {0.063, 1.42132}, {0.064, 
1.28766}, {0.065, 2.30393}, {0.066, 2.9453}, {0.067, 
2.0613}, {0.068, 0.342548}, {0.069, -0.504865}, {0.07, 
0.0779691}, {0.071, 
0.728221}, {0.072, -0.377568}, {0.073, -2.37961}, {0.074, \
-3.11988}, {0.075, -2.37731}, {0.076, -1.15611}, {0.077, -1.16658}, \
{0.078, -1.51178}, {0.079, -1.3618}, {0.08, 0.283396}, {0.081, 
1.62506}, {0.082, 1.58162}, {0.083, 0.941375}, {0.084, 
0.989153}, {0.085, 2.27732}, {0.086, 3.34886}, {0.087, 
2.56467}, {0.088, 
0.784093}, {0.089, -0.271929}, {0.09, -0.482589}, {0.091, \
-0.00980706}, {0.092, -0.682073}, {0.093, -2.18204}, {0.094, \
-2.52101}, {0.095, -1.96053}, {0.096, -0.929182}, {0.097, -1.2858}, \
{0.098, -2.20629}, {0.099, -1.89749}, {0.1, 0.0722412}}

The plotting:

SetDirectory[FileNameJoin[{NotebookDirectory[],"Data"}]];
data = Import["fg1.dat"]
plot = ListPlot[data]

enter image description here

$\endgroup$
4
$\begingroup$

Try to tweak your initial guesses in the NonlinearModelFit to help the fit:

mod = NonlinearModelFit[data, c*Sin[a*x + b], {{a, 300}, b, {c, 3}}, x]

Show[ListLinePlot[data], Plot[mod[x], {x, -.1, .1}, PlotStyle -> Red]]

enter image description here

I'm not very familiar with FindFormula, but you can use that as well:

ff[x_] = FindFormula[data, x, TargetFunctions -> {Sin, Times}]

the outputs varies every time you run it, this is one of the simplest I got:

0.00134705 + 2.12462 Sin[314.153 x] + 0.324263 Sin[816.616 x] + 0.999382 Sin[1256.8 x]

enter image description here

It's also interesting to see that using an incomplete set of data, you can still kind of "fit" the noise pattern of the whole dataset:

ff[x_] = FindFormula[data[[;; 120]], x, TargetFunctions -> {Sin, Times}]

2.11911 Sin[314. x] + Sin[1257. x]

enter image description here

$\endgroup$
5
  • $\begingroup$ Very helpful thanks! Is there a way to find frequencies? $\endgroup$ – Oualid May 12 '20 at 13:18
  • 1
    $\begingroup$ You can get the frequencies from the fit parameters. $\endgroup$ – Fraccalo May 12 '20 at 13:43
  • $\begingroup$ If you are only interested in the frequencies, you should also look for Fourier Transforms $\endgroup$ – Fraccalo May 12 '20 at 13:43
  • $\begingroup$ Can you give me a hint or example on how to di it, find frequencies from the fit parameters? Appreciate. $\endgroup$ – Oualid May 12 '20 at 16:10
  • $\begingroup$ look at this: en.wikipedia.org/wiki/Sine_wave it will help you understand what's going on $\endgroup$ – Fraccalo May 12 '20 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.