# Finding frequency from Fourier transform [closed]

I tried to find frequency using Fourier Transform, but notice that my code have some mistakes which I can't find. So, my code is below:

T0 = 0.0;
T1 = 5.0;
gf = 1.0;

ja = Table[Cos[2 Pi*gf*t], {t, T0, T1, 1/10}];
ja1 = Fourier[ja];
ja2 = Chop[ja1];
ja3 = Take[Abs[ja2], ((Length[ja2] - 1)/2) + 1];

ListPlot[ja3, Frame -> True, FrameLabel -> {Style["Frequency (a.u.)",
FontSize -> 16], Style["Amplitude (a.u.)", FontSize -> 16]},
PlotRange -> All, Joined -> True, Mesh -> All]


And result is: After I find frequency which is 1 Hz.

MaxAmp = Position[ja3, Max[ja3]][[1, 1]]


6

Freq = (MaxAmp - 1)/(T1 - T0)


1.

Than, I want to change frequency gf from 1 to 6 and I get next result: When I tried to find frequency, I got 4 Hz which isn't correct. I noticed that on the range between 1 and 5 it's work good, but if set larger value it's not correct. I also noticed that if you change the step from 1/10 to 1/20, then the result will be correct. But changing the frequency gf is constantly required to select this step, which is not convenient. How can I do it automatically, to prevent incorrect result.

• You might be interested in PeakDetect. – Henrik Schumacher Mar 30 '19 at 17:21
• This is a classical signal processing problem. (though I have not found a simple and concise answer on "signal processing StackExchange") – andre314 Mar 30 '19 at 21:15
• I have put information concerning the frequency axis and other basic aspects of Fourier here. This may help. – Hugh Mar 31 '19 at 11:46

What you observe is perfectly normal. It is the consequence of the famous Nyquist sampling theorem.

In your case, it is particularly clear that the problem is not due to the Fourier transform. Compare:

• ja at $$6 \text{ Hz}$$ gf = 6.0; ja6 = Table[Cos[2 Pi*gf*t], {t, T0, T1, 1/10}]
• ja at $$4 \text{ Hz}$$ gf = 4.0; ja4 = Table[Cos[2 Pi*gf*t], {t, T0, T1, 1/10}]

They are exactly the same:

   Max[Abs[ja6 - ja4]]


3.030908857*10^-14

(It's a very special case of aliasing due to not respecting the theorem)