Created
March 7, 2017 13:12
-
-
Save ndvbd/13030ca99336d4a1eb6390ad03d23c00 to your computer and use it in GitHub Desktop.
Upsampling - Approximated Sinc Interpolation in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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