Skip to content

Instantly share code, notes, and snippets.

@ndvbd
Created March 7, 2017 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ndvbd/13030ca99336d4a1eb6390ad03d23c00 to your computer and use it in GitHub Desktop.
Save ndvbd/13030ca99336d4a1eb6390ad03d23c00 to your computer and use it in GitHub Desktop.
Upsampling - Approximated Sinc Interpolation in Python
# Written by Nadav Benedek
import numpy as np
from numba import jit, autojit
import scipy
@jit(nopython=True)
def approx_sinc_interp(x, s, u):
MAX_ELEMENTS_TO_TAKE_EACH_SIDE = 20 # Change this number to change the accuracy
result = np.empty(len(u))
T = float(s[1] - s[0]) # Find the period
for i in xrange(0, len(u)):
t = float(i) * T * len(x) / float(len(u))
sum = 0.0
for n in xrange(np.maximum(int(-MAX_ELEMENTS_TO_TAKE_EACH_SIDE + t/T), 0), np.minimum(int(MAX_ELEMENTS_TO_TAKE_EACH_SIDE + t/T), len(x))):
sum = sum + x[n]*np.sinc((t- float(n)*T)/T)
result[i] = sum
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment