I have some data like this:
function f(x)
[sin(2*pi*x[1])*cos(2*pi*x[2]), cos(2*pi*x[1])*sin(2*pi*x[2])]
end
N=200
data = [f([i/N,j/N]) for i in 0:N-1, j in 0:N-1]
which is a matrix of size N\times N, with vector elements. Now I want to take fft in each slice of data
so that the result has the same structure as data
. I can do this by using the follow codes
using FFTW
function v_fft(A::Matrix{Vector{Float64}})
n=size(A,2)
b=Matrix{Float64}(undef, n, n)
c=Matrix{Float64}(undef, n, n)
@inbounds @simd for i in 1:n^2
b[i]=A[i][1]
c[i]=A[i][2]
end
fb=fft(b)
fc=fft(c)
result=Matrix{Vector{ComplexF64}}(undef, n, n)
@inbounds @simd for i in 1:n^2
result[i]=[fb[i],fc[i]]
end
result
end
v_fft(data)
gives what I want. Is there any simple way to do that ?