Here's what I want to do, initially at least: I have an oscillator, it's in some force field, I've integrated it using the Euler method, so I have a list of points of the form {t,x}, where t is the time and x is its position. Here it is, plotted:

enter image description here

Now (before I do more complicated stuff), I want to get the Fourier transform, which at this point ideally should be basically just a Dirac Delta function right around the fundamental frequency of ~7.95, right? Just by eye, the function is pretty clearly a single frequency.

However, Fourier[] doesn't take a list of pairs of the form I said, only single values. So I do:

vals = myList[[All,2]];

And then I can do Fourier on it, like the example from the documentation:

ft = Abs[Fourier[vals]];
Print@ListLogPlot[ft, PlotRange -> {{0, 100}, {0, .5}}];
Print@ListLogPlot[ft, PlotRange -> All];

Which gives me:

enter image description here

So there are two main problems for me here. The first is that, as you can see in the first plot, there is a peak (I assume at the fundamental frequency), but the actual number is wrong. I assume this is because I basically stripped my data of any information about the time to put it in the form accepted by Fourier[], which I guess basically just assumes the "independent variable" of your data is their integer indices. So I'd like to have it graph it in the form where it'll show the peak at the original frequency. I tried "scaling" it, assuming that if my data before ranged from 0 to 10, and had 10,000 values, so that Fourier was calculating it with the length scale {0,10000}, then any frequency Fourier returned would actually be 10000/10=1000 times smaller than the actual frequency, so I could just plot


to get what I want, but this didn't work.

My second problem is visible in the second graph, that aside from the peak near ~20 (from the first graph), it starts diverging for large numbers too. Why's this happening?


edit: From looking at a few threads it seems like people not sampling enough (lower than the Nyquist frequency) seems to be a a common problem, but I don't think it is here, in the example that produced those images, I have:

A period is 0.125664
deltat = 0.000251327

So I'm sampling many times in each period.

  • 2
    $\begingroup$ Unfortunately (because your question is written in great detail) this is no discussion for mathematica.stackexchange. What you have here is a basic problem of Digital Signal Processing. Therefore, I think it is best to move the question there, although I'm pretty sure it is a duplicate. $\endgroup$
    – halirutan
    Jun 3, 2015 at 19:34
  • $\begingroup$ Can you provide the data ? $\endgroup$
    – Sektor
    Jun 3, 2015 at 21:14
  • $\begingroup$ mathematica.stackexchange.com/questions/18082/… $\endgroup$
    – Peltio
    Jun 4, 2015 at 7:33

1 Answer 1


You are not normalizing your Fourier output correctly.

omega = 40;
rangePer = 50;
dataLimit = 2 Pi/omega rangePer;
points = 10000;
data = {#, Cos[omega #]} & /@ 
   Range[0, dataLimit, dataLimit/points][[1 ;; -2]];
ListPlot[data, PlotRange -> {{0, dataLimit/Pi}, Full}]

enter image description here

fdata = Abs@Fourier[data[[All, 2]]];
ft = {2 Pi #/dataLimit, fdata[[# + 1]]} & /@ Range[0, points - 1];
ListPlot[ft, PlotStyle -> {Red, PointSize[0.01]}, 
 PlotRange -> {{0, 2 omega}, Full}, GridLines -> Automatic]

enter image description here

I'm specifying your data range in units of period. If you change your rangePer to 50.5, "all of a sudden" you will get a peak instead of delta function. This is a fundamental property with DFT.

Here is what you get for rangePer=50.5 enter image description here

Not sure what do you mean by:

My second problem is visible in the second graph, that aside from the peak near ~20 (from the first graph), it starts diverging for large numbers too. Why's this happening?

You asking why it's symmetric?

  • $\begingroup$ this is really good. May I ask where can I look to better understand how you decide what to use for rangePer and why changing it from 50 to 50.5 makes such a dramatic difference? Many thanks! $\endgroup$
    – alex
    Jun 24, 2021 at 14:58

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.