Some Utility Functions

FourierTools.δFunction
δ([T,] sz, pos=FourierTools.fft_center.(sz))

Return an array which has 1 at pos in the array of size sz.

Examples

julia> δ((3, 3))
3×3 Matrix{Int64}:
 0  0  0
 0  1  0
 0  0  0

julia> δ(Float32, (4, 3))
4×3 Matrix{Float32}:
 0.0  0.0  0.0
 0.0  0.0  0.0
 0.0  1.0  0.0
 0.0  0.0  0.0

julia> δ(Float32, (3, 3), (1,1))
3×3 Matrix{Float32}:
 1.0  0.0  0.0
 0.0  0.0  0.0
 0.0  0.0  0.0
source
FourierTools.select_regionFunction
select_region(mat; new_size)

performs the necessary Fourier-space operations of resampling in the space of ft (meaning the already circshifted version of fft).

new_size. The size of the array view after the operation finished.

center. Specifies the center of the new view in coordinates of the old view. By default an alignment of the Fourier-centers is assumed.

Examples

julia> using FFTW, FourierTools

julia> select_region(ones(3,3),new_size=(7,7),center=(1,3))
7×7 PaddedView(0.0, OffsetArray(::Matrix{Float64}, 4:6, 2:4), (Base.OneTo(7), Base.OneTo(7))) with eltype Float64:
 0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  1.0  1.0  1.0  0.0  0.0  0.0
 0.0  1.0  1.0  1.0  0.0  0.0  0.0
 0.0  1.0  1.0  1.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0
source
FourierTools.center_set!Function
center_set!(arr_large, arr_small)

Puts the arr_small central into arr_large. The convention, where the center is, is the same as the definition as for FFT based centered. Function works both for even and uneven arrays.

Examples

julia> FourierTools.center_set!([1, 1, 1, 1, 1, 1], [5, 5, 5])
6-element Array{Int64,1}:
 1
 1
 5
 5
 5
 1
source
FourierTools.get_indices_around_centerFunction
get_indices_around_center(i_in, i_out)

A function which provides two output indices i1 and i2 where i2 - i1 = i_out The indices are chosen in a way that the set i1:i2 cuts the interval 1:i_in in a way that the center frequency stays at the center position. Works for both odd and even indices

source
FourierTools.center_extractFunction
center_extract(arr, new_size_array)

Extracts a center of an array. new_size_array must be list of sizes indicating the output size of each dimension. Centered means that a center frequency stays at the center position. Works for even and uneven. If length(new_size_array) < length(ndims(arr)) the remaining dimensions are untouched and copied.

Examples

julia> FourierTools.center_extract([1 2; 3 4], [1])
1×2 view(::Matrix{Int64}, 2:2, 1:2) with eltype Int64:
 3  4

julia> FourierTools.center_extract([1 2; 3 4], [1, 1])
1×1 view(::Matrix{Int64}, 2:2, 2:2) with eltype Int64:
 4

julia> FourierTools.center_extract([1 2 3; 3 4 5; 6 7 8], [2 2])
2×2 view(::Matrix{Int64}, 1:2, 1:2) with eltype Int64:
 1  2
 3  4
source
FourierTools.odd_viewFunction
odd_view(arr)

creates a view of arr that for each even dimension excludes the starting index yielding a view of the array with only odd dimensions. This is useful for operations in Fourier-space which should leave the first index unaltered such as reverse! Note that an array reversal can also be achieved by using two ffts instead of one fft and one ifft.

Examples

julia> odd_view([1 2 3; 4 5 6])
1×3 view(::Matrix{Int64}, 2:2, 1:3) with eltype Int64:
 4  5  6
source
FourierTools.fourier_reverse!Function
fourier_reverse!(arr; dims=1:ndims(arr))

reverses the dimensions of the input array arr in place. This effectively mirrors these array. Note that for even-sized dimensions the first index is excluded from the reverse operation along this dimensions.

Example

julia> a = [1 2 3;4 5 6;7 8 9;10 11 12]
4×3 Matrix{Int64}:
  1   2   3
  4   5   6
  7   8   9
 10  11  12

julia> fourier_reverse!(a);

julia> a
4×3 Matrix{Int64}:
  3   2   1
 12  11  10
  9   8   7
  6   5   4
source