1
$\begingroup$

I have a file, filled with data like this: enter image description here

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:

enter image description here

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$? enter image description here

$\endgroup$
3
  • $\begingroup$ 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. $\endgroup$
    – rhermans
    Commented Sep 20, 2015 at 8:21
  • $\begingroup$ I added some edits to my question. $\endgroup$
    – newt
    Commented Sep 20, 2015 at 10:42
  • $\begingroup$ A useful list of properties for Fourier including the correct selection of a frequency axis is given here. $\endgroup$
    – Hugh
    Commented Sep 20, 2015 at 12:11

2 Answers 2

4
$\begingroup$

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:

Mathematica graphics

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}]

Mathematica graphics

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

Mathematica graphics

$\endgroup$
4
  • $\begingroup$ 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. $\endgroup$
    – newt
    Commented Sep 20, 2015 at 10:38
  • $\begingroup$ @newt See update $\endgroup$ Commented Sep 20, 2015 at 10:55
  • $\begingroup$ @ 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. $\endgroup$
    – newt
    Commented Sep 20, 2015 at 12:31
  • $\begingroup$ @It all depends how you define frequency. There are many different versions around. $\endgroup$ Commented Sep 20, 2015 at 14:34
1
$\begingroup$

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]

Mathematica graphics

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"}]

Mathematica graphics

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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