Function References
FourierTools.conv
— Functionconv(u, v[, dims])
Convolve `u` with `v` over `dims` dimensions with an FFT based method.
Note, that this method introduces wrap-around artifacts without
proper padding/windowing.
Arguments
u
is an array in real space.v
is the array to be convolved in real space as well.- Per default
ntuple(+, min(N, M)))
means that we perform the convolution over all dimensions of that array which has less dimensions. Ifdims
is an array with integers, we perform convolution only over these dimensions. Eg.dims=[1,3]
would perform the convolution over the first and third dimension. Second dimension is not convolved.
If u
and v
are both a real valued array we use rfft
and hence the output is real as well. If either u
or v
is complex we use fft
and output is hence complex.
Examples
1D with FFT over all dimensions. We choose v
to be a delta peak. Therefore convolution should act as identity.
julia> u = [1 2 3 4 5]
1×5 Array{Int64,2}:
1 2 3 4 5
julia> v = [0 0 1 0 0]
1×5 Array{Int64,2}:
0 0 1 0 0
julia> conv(u, v)
1×5 Matrix{Float64}:
4.0 5.0 1.0 2.0 3.0
2D with FFT with different dims
arguments.
julia> u = 1im .* [1 2 3; 4 5 6]
2×3 Matrix{Complex{Int64}}:
0+1im 0+2im 0+3im
0+4im 0+5im 0+6im
julia> v = [1im 0 0; 1im 0 0]
2×3 Matrix{Complex{Int64}}:
0+1im 0+0im 0+0im
0+1im 0+0im 0+0im
julia> conv(u, v)
2×3 Matrix{ComplexF64}:
-5.0+0.0im -7.0+0.0im -9.0+0.0im
-5.0+0.0im -7.0+0.0im -9.0+0.0im
FourierTools.plan_conv
— Functionplan_conv(u [, dims])
Pre-plan an optimized convolution for array shaped like u
(based on pre-plan FFT) along the given dimenions dims
. dims = 1:ndims(u)
per default. The 0 frequency of u
must be located at the first entry.
We return first the v_ft
(obtained by fft(u)
or rfft(u)
). The second return is the convolution function pconv
. pconv
itself has two arguments. pconv(u, v_ft=v_ft)
where u
is the object and v_ft
the v_ft. This function achieves faster convolution than conv(u, u)
. Depending whether u
is real or complex we do fft
s or rfft
s
Examples
julia> u = [1 2 3 4 5]
1×5 Matrix{Int64}:
1 2 3 4 5
julia> v = [1 0 0 0 0]
1×5 Matrix{Int64}:
1 0 0 0 0
julia> v_ft, pconv = plan_conv(v)
(ComplexF64[1.0 + 0.0im 1.0 + 0.0im … 1.0 + 0.0im 1.0 + 0.0im], FourierTools.var"#conv#40"{Matrix{ComplexF64}, AbstractFFTs.ScaledPlan{ComplexF64, FFTW.rFFTWPlan{ComplexF64, 1, false, 2, UnitRange{Int64}}, Float64}, FFTW.rFFTWPlan{Float64, -1, false, 2, UnitRange{Int64}}}(ComplexF64[1.0 + 0.0im 1.0 + 0.0im … 1.0 + 0.0im 1.0 + 0.0im], 0.2 * FFTW complex-to-real plan for 1×5 array of ComplexF64
(rdft2-rank>=2/1
(rdft2-hc2r-rank0
(rdft-rank0-iter-ci/1-x5))
(dft-direct-5 "n1bv_5_avx2_128")), FFTW real-to-complex plan for 1×5 array of Float64
(rdft2-rank>=2/1
(rdft2-r2hc-rank0-x5)
(dft-direct-5 "n1fv_5_avx2_128"))))
julia> pconv(u, v_ft)
1×5 Matrix{Float64}:
1.0 2.0 3.0 4.0 5.0
julia> pconv(u)
1×5 Matrix{Float64}:
1.0 2.0 3.0 4.0 5.0