Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong FFT results #144

Open
aplavin opened this issue Aug 15, 2023 · 0 comments
Open

Wrong FFT results #144

aplavin opened this issue Aug 15, 2023 · 0 comments

Comments

@aplavin
Copy link
Collaborator

aplavin commented Aug 15, 2023

As I understand, fft/ifft implementations in https://github.com/mcabbott/AxisKeys.jl/blob/master/src/fft.jl are fundamentally wrong and return incorrect results. For one, the original axiskeys don't affect the resulting content at all - this cannot be right, shifting the original array should change the phase of the FFT.

These are the implementations for zero-centered axiskeys (as they @assert), seem correct --- eg ifft inverts fft, fft of delta function at zero is constant, etc:

function AbstractFFTs.fft(A::KeyedArray)
	@assert all(ks -> ks[end÷2+1] |> iszero, axiskeys(A))
	data = fft(AxisKeys.keyless(fftshift(A)))
	keys = map(axiskeys(A)) do ks
		fftfreq(length(ks), inv(step(ks)))
	end
	KeyedArray(data, keys) |> fftshift
end

function AbstractFFTs.ifft(A::KeyedArray)
	@assert all(ks -> ks[end÷2+1] |> iszero, axiskeys(A))
	data = ifft(AxisKeys.keyless(fftshift(A)))
	keys = map(axiskeys(A)) do ks
		fftfreq(length(ks), inv(step(ks)))
	end
	KeyedArray(data, keys) |> fftshift
end

Implementations for arbitrary (ranges) axiskeys should involve phase gradient multiplication, at least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant