FFT helpers

FourierTools.ffts!Function
ffts!(A [, dims])

Result is semantically equivalent to fftshift(fft!(A, dims), dims). A is in-place modified. However, the shift is done with ShiftedArrays and therefore doesn't allocate memory.

See also: ft, ift, rft, irft, ffts, iffts, ffts!, rffts, irffts,

FourierTools.ifftsFunction
iffts(A [, dims])

Result is semantically equivalent to ifft(ifftshift(A, dims), dims). A is in-place modified. However, the shift is done with ShiftedArrays and therefore doesn't allocate memory.

See also: ft, ift, rft, irft, ffts, iffts, ffts!, rffts, irffts,

FourierTools.rfftsFunction
rffts(A [, dims])

Calculates a rfft(A, dims) and then shift the frequencies to the center. dims[1] is not shifted, because there is no negative and positive frequency. The shift is done with ShiftedArrays and therefore doesn't allocate memory.

See also: ft, ift, rft, irft, ffts, iffts, ffts!, rffts, irffts,

FourierTools.irfftsFunction
irffts(A, d, [, dims])

Calculates a irfft(A, d, dims) and then shift the frequencies back to the corner. dims[1] is not shifted, because there is no negative and positive frequency. The shift is done with ShiftedArrays and therefore doesn't allocate memory.

See also: ft, ift, rft, irft, ffts, iffts, ffts!, rffts, irffts,

FourierTools.fftshift_viewFunction
fftshift_view(A [, dims])

Result is semantically equivalent to fftshift(A, dims) but returns a view instead.

FourierTools.ifftshift_viewFunction
ifftshift_view(A [, dims])

Result is semantically equivalent to fftshift(A, dims) but returns a view instead.

FourierTools.rfftshift_viewFunction
rfftshift_view(A, dims)

Shifts the frequencies to the center expect for dims[1] because there os no negative and positive frequency.

FourierTools.irfftshift_viewFunction
irfftshift_view(A, dims)

Shifts the frequencies back to the corner except for dims[1] because there os no negative and positive frequency.

FourierTools.ftFunction
ft(A [, dims])

Digital Fourier-transformation centered in both spaces. The result is semantically equivalent to fftshift(fft(ifftshift(A, dims), dims), dims) This is a digital Fourier transformation with both coordinate systems in real and Fourier-space being centered at position CtrFT == size÷2+1

The following identities are true:

julia> sz = (5,5)
(5, 5)

julia> ft(ones(sz)) ≈ prod(sz) .* δ(sz)
true

julia> ft(δ(sz)) ≈ ones(sz)
true

See also: ft, ift, rft, irft, ffts, iffts, ffts!, rffts, irffts,

FourierTools.iftFunction
ift(A [, dims])

Digital inverse Fourier-transformation centered in both spaces. The result is semantically equivalent to fftshift(ifft(ifftshift(A, dims), dims), dims) This is a digital Fourier transformation with both coordinate systems in real and Fourier-space being centered at position CtrFT == size÷2+1

The following identities are true:

julia> sz = (5,6,7)
(5, 6, 7)

julia> ift(ones(sz)) ≈ δ(sz)
true

julia> ift(δ(sz)) ≈ ones(sz) ./ prod(sz)
true

See also: ft, ift, rft, irft, ffts, iffts, ffts!, rffts, irffts,

FourierTools.rftFunction
rft(A [, dims])

Digital real-valued Fourier-transformation centered in both spaces. The result is semantically equivalent to fftshift(rfft(ifftshift(A, dims), dims), dims) This is a digital Fourier transformation with the coordinate systems in real space centered at CtrFT == size÷2+1 and in (half) Fourier-space being centered at CtrRFT == setindex(size÷2 +1,1,1).

The following identities are true:

julia> sz = (6,6)
(6, 6)

julia> rft(δ(sz)) ≈ ones(rft_size(sz))
true

See also: ft, ift, rft, irft, ffts, iffts, ffts!, rffts, irffts,

FourierTools.irftFunction
irft(A, d, [, dims])

Digital real-valued inverse Fourier-transformation centered in both spaces. The result is semantically equivalent to fftshift(irfft(ifftshift(A, dims), dims), dims) This is a digital Fourier transformation with the coordinate systems in real space centered at CtrFT == size÷2+1 and in (half) Fourier-space being centered at CtrRFT == setindex(size÷2 +1,1,1). Note that the size d of the first transform direction [1] is a required argument.

The following identities are true:

julia> sz = (6,6)
(6, 6)

julia> irft(ones(rft_size(sz)),sz[1]) ≈ δ(sz)
true

See also: ft, ift, rft, irft, ffts, iffts, ffts!, rffts, irffts,

FFT Utils

FourierTools.fftposFunction
fftpos(L, N, around=CenterFirst::Center)

Construct a range from -L/2 to L/2 around around

However, we ensure that those positions are in a way which they are useful for FFT operations. This means, that depending on the center a small offset is subtracted.

See NDTools.Center for all center options. You need to load using NDTools to access all center options.

Examples

