update
Just to clean things up a bit, we can use the discussion here to make a couple functions that help extract the frequency data from this dataset. I define two functions findPeriod
and reconstruct
:
Clear[findPeriod];
findPeriod[data_, threshold_] :=
Module[{fs, s1, s = {}, i, a0f, af, pf, pos, fr, frpos, fdata,
fdatac, n, per},
n = Length[data];
fs = Fourier[data];
s1 = Drop[fs, -Floor[Length[fs]/2]];
For[i = 1, i < Length[s1], i++,
If[Abs[fs][[i + 1]] > threshold, AppendTo[s, i + 1]]];
a0f = Abs[fs[[1]]]/Sqrt[n];
af = 2/Sqrt[n] Abs[fs][[s]];
pf = Arg[fs][[s]];
{a0f, Transpose[{s, af, pf}]}]
Clear[reconstruct];
reconstruct[data_, fp_] := Module[{n},
n = Length[data];
Show[
ListLinePlot[data, PlotStyle -> Black],
Plot[fp[[1]] +
Sum[fp[[2, j, 2]] Cos[
2 Pi (fp[[2, j, 1]] - 1)/n t - fp[[2, j, 3]]], {j, 1,
Length[fp[[2]]]}], {t, 0, n}, PlotStyle -> Red]
]]
The first can be used to extract all frequencies above a certain threshold:
TableForm[Sort[findPeriod[data, 0.4][[2]], #1[[2]] > #2[[2]] &],
TableHeadings -> {None, {"Freq", "Amp", "Phase"}}]
and the second takes this information to reconstruct the data:
old version
I had to drop the first and last points of your TXT file, so there may be some slight differences. Process should be the same, however.
f = Abs[Fourier[data]];
n = Length[f];
(* n = 3737 *)
(* Drop the first point, which may be an outlier, find the max *)
pos = Position[f, Max[f[[2 ;;]]]][[1, 1]];
(* pos = 40 *)
(* Follow the help file for Fourier *)
fr = Abs[Fourier[data Exp[2 Pi I (pos - 2) N[Range[0, n - 1]]/n],
FourierParameters -> {0, 2/n}]];
frpos = Position[fr, Max[fr]][[1, 1]];
(* frpos = 2790 *)
(* Get the period *)
per = N[n/(pos - 2 + 2 (frpos - 1)/n)];
(* per = 94.6252 *)
(* Plot the extracted frequency with the data *)
pdata = Table[Mean[data] + 0.02 Sin[2 \[Pi] x/per], {x, n}] ;
ListLinePlot[{pdata, data}]