I was testing fft on mathematica using simple functions and ran into problems.
I first tried a simple cos function with the following code:
f1[x_] := Cos[2 \[Pi]*x];
Sample = Table[f1[x], {x, 0, 2, 1/100}];
fft = Abs[Fourier[Sample]];
p1 = ListLinePlot[fft, PlotRange -> Full, DataRange -> {-1, 1}]
which does give me the graph of two delta functions. Here is my first question:
Why do I have to manually adjust DataRange in order for the peak to be at the correct position namely -1 and 1?
I then tried the addition of two cos functions and this is where it started to give me problems
f2[x_] := Cos[2 \[Pi]*x] + Cos[\[Pi]*x];
Sample1 = Table[f2[x], {x, 0, 2, 1/100}];
fft1 = Abs[Fourier[Sample1]];
p2 = ListLinePlot[fft1, PlotRange -> Full]
Supposedly it should give me four peaks at -2,-1,1,2 but the graph is not showing so. Where might it go wrong in this case? And what datarange shall i use?



Fourierhere in answer to another question. You may find them helpful. Let me know if you need more. – Hugh Jan 28 '22 at 13:41