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.
PeakDetect
. $\endgroup$ – Henrik Schumacher Mar 30 '19 at 17:21