This package provides a simple sinc interpolation routine (up and downsampling) written in Julia. It works with real and complex N-dimensional arrays.
As this package is at an early stage of development, we would be excited to welcome any new contributers!
|Documentation||Build Status||Code Coverage|
FFTResampling.jl is has been tested version Julia from 1.3 to 1.6. It won't be maintained further.
It can be installed with the following command
julia> ] add FFTResampling
However, please prefer FourierTools.jl which is maintained and is also more performant.
The FFTW based methods require periodic, bandwidth limited (and properly Nyquist sampled) signals.
Currently the algorithms work only with equidistant spaced signals. We offer one main method:
It offers upsampling of a signal by zero padding the spectrum in Fourier space.
Secondly, a signal can be downsampled by cropping frequencies around the center spot in Fourier space. We therefore reduce resolution without aliasing.
This package also works partially with CUDA arrays. You need to set the keyword argument
resample to prevent a scalar indexing allowing a fast execution.
Below you can find a simple example for up sampling using
sinc_interpolate_sum is a slow sum based method.
Furthermore, there is an image interpolation Pluto.jl notebook in the examples folder.
We can see that the interpolated signal matches the higher sampled signal well.
begin N_low = 128 x_min = 0.0 x_max = 16π xs_low = range(x_min, x_max, length=N_low+1)[1:N_low] xs_high = range(x_min, x_max, length=5000)[1:end-1] f(x) = sin(0.5*x) + cos(x) + cos(2 * x) + sin(0.25*x) arr_low = f.(xs_low) arr_high = f.(xs_high) end begin N = 1000 xs_interp = range(x_min, x_max, length=N+1)[1:N] arr_interp = resample(arr_low, N) N2 = 1000 xs_interp_s = range(x_min, x_max, length=N2+1)[1:N2] arr_interp_s = FFTResampling.sinc_interpolate_sum(arr_low, N2) end begin scatter(xs_low, arr_low, legend=:bottomleft, markersize=2, label="Low sampling") plot!(xs_interp, arr_interp, label="FFT based sinc interpolation", linestyle=:dash) plot!(xs_interp_s, arr_interp_s, label="sum based sinc interpolation", linestyle=:dot) plot!(xs_high, arr_high, linestyle=:dashdotdot, label="High sampling") end
32 samples in the downsampled signal should be sufficient for Nyquist sampling. And as we can see, the downsampled signal still matches the original one.
begin N_ds = 32 xs_ds = range(x_min, x_max, length=N_ds+1)[1:N_ds] arr_ds = resample(arr_high, N_ds) end begin scatter(xs_low, arr_low, legend=:bottomleft, markersize=2, label="Low sampling") plot!(xs_interp, arr_interp, label="FFT based sinc interpolation", linestyle=:dash) plot!(xs_ds, arr_ds, label="resampled array", linestyle=:dot) end
Having a Nyquist sampled image, it is possible to perform a sinc interpolation and creating visually much nicer images. However, the information content does not change between both images. The full Pluto notebook is here. The right image is the upsampled version of the left one.
There is also a discussion on Discourse about some of the issues that were encountered during creation of that package.