Failed to obtain the correct phase?

Hello,

The sampling rate seems to be too large. Try decreasing it:

using FFTW, Plots
t= 0:0.001:34;
a = 3cos.(2π/17 .* t .+ 0.2);
plot(t,a)
N =  floor(Int64,length(a)/2);
fa = fft(a)[1:N];
fam = abs.(fa);
famfm = findmax(fam)
f0 = (famfm[2] - 1)/(t[end]-t[1])
T0 = 1 /f0   # period
A0 = famfm[1] / N  # amplitude
fap = angle.(fa);
fap[famfm[2]]   # phase

Regards,
Rafael

2 Likes