FFT helpers
FourierTools.ffts — Functionffts(A [, dims])Result is semantically equivalent to fftshift(fft(A, dims), dims) 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.ffts! — Functionffts!(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.iffts — Functioniffts(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.rffts — Functionrffts(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.irffts — Functionirffts(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_view — Functionfftshift_view(A [, dims])Result is semantically equivalent to fftshift(A, dims) but returns a view instead.
FourierTools.ifftshift_view — Functionifftshift_view(A [, dims])Result is semantically equivalent to fftshift(A, dims) but returns a view instead.
FourierTools.rfftshift_view — Functionrfftshift_view(A, dims)Shifts the frequencies to the center expect for dims[1] because there os no negative and positive frequency.
FourierTools.irfftshift_view — Functionirfftshift_view(A, dims)Shifts the frequencies back to the corner except for dims[1] because there os no negative and positive frequency.
FourierTools.ft — Functionft(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)
trueSee also: ft, ift, rft, irft, ffts, iffts, ffts!, rffts, irffts,
FourierTools.ift — Functionift(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)
trueSee also: ft, ift, rft, irft, ffts, iffts, ffts!, rffts, irffts,
FourierTools.rft — Functionrft(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))
trueSee also: ft, ift, rft, irft, ffts, iffts, ffts!, rffts, irffts,
FourierTools.irft — Functionirft(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)
trueSee also: ft, ift, rft, irft, ffts, iffts, ffts!, rffts, irffts,
FFT Utils
FourierTools.fftpos — Functionfftpos(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.4375fftpos(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_center — Functionfft_center(x)Returns the center of a size in Fourier sense and Julia 1-based indices.
FourierTools.rft_size — Functionrft_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_size — Functionrfft_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_diff — Functionft_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_diff — Functionrft_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_pos — Functioncenter_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)
3FFT Helpers 2D
FourierTools.fftshift2d — Functionfftshift2d(mat::AbstractArray{T, N}) where {T, N}Short-hand for fftshift(mat, (1,2)). See fftshift for details.
FourierTools.ifftshift2d — Functionifftshift2d(mat::AbstractArray{T, N}) where {T, N}Short-hand for ifftshift(mat, (1,2)). See ifftshift for details.
FourierTools.fftshift2d_view — Functionfftshift2d_view(mat::AbstractArray{T, N}) where {T, N}Short-hand for fftshift_view(mat, (1,2)). See fftshift_view for details.
FourierTools.ifftshift2d_view — Functionifftshift2d_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.fft2d — Functionfft2d(mat::AbstractArray{T, N}) where {T, N}Only over dims=(1,2).
FourierTools.ifft2d — Functionifft2d(mat::AbstractArray{T, N}) where {T, N}Only over dims=(1,2).
FourierTools.rfft2d — Functionrfft2d(mat::AbstractArray{T, N}) where {T, N}Only over dims=(1,2).
FourierTools.irfft2d — Functionirfft2d(mat::AbstractArray{T, N}, d) where {T, N}Only over dims=(1,2).
FourierTools.ffts2d — Functionft2d(mat::AbstractArray{T, N}) where {T, N}Only over dims=(1,2).
FourierTools.ffts2d! — Functionfft2ds!(mat::AbstractArray{T, N}) where {T, N}Only over dims=(1,2).
FourierTools.iffts2d — Functioniffts2d(mat::AbstractArray{T, N}) where {T, N}Only over dims=(1,2).
FourierTools.rffts2d — Functionrffts2d(mat::AbstractArray{T, N}) where {T, N}Only over dims=(1,2).
FourierTools.irffts2d — Functionriffts2d(mat::AbstractArray{T, N}, d) where {T, N}Only over dims=(1,2).
FourierTools.ft2d — Functionft2d(mat::AbstractArray{T, N}) where {T, N}Only over dims=(1,2).
FourierTools.ift2d — Functionift2d(mat::AbstractArray{T, N}) where {T, N}Only over dims=(1,2).
FourierTools.rft2d — Functionrft2d(mat::AbstractArray{T, N}) where {T, N}Only over dims=(1,2).
FourierTools.irft2d — Functionirft2d(mat::AbstractArray{T, N}, d) where {T, N}Only over dims=(1,2).