# FFTResampling.jl

Here you can find the docstrings of all functions.

FFTResampling.resampleFunction
resample(arr, new_size [, normalize]; take_real=true, boundary_handling=true)

Calculates the sinc interpolation of an arr on a new array size new_size. It is a re-evaluation of the Fourier series at new grid points. new_size can be arbitrary. Each dimension is then independently either up or downsampled.

This method is based on FFTs and therefore implicitly assumes periodic boundaries and a finite frequency support. normalize=true by default multiplies by an appropriate factor so that the average intensity stays the same. If size(new_size)[i] > size(arr)[i], we apply zero padding in Fourier space. If size(new_size)[i] < size(arr)[i], we cut out a centered part of the Fourier spectrum.

We apply some tricks at the boundary to increase accuracy of highest frequencies. If you set the keyword argument boundary_handling=false you turn this boundary handling off. This can increase inaccuracies for the highest frequency (not a big problem in real images/signals). However, resample is then faster on CPUs and especially on CUDA GPUs.

Examples

julia> resample([1.0, 2.0, 3.0, 4.0], 8)
8-element Array{Float64,1}:
1.0
1.085786437626905
2.0
2.5
3.0
3.914213562373095
4.0
2.5

julia> resample([1.0  2.0; 3.0 4.0], (4,4))
4×4 Array{Float64,2}:
1.0  1.5  2.0  1.5
2.0  2.5  3.0  2.5
3.0  3.5  4.0  3.5
2.0  2.5  3.0  2.5

julia> resample([1.0, 0.0, 1.0, 0.0, 1.0, 0.0], (3))
3-element Array{Float64,1}:
0.5
0.5
0.5

julia> resample([1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0], (6))
6-element Array{Float64,1}:
1.0
-0.3333333333333333
1.0
-0.3333333333333333
1.0
-0.3333333333333333

julia> resample([1 2 3; 4 5 6], (3, 2))
3×2 Array{Float64,2}:
1.0   3.0
3.25  5.25
3.25  5.25
FFTResampling.sinc_interpolate_sumFunction
sinc_interpolate_sum(arr, new_length)

Calculates the sinc interpolation of an 1D arr on a new array size new_size. This method is slow, because of an explicit sum evalulation and not a FFT based evaluation.

Examples

julia> sinc_interpolate_sum([1.0, 2.0, 3.0, 4.0], 8)
8-element Array{Float64,1}:
1.0
1.7825353626292277
2.0
2.1220659078919377
3.0
4.1592491794681985
4.0
2.0735615442829793

Additionally we have some utility functions:

FFTResampling.make_hermitianFunction
make_hermitian(arr)

Takes an array arr and appends rows, cols, ... if necessary so that arr is a hermitian array which preserves Parseval's theorem.

Examples

julia> FFTResampling.make_hermitian([1.0 2.0])
1×3 Array{Float64,2}:
0.5  2.0  0.5

julia> FFTResampling.make_hermitian([1.0 2.0; 3.0 4.0])
3×3 Array{Float64,2}:
0.5  1.0  0.0
1.5  4.0  1.5
0.0  1.0  0.5

julia> FFTResampling.make_hermitian([1im 2.0; 3.0im 4.0im; 5.0 6.0im])
3×3 Array{Complex{Float64},2}:
0.0+0.5im  2.0+0.0im  2.5-0.0im
0.0+1.5im  0.0+4.0im  0.0-1.5im
2.5+0.0im  0.0+6.0im  0.0-0.5im
FFTResampling.reverse_allFunction
reverse_all(arr)

Reverse an array arr over all dimensions.

Examples

julia> FFTResampling.reverse_all([1 2 3 4 5])
1×5 Array{Int64,2}:
5  4  3  2  1

julia> FFTResampling.reverse_all([1 2 3 4 5; 7 8 9 10 11])
2×5 Array{Int64,2}:
11  10  9  8  7
5   4  3  2  1

julia> FFTResampling.reverse_all([1; 2; 3; 4; 5])
5-element Array{Int64,1}:
5
4
3
2
1
FFTResampling.sliceFunction
slice(arr, dim, index)

Return a N dimensional slice (where one dimensions has size 1) of the N-dimensional arr at the index position index in the dim dimension of the array. It holds size(out)[dim] == 1.

Examples

julia> x = [1 2 3; 4 5 6; 7 8 9]
3×3 Array{Int64,2}:
1  2  3
4  5  6
7  8  9

julia> FFTResampling.slice(x, 1, 1)
1×3 view(::Array{Int64,2}, 1:1, :) with eltype Int64:
1  2  3

julia> FFTResampling.slice(x, 2, 3)
3×1 view(::Array{Int64,2}, :, 3:3) with eltype Int64:
3
6
9

FFTResampling.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> FFTResampling.center_extract([1 2; 3 4], [1])
1×2 Array{Int64,2}:
3  4

julia> FFTResampling.center_extract([1 2; 3 4], [1, 1])
1×1 Array{Int64,2}:
4

julia> FFTResampling.center_extract([1 2 3; 3 4 5; 6 7 8], [2 2])
2×2 Array{Int64,2}:
1  2
3  4
FFTResampling.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> FFTResampling.center_set!([1, 1, 1, 1, 1, 1], [5, 5, 5])
6-element Array{Int64,1}:
1
1
5
5
5
1
FFTResampling.center_posFunction
center_pos(x)

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

Examples

julia> FFTResampling.center_pos(3)
2
julia> FFTResampling.center_pos(4)
3
FFTResampling.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