julia> collect(fftpos(1,4))
4-element Vector{Float64}:
 0.0
 0.2916666666666667
 0.5833333333333334
 0.875

julia> collect(fftpos(1,5))
5-element Vector{Float64}:
 0.0
 0.225
 0.45
 0.675
 0.9

julia> using NDTools

julia> collect(fftpos(1,4, CenterFirst))
4-element Vector{Float64}:
 0.0
 0.2916666666666667
 0.5833333333333334
 0.875

julia> collect(fftpos(1,4, CenterFT))
4-element Vector{Float64}:
 -0.5833333333333333
 -0.29166666666666663
  3.70074341541719e-17
  0.2916666666666667

julia> collect(fftpos(1,4, CenterMiddle))
4-element Vector{Float64}:
 -0.4375
 -0.14583333333333334
  0.14583333333333334
  0.4375
fftpos(l, N, around)

Another fftpos method where the range is constructed around around. around is here a number indicating the index position around the range is constructed

FourierTools.fft_centerFunction
fft_center(x)

Returns the center of a size in Fourier sense and Julia 1-based indices.

FourierTools.rft_sizeFunction
rft_size(sz::NTuple{Int})

Returns the size of an rft or rfft performed on the data x, without performing the rfft. sz: corresponding real space size to obtain the rft size for

rft_size(arr)

Returns the size of an rft or rfft performed on the data x, without performing the rfft.

arr: array to optain the corresponding rft size for

FourierTools.rfft_sizeFunction
rfft_size(size, dims)

Returns the size rfft would return if applied to a real array. size is the input size to rfft and dims the dimensions the rfft transforms over. Actually we only would need first(dims).

julia> using FFTW

julia> rfft((ones((4,3,2))), (2,3)) |> size
(4, 2, 2)

julia> FourierTools.rfft_size((4,3,2), (2, 3))
(4, 2, 2)
FourierTools.ft_center_diffFunction
ft_center_diff(s [, dims])

Calculates how much each dimension must be shifted that the center frequency is at the Fourier center. This if for a normal fft

FourierTools.rft_center_diffFunction
rft_center_diff(s [, dims])

Calculates how much each dimension must be shifted that the center frequency is at the Fourier center. This is for rfft. The dims[1] must be therefore not shifted!

FourierTools.center_posFunction
center_pos(x)

Calculate the position of the center frequency. Size of the array is x

Examples

julia> FourierTools.center_pos(3)
2
julia> FourierTools.center_pos(4)
3

FFT Helpers 2D

FourierTools.fftshift2dFunction
fftshift2d(mat::AbstractArray{T, N}) where {T, N}

Short-hand for fftshift(mat, (1,2)). See fftshift for details.

FourierTools.ifftshift2dFunction
ifftshift2d(mat::AbstractArray{T, N}) where {T, N}

Short-hand for ifftshift(mat, (1,2)). See ifftshift for details.

FourierTools.fftshift2d_viewFunction
fftshift2d_view(mat::AbstractArray{T, N}) where {T, N}

Short-hand for fftshift_view(mat, (1,2)). See fftshift_view for details.

FourierTools.ifftshift2d_viewFunction
ifftshift2d_view(mat::AbstractArray{T, N}) where {T, N}

Short-hand for ifftshift_view(mat, (1,2)) performing only a 2D inverse ft. See ifft for details.

FourierTools.fft2dFunction
fft2d(mat::AbstractArray{T, N}) where {T, N}

Only over dims=(1,2).

FourierTools.ifft2dFunction
ifft2d(mat::AbstractArray{T, N}) where {T, N}

Only over dims=(1,2).

FourierTools.rfft2dFunction
rfft2d(mat::AbstractArray{T, N}) where {T, N}

Only over dims=(1,2).

FourierTools.irfft2dFunction
irfft2d(mat::AbstractArray{T, N}, d) where {T, N}

Only over dims=(1,2).

FourierTools.ffts2dFunction
ft2d(mat::AbstractArray{T, N}) where {T, N}

Only over dims=(1,2).

FourierTools.ffts2d!Function
fft2ds!(mat::AbstractArray{T, N}) where {T, N}

Only over dims=(1,2).

FourierTools.iffts2dFunction
iffts2d(mat::AbstractArray{T, N}) where {T, N}

Only over dims=(1,2).

FourierTools.rffts2dFunction
rffts2d(mat::AbstractArray{T, N}) where {T, N}

Only over dims=(1,2).

FourierTools.irffts2dFunction
riffts2d(mat::AbstractArray{T, N}, d) where {T, N}

Only over dims=(1,2).

FourierTools.ft2dFunction
ft2d(mat::AbstractArray{T, N}) where {T, N}

Only over dims=(1,2).

FourierTools.ift2dFunction
ift2d(mat::AbstractArray{T, N}) where {T, N}

Only over dims=(1,2).

FourierTools.rft2dFunction
rft2d(mat::AbstractArray{T, N}) where {T, N}

Only over dims=(1,2).

FourierTools.irft2dFunction
irft2d(mat::AbstractArray{T, N}, d) where {T, N}

Only over dims=(1,2).