Function References

FourierTools.convFunction
conv(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. If dims 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
source
FourierTools.plan_convFunction
plan_conv(u, v [, dims])

Pre-plan an optimized convolution for arrays shaped like u and v (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 two arguments: The first one is v_ft (obtained by fft(v) or rfft(v)). 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 ffts or rffts

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(u, v);

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
source