0

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

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.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
John
  • 573
  • 2
  • 9

1 Answers1

5

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)

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
andre314
  • 18,474
  • 1
  • 36
  • 69