As I use rfft
I already get only half the spectrum and from my understanding fftshift
only perform a circular shit to put the 0 frequency in the middle of the spectrum. For example if I want the reconstruction using fft
instead I will have to do this:
plot(x, y, legend = false)
Fy = fftshift(fft(y))
freq = 0.0:(fs / length(y)):(fs / 2)
freq = [freq[end:-1:2]; freq]
N = length(Fy)
ak = real.(Fy ./ N)
bk = imag.(Fy ./ N)
yr = [ak[div(N, 2) + 1] / 2 for _ in x]
for i in 1:div(N, 2) # negative frequency
yr .+= ak[i] .* cos.(2 * pi * freq[i] .* (x .+ Δt)) .- bk[i] .* sin.(2 * pi * freq[i] .* (x .+ Δt))
end
for i in (div(N, 2) + 2):N # positive frequency
yr .+= ak[i] .* cos.(2 * pi * freq[i] .* (x .+ Δt)) .+ bk[i] .* sin.(2 * pi * freq[i] .* (x .+ Δt))
end
yr .= -yr
plot!(x, yr)
But once again I have to add a time shift of Δt
and to reverse the signal from the x axis… It seems I’m missing something there