## Function References

`FourierTools.conv`

— Function`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
```

`FourierTools.ccorr`

— Function`ccorr(u, v[, dims]; centered=false)`

Calculates the cross-correlation between `u`

and `v`

along `dims`

. `centered=true`

moves the output of the cross-correlation to the Fourier center.

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.

Per default the correlation is performed along `min(ndims(u), ndims(v))`

.

```
julia> ccorr([1,1,0,0], [1,1,0,0], centered=true)
4-element Vector{Float64}:
0.0
1.0
2.0
1.0
julia> ccorr([1,1,0,0], [1,1,0,0])
4-element Vector{Float64}:
2.0
1.0
0.0
1.0
julia> ccorr([1im,0,0,0], [0,1im,0,0])
4-element Vector{ComplexF64}:
0.0 + 0.0im
0.0 + 0.0im
0.0 + 0.0im
1.0 + 0.0im
julia> ccorr([1im,0,0,0], [0,1im,0,0], centered=true)
4-element Vector{ComplexF64}:
0.0 + 0.0im
1.0 + 0.0im
0.0 + 0.0im
0.0 + 0.0im
```

`FourierTools.conv_psf`

— Function`conv_psf(u, psf[, dims])`

`conv_psf`

is a shorthand for `conv(u,ifftshift(psf))`

. For examples see `conv`

.

`FourierTools.plan_conv`

— Function`plan_conv(u, v [, dims]; kwargs...)`

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 `fft`

s or `rfft`

s Additionally, it is possible to provide `flags=FFTW.MEASURE`

as `kwargs`

to change the planning of the FFT.

**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
```

`FourierTools.plan_conv_psf`

— Function`plan_conv_psf(u, psf [, dims]; kwargs...) where {T, N}`

`plan_conv_psf`

is a shorthand for `plan_conv(u, ifftshift(psf))`

. For examples see `plan_conv`

.

`FourierTools.plan_conv_buffer`

— Function`plan_conv_buffer(u, v [, dims]; kwargs...)`

Similar to `plan_conv`

but instead uses buffers to prevent memory allocations. Not AD friendly!

`FourierTools.plan_conv_psf_buffer`

— Function`plan_conv_psf_buffer(u, psf [, dims]; kwargs...) where {T, N}`

`plan_conv_psf_buffer`

is a shorthand for `plan_conv_buffer(u, ifftshift(psf))`

. For examples see `plan_conv`

.