# Wrong frequency in Fourier

I have a file, filled with data like this:

As you can see the approximate frequency is about $5/1000 = 0.005$, then angular frequency is about $2 \pi \times 0.005 \approx 0.03$.

Then I use discrete Fourier to obtain this frequency

 num = 3000;
time = 30;
ListPlot[(Sqrt[2 Pi]/Sqrt[num]) Abs[Fourier[list]], Joined -> True,
PlotRange -> {{0, 0.07}, {0, 5}} , DataRange -> {0, 2 Pi/0.01}]


(here I used $0.01$ which is $time/num$)

but the result is the following:

And the plot is going down with no peaks anymore (except mirror reflection on the right side).

So, what's wrong?

EDIT: If I delete PlotRange, the maximum of frequency lies to the left from the value 100. So I correct your PlotRange and then I get, for example, that maximum of frequency lies to the left from 50 and so on. Finally I'll finish with my picture and the maximum of frequency will be 0.

EDIT: Okay, I subtracted the average value from the list:

ListPlot[(Sqrt[2 Pi]/Sqrt[number]) Abs[Fourier[list - Mean[list]]],
Joined -> True, PlotRange -> {{0, 10}, {0, 0.01}},
DataRange -> {0, 2 Pi/0.01}]


Now there are two peaks, but where is frequency $\approx 0.03$?

• Please share the data. You can look here for ideas on how to share the data. You should also read this question and answers. The Fourier function does not scale the x axis. – rhermans Sep 20 '15 at 8:21
• I added some edits to my question. – newt Sep 20 '15 at 10:42
• A useful list of properties for Fourier including the correct selection of a frequency axis is given here. – Hugh Sep 20 '15 at 12:11

Your problem lies in your use of PlotRange. Given a one-dimensional list as input Fourier returns a one-dimensional list as output. This list is considered a set of y-values only if plotted by ListPlot, which takes the x-values to be the consecutive integers 1, 2, 3 ...

With your plot range specification of {0, 0.07} for the x-range you create a problem. You could use All or Automatic instead. Or just remove PlotRange. You'll get something like:

This all is assuming you have sampled your functions with fixed spacing.

Update

If you're interested in the location of the maximum frequency you have to account for the (documented) fact that the DC term is located in the first element of the output list. You can either throw this away in your plot (starting at position 2) or by subtracting the average value from the list:

ListPlot[(Sqrt[2 Pi]/Sqrt[num]) Abs[Fourier[list - Mean[list]]],
Joined -> True, PlotRange -> All, DataRange -> {0, 2 Pi/0.01}]


ListPlot[(Sqrt[2 Pi]/Sqrt[num]) Abs[Fourier[list]], Joined -> True,
PlotRange -> {{2, All}, {0, 40}}, DataRange -> {0, 2 Pi/0.01}]


• Yes, I know. I have this plot. But the maximum of frequency lies to the left from the value 100. So you correct your PlotRange and you get, for example, that maximum of frequency lies to the left from 50 and so on. Finally you'll finish with my picture and the maximum of frequency will be 0. – newt Sep 20 '15 at 10:38
• @newt See update – Sjoerd C. de Vries Sep 20 '15 at 10:55
• @ Sjoerd C. de Vries Sorry, I think to estimate frequency value I should take number of oscillations per time, not per number of samples. Then I got right result. – newt Sep 20 '15 at 12:31
• @It all depends how you define frequency. There are many different versions around. – Sjoerd C. de Vries Sep 20 '15 at 14:34

If I estimate your data you have a time increment of 0.01 and a frequency of about 0.5 Hz. Thus

dt = 0.01;
f0 = 0.5;
data = N@Table[
1000 + 10 Sin[2 \[Pi] f0 (n - 1) dt] + RandomReal[{-3, 3}],


{n,3000}]; ListLinePlot[data]

Now we take the Fourier transform and also generate a frequency axis. Plotting on a log scale and also plotting with the low frequency (mean value) dropped gives the following plots.

ft = Fourier[data, FourierParameters -> {-1, -1}];
ff = N@Table[(n - 1)/(dt Length[ft]), {n, Length[ft]}];
ListLogPlot[Transpose[{ff, Abs[ft]}][[1 ;; 20]], PlotRange -> All,
Frame -> True, FrameLabel -> {"Frequency/Hz", "Modulus"},
Joined -> True]
ListLinePlot[Transpose[{ff, Abs[ft]}][[10 ;; 50]], PlotRange -> All,
Frame -> True, FrameLabel -> {"Frequency/Hz", "Modulus"}]


There is a clear peak at 0.5 Hz. More details on working with Fourier may be found here. Hope that helps.